private void ExtractStatement(Statement statement, Procedure procedureContext) { Statements.AddStatement(statement); if (statement is While) { ExtractWhile(statement as While, procedureContext); } else if (statement is If) { ExtractIf(statement as If, procedureContext); } else if (statement is Assign) { ExtractAssign(statement as Assign); } else if (statement is Call) { ExtractCall(statement as Call, procedureContext); } }
public void AddStatement(StatementNode statement) { Statements.AddStatement(statement); }
private ExpressionValue ExecuteStatement(Statement statement, Environment env) { switch (statement.Type) { case StatementType.ASSIGN: { this.Assign(statement.Assignment); return(null); } case StatementType.IF_THEN: { ExpressionValue value = this.evaluator.Evaluate(statement.ConditionExpression, this.env); if (value.Bool == true) { return(this.ExecuteStatements(statement.Statement1)); } return(null); } case StatementType.IF_THEN_ELSE: { ExpressionValue value = this.evaluator.Evaluate(statement.ConditionExpression, this.env); if (value.Bool == true) { return(this.ExecuteStatements(statement.Statement1)); } else { return(this.ExecuteStatements(statement.Statement2)); } } case StatementType.WHILE: { ExpressionValue value = this.evaluator.Evaluate(statement.ConditionExpression, this.env); if (value.Bool == true) { Statements st = new Statements(); st.AddStatement(statement.Statement1); st.AddStatement(statement); return(this.ExecuteStatements(st)); } return(null); } case StatementType.FUNCTION_DECLARATION: { this.DeclareFunction(statement.FunctionDeclaration); return(null); } case StatementType.FUNCTION: { return(this.ExecuteFunction(statement.Function)); } case StatementType.RETURN: { return(this.evaluator.Evaluate(statement.ReturnValue, this.Environment)); } } return(null); }
private ExpressionValue ExecuteStatement(Statement statement, Environment env) { switch (statement.kind) { case StatementType.ASSIGN: { AssignmentStatement asg = statement as AssignmentStatement; this.Assign(asg.assignment); return(null); } case StatementType.IF: { IfStatement st = statement as IfStatement; ExpressionValue value = this.evaluator.Evaluate(st.condition.Expression, this.env); if (value.Bool == true) { return(this.ExecuteStatements(st.body)); } return(null); } case StatementType.IF_ELSE: { IfElseStatement st = statement as IfElseStatement; ExpressionValue value = this.evaluator.Evaluate(st.condition.Expression, this.env); if (value.Bool == true) { return(this.ExecuteStatements(st.ifBody)); } else { return(this.ExecuteStatements(st.elseBody)); } } case StatementType.WHILE: { WhileStatement st = statement as WhileStatement; ExpressionValue value = this.evaluator.Evaluate(st.condition.Expression, this.env); if (value.Bool == true) { Statements ss = new Statements(); ss.AddStatement(st.body); ss.AddStatement(st); return(this.ExecuteStatements(ss)); } return(null); } case StatementType.FUNC_DECL: { FunctionStatement st = statement as FunctionStatement; this.DeclareFunction(st.function); return(null); } case StatementType.FUNCTION: { FunctionStatement st = statement as FunctionStatement; return(this.ExecuteFunction(st.val)); } case StatementType.RETURN: { FunctionStatement st = statement as FunctionStatement; return(this.evaluator.Evaluate(st.val, this.Environment)); } } return(null); }