private static Tuple <Node, Node> Push(Node value) { var push = new AssignmentNode(new MemoryNode(Target.RSP), value); var move = new AssignmentNode(Target.RSP, new SubOperatorNode(Target.RSP, new ConstantNode <long>(8))); return(new Tuple <Node, Node>(push, move)); }
public void Visit(AssignmentNode node) { Node first = node[0]; if (first is ListIndexNode) { (first as ListIndexNode).isAssignment = true; } else if (first is IdentifierNode) { (first as IdentifierNode).isAssignment = true; } Visit((dynamic)node[0]); Visit((dynamic)node[1]); if (node[0] is ListIndexNode) { Type type = node[0].extra; switch (type) { case Type.BOOL_LIST: case Type.INT_LIST: builder.AppendLine("\t\tstelem.i4"); break; case Type.STRING_LIST: builder.AppendLine("\t\tstelem.ref"); break; } } else { string varName = node[0].AnchorToken.Lexeme; StoreInVariable(varName); } }
public void Visit(AssignmentNode node) { node.ExpressionRight.Accept(this); var(t, type) = VariableManager.GetVariable(node.ID.Text); if (type == "") { type = VirtualTable.GetAttributeType(VariableManager.CurrentClass, node.ID.Text); } if ((node.ExpressionRight.StaticType.Text == "Int" || node.ExpressionRight.StaticType.Text == "Bool" || node.ExpressionRight.StaticType.Text == "String") && type == "Object") //node.StaticType.Text == "Object") { IC.Add(new PushParam(VariableManager.PeekVariableCounter())); IC.Add(new CallLabel(new LabelLine("_wrapper", node.ExpressionRight.StaticType.Text), VariableManager.PeekVariableCounter())); IC.Add(new PopParam(1)); } if (t != -1) { //IntermediateCode.Add(new AssignmentVariableToVariable(VariableManager.PeekVariableCounter(), t)); IC.Add(new AssignmentVariableToVariable(t, VariableManager.PeekVariableCounter())); } else { int offset = VirtualTable.GetOffset(VariableManager.CurrentClass, node.ID.Text); IC.Add(new AssignmentVariableToMemory(0, VariableManager.PeekVariableCounter(), offset)); } }
public void VisitAssignment(AssignmentNode node) { // Don't insert unreachable code if (!_builder.InsertBlock.IsValid) { return; } AssignmentCodeGenVisitor assignmentCodeGenVisitor = new AssignmentCodeGenVisitor(_builder, _genContext, _function); node.Lhs.AcceptAddressableVisitor(assignmentCodeGenVisitor); if (!assignmentCodeGenVisitor.AssignmentWritePointer.IsValid) { throw new InvalidOperationException("assignment did not produce a usable lvalue"); } Value varStorage = assignmentCodeGenVisitor.AssignmentWritePointer; node.Rhs.AcceptExpressionVisitor(this); if (!_visitedValue.IsValid) { throw new InvalidOperationException("assignment did not produce a usable rvalue"); } SetCurrentDebugLocation(node); _visitedValue = _builder.BuildStore(_visitedValue, varStorage); }
public void Visit(AssignmentNode n) { var children = n.GetChildren(); var subCalls = children.SkipLast().ToList(); var table = (FunctionSymbolTableEntry)n.SymTable; _writer.WriteComment($"Assignment"); var rhsNode = children.Last(); rhsNode.Accept(this); var rhsVarName = rhsNode.TemporaryVariableName; var rhsOffset = table.MemoryLayout.GetOffset(rhsVarName); WriteCallchainCode(subCalls, FSPReg); // r12 has absolute address of variable to write to. var finalValSize = Utils.GetTypeFullSize(_globalSymbolTable, subCalls.Last().ExprType); var srcReg = Registers.R12; var dstReg = PopRegister(); var sizeReg = PopRegister(); _writer.WriteInstruction(Instructions.Addi, sizeReg, sizeReg, $"{finalValSize}"); _writer.WriteInstruction(Instructions.Add, dstReg, dstReg, FSPReg); _writer.WriteInstruction(Instructions.Addi, dstReg, dstReg, $"{rhsOffset}"); // src dst inverted, because bugs WriteMultiByteCopy(dstReg, srcReg, sizeReg); PushRegister(sizeReg); PushRegister(dstReg); }
/// <summary> /// Visits a single assignment /// </summary> /// <param name="line">Line to add the tag for</param> /// <param name="context">AssignmentNode to visit</param> /// <param name="lineNo">Current line numer</param> /// <param name="collectedSpans">Collection of spancs found</param> private void Visit(ITextSnapshotLine line, AssignmentNode context, int lineNo, List <TagSpan <Z80TestTokenTag> > collectedSpans) { if (context == null || lineNo < context.Span.StartLine || lineNo > context.Span.EndLine) { return; } if (context is RegisterAssignmentNode regAsgn) { Visit(line, regAsgn.RegisterSpan, lineNo, collectedSpans, Z80TestTokenType.Z80Key); Visit(line, regAsgn.Expr, lineNo, collectedSpans); } else if (context is FlagAssignmentNode flagAsgn) { Visit(line, flagAsgn.Span, lineNo, collectedSpans, Z80TestTokenType.Z80Key); } else if (context is MemoryAssignmentNode memAsgn) { Visit(line, memAsgn.Address, lineNo, collectedSpans); Visit(line, memAsgn.Value, lineNo, collectedSpans); Visit(line, memAsgn.Length, lineNo, collectedSpans); } }
private Value Assignment(AssignmentNode exp) { Value left = Eval(exp.Left); Value right = Eval(exp.Right); try { Constant rightConstant = right.GetRValue(); if (left is LValue l) { l.SetValue((Object)right); return(right); } } catch (Exception exc) { throw new ModelInterpreterException(exc.Message) { Line = exp.Left.Position, Position = exp.Right.Position }; } throw new ModelInterpreterException("Левая часть присваивания должна быть идентификатором") { Line = exp.Left.Line, Position = exp.Left.Position }; }
public SequenceNode FunctionCall(Function from, Node[] args, RegisterNode result, out Action <Node> nextNodeSetter) { var pl = _enclosedIn == null ? 0 : 1; // space for enclosing function stack frame address var seq = new Node[args.Length + Math.Max(0, args.Length - Target.HardwareRegistersOrder.Length) + 3 + pl]; // params in registers, params on stack, call, result, cleanup stack if (pl == 1) { seq[0] = new AssignmentNode(Target.HardwareRegistersOrder[0], from.ComputationOfStackFrameAddress(this)); } var i = 0; for (; i < Target.HardwareRegistersOrder.Length && i < args.Length; ++i) { seq[i + pl] = new AssignmentNode(Target.HardwareRegistersOrder[i], args[i]); } var ptr = i + pl; for (; i < args.Length; ++i) { var v = Push(args[i]); seq[ptr++] = v.Item1; seq[ptr++] = v.Item2; } seq[ptr++] = new FunctionCallNode(this); seq[ptr++] = new AssignmentNode(result, Body.Last().ResultRegister); // Assume value of function body is return value seq[ptr++] = new AssignmentNode(Target.RSP, new AddOperatorNode(Target.RSP, new ConstantNode <long>(_stackFrameSize))); return(new SequenceNode(seq, out nextNodeSetter, result)); }
public object Visit(AssignmentNode node) { var exprLeft = Visit((dynamic)node.Left); var value = Visit((dynamic)node.Right); _symbolTable[exprLeft?.ToString() ?? node.Left.Token.Value] = value; return(value); }
public override dynamic Visit(AssignmentNode node) { var lValue = node.LValue.Accept(this); // var index = node.IndexExpression.Accept(this); var expression = node.Expression.Accept(this); return(null); }
public override void Visit(AssignmentNode node) { node.LeftValue.Accept(this); Console.Write(" = "); node.RightValue.Accept(this); Console.Write(";"); PrettyPrintNewLine(); }
public override Node visitAssignmentExpression(JuliarParser.AssignmentExpressionContext ctx) { AssignmentNode node = new AssignmentNode(null); IterateOverContext iterateOverContext = new IterateOverContextAnonymousInnerClassHelper(this); iterateOverContext.iterateOverChildren(ctx, this, node); return(node); }
public void Visit(AssignmentNode node) { LValue?assignedLValue = _lValueResolver.Resolve(node.Lhs); if (assignedLValue != null && assignedLValue.Covers(_targetLValue)) { _isTargetCurrentlyAssigned = true; } }
public override dynamic Visit(AssignmentNode node) { node.LValue.Accept(this); //node.IndexExpression.Accept(this); node.Expression = ReplaceBoolean(node.Expression); node.Expression.Accept(this); return(null); }
public void Visit(AssignmentNode n) { PrintDOTIDLabel(n); PrintDOTParentChild(n); foreach (var child in n.GetChildren()) { child.Accept(this); } }
protected override List <AssemblyElement> VisitAssignment(AssignmentNode node) { List <AssemblyElement> instructions = new List <AssemblyElement>(); instructions.AddRange(Visit(node.RightSideNode)); instructions.AddRange(Visit(node.LeftSideNode)); instructions.Add(GetAssignInstruction(node.LeftSideNode.Symbol)); return(instructions); }
/// <summary> /// This method prints the assignmentNode and make an indentation /// It accepts the lefthand side and righthands side of the assignment /// Then outdent /// </summary> /// <param name="assignmentNode">The node to print.</param> /// <returns>Returns null</returns> public override object Visit(AssignmentNode assignmentNode) { Print("AssignmentNode"); Indent++; assignmentNode.LeftHand.Accept(this); assignmentNode.RightHand.Accept(this); Indent--; return(null); }
public override DynValue Visit(AssignmentNode assignmentNode) { var left = Visit(assignmentNode.Left); var right = Visit(assignmentNode.Right); switch (assignmentNode.OperationType) { case AssignmentOperationType.Direct: break; case AssignmentOperationType.Add: right = Addition(left, right, assignmentNode); break; case AssignmentOperationType.Subtract: right = Subtraction(left, right, assignmentNode); break; case AssignmentOperationType.Multiply: if (left.Type == DynValueType.Number) { right = Multiplication(right, left, assignmentNode); } else { right = Multiplication(left, right, assignmentNode); } break; case AssignmentOperationType.Divide: right = Division(left, right, assignmentNode); break; case AssignmentOperationType.Modulo: right = Modulus(left, right, assignmentNode); break; case AssignmentOperationType.BitwiseAnd: right = BitwiseAnd(left, right, assignmentNode); break; case AssignmentOperationType.BitwiseOr: right = BitwiseOr(left, right, assignmentNode); break; case AssignmentOperationType.BitwiseXor: right = BitwiseXor(left, right, assignmentNode); break; default: throw new RuntimeException("Unexpected compound assignment type??", null); } left.CopyFrom(right); return(right); }
public void AssignStatementWithVariable_ShouldContainExpressionNode() { var ast = TestHelpers.MakeAstRoot("int varTest = 2;\nint tester = 2;\nfunction testFunction -> | void\ntester = varTest;\nendfunction"); FunctionNode funcNode = ast.GetChildren(2) as FunctionNode; AssignmentNode assignNode = funcNode.GetChildren(0) as AssignmentNode; Assert.That(assignNode.Identifier, Is.EqualTo("tester")); Assert.That(assignNode.Expression, Is.TypeOf <IdentfierNode>()); }
public void Visit(AssignmentNode n) { var children = n.GetChildren(); foreach (var child in children) { child.SymTable = n.SymTable; child.Accept(this); } }
private IStatementNode ParseSimpleStatementNode(bool canHaveLabel = false) { var token = this.NextToken(); while (token != null && token.Type == TokenType.NewLine) { token = this.NextToken(); } if (token == null) { return(null); } if (token.Type == TokenType.Name) { IStatementNode stmt = this.TryParseNameStatement(token.Value); if (stmt != null) { return(stmt); } } this.PushToken(token); if (token.Type == TokenType.Delimiter && token.Value == "{") { return(this.ParseStatementBlock()); } IExpressionNode node = this.ParseExpressionNode(); if (node == null) { return(null); } AssignmentNode anode = this.TryParseAssignmentNode(node); if (anode != null) { return(anode); } if (this.TryParseToken(TokenType.Operator, "<-")) { var cmdnode = new SendNode(node, this.ParseExpressionNode()); return(cmdnode); } var cmd = new ExpressionStatementNode(node); return(cmd); }
public void Visit(AssignmentNode node) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.Write(Indent + "AssignmentNode: " + node.Identifier + " "); Console.Write("\n"); IndentLevel++; node.Expression.Accept(this); IndentLevel--; Console.Write("\n"); Console.ResetColor(); }
public override AstNode VisitAssignstmt(ALangParser.AssignstmtContext context) { var assignNode = new AssignmentNode(context); assignNode.Identifier = context.ID().GetText(); if (context.primaryExpression() != null) { assignNode.Expression = context.primaryExpression().Accept(this); } return(assignNode); }
public void AssignStatementHasCorrectId() { var ast = TestHelpers.MakeAstRoot("int tester = 2;\nfunction testFunction -> | void\ntester = 4;\nendfunction"); FunctionNode funcNode = ast.GetChildren(1) as FunctionNode; AssignmentNode assignNode = funcNode.GetChildren(0) as AssignmentNode; //TestContext.WriteLine(((ExpressionNode)assignNode.Expression).Operator); Assert.That(assignNode.Identifier, Is.EqualTo("tester")); Assert.That(assignNode.Expression, Is.TypeOf <IntNode>()); }
public static GraphNode ToGraphNode(AssignmentNode node) { var root = new GraphNode(node.GetHashCode(), "\"" + node.Name + "\""); root.AddProperty("color", "darkgreen"); root.AddProperty("tooltip", nameof(AssignmentNode)); root.AddNode(ToGraphNode((dynamic)node.Value)); return(root); }
AssignmentNode AssignmentStatement() { var left = Variable(); var token = _tokens.Current; Eat(PascalTerms.Assign); var right = Expression(); var node = new AssignmentNode(left, token, right); return(node); }
public void Visit(AssignmentNode assignmentNode) { indentCount += 2; Indent(); sb.Append($"{assignmentNode.Identifier} = "); assignmentNode.Expression?.Accept(this); indentCount -= 2; sb.AppendLine(""); }
public void VisitAssignment(AssignmentNode node) { IType lhsType = GetExpressionType(node.Lhs); IType rhsType = GetExpressionType(node.Rhs); if (lhsType != rhsType) { AddAssigmentTypeMismatchError(lhsType, rhsType, node); } SetAndCacheType(node, lhsType); }
private void Visit(AssignmentNode node) { var varName = node.Variable.Data.Value.ToString(); var varSymbol = CurrentScope.Lookup(varName); if (varSymbol == null) { throw new InvalidOperationException($"Variable {varName} was not declared."); } Visit(node.Value); }
public void Visit(AssignmentNode node) { var varName = node.AnchorToken.Lexeme; if (!localScopeSymbolTable.Contains(varName) && !globalScopeSymbolTable.Contains(varName)) { throw new SemanticError("Undeclared variable: " + varName, node[0].AnchorToken); } foreach (var subnode in node) { Visit((dynamic)subnode); } }
// $ANTLR start "assignmentOperator" // JavaScript.g:232:1: assignmentOperator : ( '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|=' ); public JavaScriptParser.assignmentOperator_return assignmentOperator() // throws RecognitionException [1] { JavaScriptParser.assignmentOperator_return retval = new JavaScriptParser.assignmentOperator_return(); retval.Start = input.LT(1); object root_0 = null; IToken char_literal266 = null; IToken string_literal267 = null; IToken string_literal268 = null; IToken string_literal269 = null; IToken string_literal270 = null; IToken string_literal271 = null; IToken string_literal272 = null; IToken string_literal273 = null; IToken string_literal274 = null; IToken string_literal275 = null; IToken string_literal276 = null; IToken string_literal277 = null; object char_literal266_tree=null; object string_literal267_tree=null; object string_literal268_tree=null; object string_literal269_tree=null; object string_literal270_tree=null; object string_literal271_tree=null; object string_literal272_tree=null; object string_literal273_tree=null; object string_literal274_tree=null; object string_literal275_tree=null; object string_literal276_tree=null; object string_literal277_tree=null; try { // JavaScript.g:233:2: ( '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|=' ) int alt142 = 12; switch ( input.LA(1) ) { case 46: { alt142 = 1; } break; case 70: { alt142 = 2; } break; case 71: { alt142 = 3; } break; case 72: { alt142 = 4; } break; case 73: { alt142 = 5; } break; case 74: { alt142 = 6; } break; case 75: { alt142 = 7; } break; case 76: { alt142 = 8; } break; case 77: { alt142 = 9; } break; case 78: { alt142 = 10; } break; case 79: { alt142 = 11; } break; case 80: { alt142 = 12; } break; default: if ( state.backtracking > 0 ) {state.failed = true; return retval;} NoViableAltException nvae_d142s0 = new NoViableAltException("", 142, 0, input); throw nvae_d142s0; } switch (alt142) { case 1 : // JavaScript.g:233:4: '=' { root_0 = (object)adaptor.GetNilNode(); char_literal266=(IToken)Match(input,46,FOLLOW_46_in_assignmentOperator2050); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal266_tree = new AssignmentNode(char_literal266) ; root_0 = (object)adaptor.BecomeRoot(char_literal266_tree, root_0); } } break; case 2 : // JavaScript.g:234:4: '*=' { root_0 = (object)adaptor.GetNilNode(); string_literal267=(IToken)Match(input,70,FOLLOW_70_in_assignmentOperator2061); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal267_tree = new CompoundMultNode(string_literal267) ; root_0 = (object)adaptor.BecomeRoot(string_literal267_tree, root_0); } } break; case 3 : // JavaScript.g:235:4: '/=' { root_0 = (object)adaptor.GetNilNode(); string_literal268=(IToken)Match(input,71,FOLLOW_71_in_assignmentOperator2071); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal268_tree = new CompoundDivNode(string_literal268) ; root_0 = (object)adaptor.BecomeRoot(string_literal268_tree, root_0); } } break; case 4 : // JavaScript.g:236:4: '%=' { root_0 = (object)adaptor.GetNilNode(); string_literal269=(IToken)Match(input,72,FOLLOW_72_in_assignmentOperator2081); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal269_tree = new CompoundModNode(string_literal269) ; root_0 = (object)adaptor.BecomeRoot(string_literal269_tree, root_0); } } break; case 5 : // JavaScript.g:237:4: '+=' { root_0 = (object)adaptor.GetNilNode(); string_literal270=(IToken)Match(input,73,FOLLOW_73_in_assignmentOperator2091); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal270_tree = new CompoundAddNode(string_literal270) ; root_0 = (object)adaptor.BecomeRoot(string_literal270_tree, root_0); } } break; case 6 : // JavaScript.g:238:4: '-=' { root_0 = (object)adaptor.GetNilNode(); string_literal271=(IToken)Match(input,74,FOLLOW_74_in_assignmentOperator2101); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal271_tree = new CompoundSubNode(string_literal271) ; root_0 = (object)adaptor.BecomeRoot(string_literal271_tree, root_0); } } break; case 7 : // JavaScript.g:239:4: '<<=' { root_0 = (object)adaptor.GetNilNode(); string_literal272=(IToken)Match(input,75,FOLLOW_75_in_assignmentOperator2111); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal272_tree = new CompoundLShiftNode(string_literal272) ; root_0 = (object)adaptor.BecomeRoot(string_literal272_tree, root_0); } } break; case 8 : // JavaScript.g:240:4: '>>=' { root_0 = (object)adaptor.GetNilNode(); string_literal273=(IToken)Match(input,76,FOLLOW_76_in_assignmentOperator2121); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal273_tree = new CompoundRShiftNode(string_literal273) ; root_0 = (object)adaptor.BecomeRoot(string_literal273_tree, root_0); } } break; case 9 : // JavaScript.g:241:4: '>>>=' { root_0 = (object)adaptor.GetNilNode(); string_literal274=(IToken)Match(input,77,FOLLOW_77_in_assignmentOperator2131); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal274_tree = new CompoundRUShiftNode(string_literal274) ; root_0 = (object)adaptor.BecomeRoot(string_literal274_tree, root_0); } } break; case 10 : // JavaScript.g:242:4: '&=' { root_0 = (object)adaptor.GetNilNode(); string_literal275=(IToken)Match(input,78,FOLLOW_78_in_assignmentOperator2141); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal275_tree = new CompoundAndNode(string_literal275) ; root_0 = (object)adaptor.BecomeRoot(string_literal275_tree, root_0); } } break; case 11 : // JavaScript.g:243:4: '^=' { root_0 = (object)adaptor.GetNilNode(); string_literal276=(IToken)Match(input,79,FOLLOW_79_in_assignmentOperator2151); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal276_tree = new CompoundXOrNode(string_literal276) ; root_0 = (object)adaptor.BecomeRoot(string_literal276_tree, root_0); } } break; case 12 : // JavaScript.g:244:4: '|=' { root_0 = (object)adaptor.GetNilNode(); string_literal277=(IToken)Match(input,80,FOLLOW_80_in_assignmentOperator2161); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal277_tree = new CompoundOrNode(string_literal277) ; root_0 = (object)adaptor.BecomeRoot(string_literal277_tree, root_0); } } break; } retval.Stop = input.LT(-1); if ( (state.backtracking==0) ) { retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);} } catch (RecognitionException re) { ReportError(re); Recover(input,re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re); } finally { } return retval; }
protected bool Equals(AssignmentNode other) { return string.Equals(Property, other.Property) && Equals(Value, other.Value); }
public ITreeNode Program() { ITreeNode programNode = new ErrorNode(); switch (curTokenType) { case TokenType.BEGINBL: Match(ref matchToken, TokenType.BEGINBL); ITreeNode someStatement = Program(); BlockNode block = new BlockNode(); block.addStatement(someStatement); while (curTokenType != TokenType.ENDBL) { someStatement = Program(); block.addStatement(someStatement); } Match(ref matchToken, TokenType.ENDBL); programNode = block; break; case TokenType.LABEL: Match(ref matchToken, TokenType.LABEL); LabelNode labeledBlock = new LabelNode(matchToken.getValue()); ITreeNode labeledStatement; do { labeledStatement = Program(); labeledBlock.addStatement(labeledStatement); } while (curTokenType != TokenType.EOF); programNode = labeledBlock; break; case TokenType.INTDEC: Match(ref matchToken, TokenType.INTDEC); Match(ref matchToken, TokenType.ID); programNode = new IdentifierDeclarationNode(IdentifierType.INT, matchToken.getValue()); Match(ref matchToken, TokenType.EOS); break; case TokenType.BOOLDEC: Match(ref matchToken, TokenType.BOOLDEC); Match(ref matchToken, TokenType.ID); programNode = new IdentifierDeclarationNode(IdentifierType.BOOL, matchToken.getValue()); Match(ref matchToken, TokenType.EOS); break; case TokenType.FOR: Match(ref matchToken, TokenType.FOR); Match(ref matchToken, TokenType.LPAREN); AssignmentNode init = (AssignmentNode)Program(); AssignmentNode step = (AssignmentNode)Program(); BooleanExpressionNode condition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); BlockNode forBody = (BlockNode)Program(); programNode = new ForNode(init, step, condition, forBody); break; /*case TokenType.FUN: Match(ref matchToken, TokenType.FUN); IdentifierNode id = (IdentifierNode)Factor(); programNode = new FunctionNode(id); Match(ref matchToken, TokenType.EOS); break;*/ case TokenType.GOTO: Match(ref matchToken, TokenType.GOTO); Match(ref matchToken, TokenType.ID); IdentifierNode gotoLabel = new IdentifierNode(matchToken.getValue(), IdentifierType.LABEL); programNode = new GotoNode(gotoLabel); Match(ref matchToken, TokenType.EOS); break; case TokenType.ID: Match(ref matchToken, TokenType.ID); IdentifierNode assignId = new IdentifierNode(matchToken.getValue(), IdentifierType.UNKNOWN); Match(ref matchToken, TokenType.ASSIGN); BooleanExpressionNode assignValue = (BooleanExpressionNode)BooleanExpression(); programNode = new AssignmentNode(assignId, assignValue); Match(ref matchToken, TokenType.EOS); break; case TokenType.IF: Match(ref matchToken, TokenType.IF); ITreeNode thenBranch; ITreeNode elseBranch; Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode ifCondition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); Match(ref matchToken, TokenType.THEN); thenBranch = (BlockNode)Program(); if (curTokenType == TokenType.ELSE) { Match(ref matchToken, TokenType.ELSE); elseBranch = (BlockNode)Program(); } else { elseBranch = new BlankNode(); } programNode = new IfNode(ifCondition, thenBranch, elseBranch); break; /*case TokenType.LET: Match(ref matchToken, TokenType.LET); IdentifierNode shortId = (IdentifierNode)Factor(); Match(ref matchToken, TokenType.ASSIGN); BooleanExpressionNode subst = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.IN); BooleanExpressionNode target = (BooleanExpressionNode)BooleanExpression(); programNode = new LetNode(shortId, subst, target); Match(ref matchToken, TokenType.EOS); break;*/ case TokenType.PRINT: Match(ref matchToken, TokenType.PRINT); Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode printArgument = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); programNode = new PrintNode(printArgument); Match(ref matchToken, TokenType.EOS); break; case TokenType.WHILE: Match(ref matchToken, TokenType.WHILE); Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode whileCondition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); BlockNode whileBody = (BlockNode)Program(); programNode = new WhileNode(whileCondition, whileBody); break; case TokenType.EOF: programNode = new BlankNode(); break; default: Expect(TokenType.UNKNOWN, lookAheadToken); break; } return programNode; }