You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (context->symbolTable->exists(variableName, false)) {
61
+
return rt.failure(RuntimeError(node->positionStart, node->positionEnd, "Variable " + variableName + " is already declared in the current scope!", context));
62
+
}
63
+
spObject value;
64
+
value = rt.registerRT(visit(node->valueNode, context));
case SymbolTableSetReturnCode::perfect: { return rt.success(value); }
69
+
case SymbolTableSetReturnCode::errorGlobalConstantVariable: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "You cannot modify a global constant variable!", context)); }
70
+
case SymbolTableSetReturnCode::errorUserDefinedConstantVariable: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "You cannot modify a constant variable!", context)); }
71
+
case SymbolTableSetReturnCode::errorNotInScope: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "Variable \"" + variableName + "\" does not exist in the current scope!", context)); }
72
+
default: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "Unknown return value when setting: " + std::to_string((int) success), context)); }
case SymbolTableSetReturnCode::perfect: { return rt.success(value); }
64
84
case SymbolTableSetReturnCode::errorGlobalConstantVariable: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "You cannot modify a global constant variable!", context)); }
65
85
case SymbolTableSetReturnCode::errorUserDefinedConstantVariable: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "You cannot modify a constant variable!", context)); }
66
-
case SymbolTableSetReturnCode::errorNotInScope: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "Variable " + variableName + " does not exist in the current scope!", context)); }
86
+
case SymbolTableSetReturnCode::errorNotInScope: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "Variable \"" + variableName + "\" does not exist in the current scope!", context)); }
67
87
default: { return rt.failure(RuntimeError(node->token.positionStart, node->positionEnd, "Unknown return value when setting: " + std::to_string((int) success), context)); }
return pr.failure(InvalidSyntaxError(currentToken.positionStart, currentToken.positionEnd, "Expected a 'let', number, identifier, '+', '-', or a '('"));
136
+
return pr.failure(InvalidSyntaxError(currentToken.positionStart, currentToken.positionEnd, "Expected a number, identifier, '+', '-', or a '('"));
102
137
}
103
138
return pr.success(termRes);
104
139
}
105
140
}
106
141
107
-
ParseResult Parser::parse() {
108
-
ParseResult pr = expr();
109
-
if (!pr.hasError() && currentToken.type != tokens::EEOF) {
110
-
return pr.failure(InvalidSyntaxError(currentToken.positionStart, currentToken.positionEnd, "Expected a '+', '-', '*', '/', '**', '//', or a '('"));
142
+
ParseResult Parser::statement() {
143
+
if (currentToken.matches(tokens::KEYWORD, reservedWords::LET)) {
144
+
returndeclaration();
145
+
} else {
146
+
ParseResult pr = expr();
147
+
if (pr.hasError()) {
148
+
return pr.failure(InvalidSyntaxError(currentToken.positionStart, currentToken.positionEnd, "Expected a 'let', number, identifier, '+', '-', or a '('"));
149
+
}
150
+
if (!pr.hasError() && currentToken.type != tokens::EEOF) {
151
+
return pr.failure(InvalidSyntaxError(currentToken.positionStart, currentToken.positionEnd, "Expected a '+', '-', '*', '/', '**', '//', or a '('"));
0 commit comments