Implements variable usage, tweaks and fixes for variable assignment

This commit is contained in:
2019-05-30 15:23:48 +02:00
parent 257eb942c7
commit 6fad5a0a7d
17 changed files with 145 additions and 4 deletions

View File

@@ -22,9 +22,11 @@ void Evaluator::EvaluateStatement(BoundStatement *statement) {
}
void Evaluator::EvaluateBlockStatement(BoundBlockStatement* statement) {
this->_evaluationScope->OuterScope();
for (auto s: statement->GetStatements()){
this -> EvaluateStatement(s);
}
this->_evaluationScope->InnerScope();
}
void Evaluator::EvaluateExpressionStatement(BoundExpressionStatement *statement) {
@@ -54,12 +56,17 @@ EvalValue *Evaluator::EvaluateExpression(BoundExpression *expression) {
}
}
EvalValue* Evaluator::GetVariable(BoundVariableExpression* expression){
return this->_evaluationScope->GetVariable(expression->GetScope(), expression->GetId())->Clone();
}
NumericEvalValue* Evaluator::EvaluateIntegerExpression(BoundExpression *expression) {
switch (expression->GetKind()){
case BoundExpressionKind ::LiteralInteger: return new IntegerEvalValue(((BoundLiteralIntegerExpression*)expression)->GetValue());
case BoundExpressionKind ::LiteralFloat: return new FloatEvalValue(((BoundLiteralFloatExpression*)expression)->GetValue());
case BoundExpressionKind::Unary: return this -> EvaluateIntegerUnary((BoundUnaryExpression*)expression);
case BoundExpressionKind ::Binary: return this -> EvaluateIntegerBinary((BoundBinaryExpression*)expression);
case BoundExpressionKind::Variable: return (NumericEvalValue*)this->GetVariable((BoundVariableExpression*)expression);
case BoundExpressionKind ::LiteralString:
case BoundExpressionKind ::LiteralBool:
@@ -73,6 +80,7 @@ BooleanEvalValue* Evaluator::EvaluateBoolExpression(BoundExpression *expression)
case BoundExpressionKind::LiteralBool: return new BooleanEvalValue(((BoundLiteralBoolExpression*)expression)->GetValue());
case BoundExpressionKind::Unary: return this -> EvaluateBooleanUnary((BoundUnaryExpression*)expression);
case BoundExpressionKind::Binary: return this -> EvaluateBooleanBinary((BoundBinaryExpression*)expression);
case BoundExpressionKind::Variable: return (BooleanEvalValue*)this->GetVariable((BoundVariableExpression*)expression);
case BoundExpressionKind::Bad:
case BoundExpressionKind::LiteralInteger:
@@ -89,6 +97,8 @@ StringEvalValue* Evaluator::EvaluateStringExpression(BoundExpression *expression
return new StringEvalValue(((BoundLiteralStringExpression*)expression)->GetValue());
case BoundExpressionKind::Binary:
return this -> EvaluateStringBinary((BoundBinaryExpression*)expression);
case BoundExpressionKind::Variable: return (StringEvalValue*)this->GetVariable((BoundVariableExpression*)expression);
case BoundExpressionKind::Bad:
case BoundExpressionKind::LiteralInteger: