public Node IfStatement() { var ifNode = new If_Statement() { AnchorToken = Expect(TokenCategory.IF) }; ifNode.Add(Expression()); Expect(TokenCategory.THEN); var stmtList = new Statement_List(); while (firstOfStatement.Contains(CurrentToken)) { stmtList.Add(Statement()); } ifNode.Add(stmtList); while (CurrentToken == TokenCategory.ELSEIF) { var elseIfNode = new ElseIf_Statement() { AnchorToken = Expect(TokenCategory.ELSEIF) }; elseIfNode.Add(Expression()); Expect(TokenCategory.THEN); var stmtListElseIf = new Statement_List(); while (firstOfStatement.Contains(CurrentToken)) { stmtListElseIf.Add(Statement()); } elseIfNode.Add(stmtListElseIf); ifNode.Add(elseIfNode); } while (CurrentToken == TokenCategory.ELSE) { var elseNode = new Else_Statement() { AnchorToken = Expect(TokenCategory.ELSE) }; var stmtListElse = new Statement_List(); while (firstOfStatement.Contains(CurrentToken)) { stmtListElse.Add(Statement()); } elseNode.Add(stmtListElse); ifNode.Add(elseNode); } Expect(TokenCategory.END); Expect(TokenCategory.EOL); return(ifNode); }
public Node LoopStatement() { var loopNode = new Loop_Statement() { AnchorToken = Expect(TokenCategory.LOOP) }; var stmtList = new Statement_List(); while (firstOfStatement.Contains(CurrentToken)) { stmtList.Add(Statement()); } Expect(TokenCategory.END); Expect(TokenCategory.EOL); loopNode.Add(stmtList); return(loopNode); }
public Node ForStatement() { var forNode = new For_Statement() { AnchorToken = Expect(TokenCategory.FOR) }; var forID = new Identifier() { AnchorToken = Expect(TokenCategory.IDENTIFIER) }; var inNode = new IN_Statement() { AnchorToken = Expect(TokenCategory.IN) }; inNode.Add(forID); inNode.Add(Expression()); var doNode = new DO_Statement() { AnchorToken = Expect(TokenCategory.DO) }; var stmtList = new Statement_List(); while (firstOfStatement.Contains(CurrentToken)) { stmtList.Add(Statement()); } doNode.Add(stmtList); Expect(TokenCategory.END); Expect(TokenCategory.EOL); forNode.Add(inNode); forNode.Add(doNode); return(forNode); }
public Node Program() { var declList = new Declaration_List(); var stmtList = new Statement_List(); while (firstOfDeclaration.Contains(CurrentToken)) { declList.Add(Declaration()); } Expect(TokenCategory.PROGRAM); while (firstOfStatement.Contains(CurrentToken)) { stmtList.Add(Statement()); } Expect(TokenCategory.END); Expect(TokenCategory.EOL); Expect(TokenCategory.EOF); return(new Program_Node() { declList, stmtList }); }
public Node ProcedureDeclaration() { var procedureNode = new Procedure_Declaration() { AnchorToken = Expect(TokenCategory.PROCEDURE) }; var procedureName = new Identifier() { AnchorToken = Expect(TokenCategory.IDENTIFIER) }; var declList = new Declaration_List(); var stmtList = new Statement_List(); Expect(TokenCategory.PARENTHESIS_OPEN); while (CurrentToken == TokenCategory.IDENTIFIER) { declList.Add(ParameterDeclaration()); } Expect(TokenCategory.PARENTHESIS_CLOSE); if (CurrentToken == TokenCategory.DECL) { var declNode = new Identifier() { AnchorToken = Expect(TokenCategory.DECL) }; declNode.Add(procedureName); declNode.Add(Type()); procedureNode.Add(declNode); } else { procedureNode.Add(procedureName); } Expect(TokenCategory.EOL); while (CurrentToken == TokenCategory.CONST) { declList.Add(ConstantDeclaration()); } while (CurrentToken == TokenCategory.VAR) { declList.Add(VariableDeclaration()); } stmtList.AnchorToken = (Expect(TokenCategory.BEGIN)); while (firstOfStatement.Contains(CurrentToken)) { stmtList.Add(Statement()); } Expect(TokenCategory.END); Expect(TokenCategory.EOL); procedureName.Add(declList); procedureName.Add(stmtList); return(procedureNode); }