public override void VisitUnaryExpression(UnaryExpression unaryExpression) { Visit(unaryExpression.Operand); var unaryOp = new UnaryOperation(unaryExpression.Operation, ExpressionStack.Pop()); var variable = new Identifier(NewVariable); var assignment = new Assignment(variable.Name, unaryOp); Program.Add(assignment); ExpressionStack.Push(variable); }
public override void VisitBinaryExpression(BinaryExpression binaryExpression) { Visit(binaryExpression.Left); var leftExpression = ExpressionStack.Pop(); Visit(binaryExpression.Right); var rightExpression = ExpressionStack.Pop(); var variable = new Identifier(NewVariable); var binOp = new BinaryOperation(leftExpression, binaryExpression.Operation, rightExpression); Program.Add(new Assignment(variable.Name, binOp)); ExpressionStack.Push(variable); }
public override void VisitFor(ForStatement forStatement) { Visit(forStatement.From); Program.Add(new Assignment(forStatement.ForVariable.Name, ExpressionStack.Pop())); var forBegin = NewLabel; var forEnd = NewLabel; var forVariable = new Identifier(forStatement.ForVariable.Name); Visit(forStatement.To); var forTo = ExpressionStack.Pop(); var check = new ConditionalGoto( forEnd, new BinaryOperation(forVariable, Operation.Greater, forTo)) { Label = forBegin }; Program.Add(check); Visit(forStatement.Body); Program.Add(Assignment.Increment(forVariable.Name)); Program.Add(new Goto(forBegin)); Program.Add(new NoOperation(forEnd)); }