public Node ExprPrimary() { switch (CurrentToken) { case TokenCategory.IDENTIFIER: var idToken = Expect(TokenCategory.IDENTIFIER); if (CurrentToken == TokenCategory.PARENTHESIS_OPEN) { Expect(TokenCategory.PARENTHESIS_OPEN); var fun = new FunCallNode() { AnchorToken = idToken }; fun.Add(ExprList()); Expect(TokenCategory.PARENTHESIS_CLOSE); return(fun); } else { var id = new IdentifierNode() { AnchorToken = idToken }; return(id); } case TokenCategory.SQUARE_OPEN: return(Arr()); case TokenCategory.PARENTHESIS_OPEN: Expect(TokenCategory.PARENTHESIS_OPEN); var node = Expr(); Expect(TokenCategory.PARENTHESIS_CLOSE); return(node); case TokenCategory.STRING_LITERAL: return(new StrNode() { AnchorToken = Expect(TokenCategory.STRING_LITERAL) }); case TokenCategory.CHAR_LITERAL: return(new CharNode() { AnchorToken = Expect(TokenCategory.CHAR_LITERAL) }); case TokenCategory.INT_LITERAL: return(new IntLiteralNode() { AnchorToken = Expect(TokenCategory.INT_LITERAL) }); case TokenCategory.TRUE: return(new TrueNode() { AnchorToken = Expect(TokenCategory.TRUE) }); case TokenCategory.FALSE: return(new IntLiteralNode() { AnchorToken = Expect(TokenCategory.FALSE) }); default: throw new SyntaxError(firstOfExprPrimary, tokenStream.Current); } }
public Node Stmt() { switch (CurrentToken) { case TokenCategory.IDENTIFIER: var idToken = Expect(TokenCategory.IDENTIFIER); switch (CurrentToken) { case TokenCategory.ASSIGN: Expect(TokenCategory.ASSIGN); var ass = new AssignmentNode() { AnchorToken = idToken }; ass.Add(Expr()); Expect(TokenCategory.SEMICOLON); return(ass); case TokenCategory.INCREMENT: Expect(TokenCategory.INCREMENT); var inc = new IncrementNode() { AnchorToken = idToken }; Expect(TokenCategory.SEMICOLON); return(inc); case TokenCategory.DECREMENT: Expect(TokenCategory.DECREMENT); var dec = new DecrementNode() { AnchorToken = idToken }; Expect(TokenCategory.SEMICOLON); return(dec); case TokenCategory.PARENTHESIS_OPEN: Expect(TokenCategory.PARENTHESIS_OPEN); var fun = new FunCallNode() { AnchorToken = idToken }; fun.Add(ExprList()); Expect(TokenCategory.PARENTHESIS_CLOSE); Expect(TokenCategory.SEMICOLON); return(fun); } break; case TokenCategory.IF: return(If()); case TokenCategory.WHILE: return(While()); case TokenCategory.BREAK: var bre = new StmtNode() { AnchorToken = Expect(TokenCategory.BREAK) }; Expect(TokenCategory.SEMICOLON); return(bre); case TokenCategory.RETURN: return(Return()); case TokenCategory.SEMICOLON: return(new StmtNode() { AnchorToken = Expect(TokenCategory.SEMICOLON) }); default: throw new SyntaxError(firstOfStmt, tokenStream.Current); } throw new SyntaxError(firstOfStmt, tokenStream.Current); }