public Node ProcedureDeclaration() { var result = new ProcedureDeclaration(); Expect(TokenCategory.PROCEDURE); result.AnchorToken = Expect(TokenCategory.IDENTIFIER); Expect(TokenCategory.LEFT_PAR); var parameterDeclarationList = new ParameterDeclarationList(); while (CurrentToken == TokenCategory.IDENTIFIER) { parameterDeclarationList.Add(ParameterDeclaration()); } result.Add(parameterDeclarationList); Expect(TokenCategory.RIGHT_PAR); if (CurrentToken == TokenCategory.COLON) { Expect(TokenCategory.COLON); result.Add(Type()); } Expect(TokenCategory.SEMICOLON); if (CurrentToken == TokenCategory.CONST) { var constantDeclarationList = new ConstantDeclarationList() { AnchorToken = Expect(TokenCategory.CONST) }; do { constantDeclarationList.Add(ConstantDeclaration()); } while (CurrentToken == TokenCategory.IDENTIFIER); result.Add(constantDeclarationList); } if (CurrentToken == TokenCategory.VAR) { var variableDeclarationList = new VariableDeclarationList() { AnchorToken = Expect(TokenCategory.VAR) }; do { variableDeclarationList.Add(VariableDeclaration()); } while (CurrentToken == TokenCategory.IDENTIFIER); result.Add(variableDeclarationList); } Expect(TokenCategory.BEGIN); var statementList = new StatementList(); while (firstOfStatement.Contains(CurrentToken)) { statementList.Add(Statement()); } result.Add(statementList); Expect(TokenCategory.END); Expect(TokenCategory.SEMICOLON); return(result); }
public Node ProcedureDeclaration() { var result = new ProcedureDeclaration() { AnchorToken = Expect(TokenCategory.PROCEDURE) }; result.Add(new Identifier() { AnchorToken = Expect(TokenCategory.IDENTIFIER) }); Expect(TokenCategory.PARENTHESIS_OPEN); var parameterList = new ParameterDeclarationList(); if (CurrentToken == TokenCategory.IDENTIFIER) { while (CurrentToken == TokenCategory.IDENTIFIER) { parameterList.Add(VariableDeclaration()); } } result.Add(parameterList); Expect(TokenCategory.PARENTHESIS_CLOSE); var type = new TypeNode(); if (CurrentToken == TokenCategory.COLON) { Expect(TokenCategory.COLON); if (CurrentToken != TokenCategory.LIST) { type.Add(SimpleType()); } else if (CurrentToken == TokenCategory.LIST) { type.Add(ListType()); } } result.Add(type); Expect(TokenCategory.SEMICOLON); var constantList = new ConstantDeclarationList(); if (firstOfDeclaration.Contains(CurrentToken) && CurrentToken == TokenCategory.CONST) { constantList.AnchorToken = Expect(TokenCategory.CONST); do { constantList.Add(ConstantDeclaration()); } while (CurrentToken == TokenCategory.IDENTIFIER); } result.Add(constantList); var variableList = new VariableDeclarationList(); if (firstOfDeclaration.Contains(CurrentToken) && CurrentToken == TokenCategory.VAR) { variableList.AnchorToken = Expect(TokenCategory.VAR); do { variableList.Add(VariableDeclaration()); } while (CurrentToken == TokenCategory.IDENTIFIER); } result.Add(variableList); Expect(TokenCategory.BEGIN); var statementList = new StatementList(); if (firstOfStatement.Contains(CurrentToken)) { while (firstOfStatement.Contains(CurrentToken)) { statementList.Add(Statement()); } } result.Add(statementList); Expect(TokenCategory.END); Expect(TokenCategory.SEMICOLON); return(result); }
public Node ProcedureDeclaration() { var procedure = new ProcedureDeclaration(); Expect(TokenCategory.PROCEDURE); procedure.AnchorToken = Expect(TokenCategory.IDENTIFIER); var consDecList = new ConstantDeclarationList(); var statement = new StatementList(); Expect(TokenCategory.INITPARENTHESIS); if (CurrentToken == TokenCategory.IDENTIFIER) { var parDecList = ParameterDeclaration(); procedure.Add(parDecList); } Expect(TokenCategory.CLOSINGPARENTHESIS); if (CurrentToken == TokenCategory.DECLARATION) { Expect(TokenCategory.DECLARATION); var type = Type(); procedure.Add(type); } Expect(TokenCategory.ENDLINE); if (CurrentToken == TokenCategory.CONST) { consDecList.AnchorToken = Expect(TokenCategory.CONST); var i = 0; do { consDecList.Add(ConstantDeclaration()); Console.WriteLine(consDecList[i]); i++; } while (CurrentToken == TokenCategory.IDENTIFIER); procedure.Add(consDecList); } if (CurrentToken == TokenCategory.VAR) { var varDecList = VariableDeclaration(); procedure.Add(varDecList); } var tempStatement = Expect(TokenCategory.BEGIN); while (firstOfStatement.Contains(CurrentToken)) { statement.Add(Statement()); } if (statement.getLength() > 0) { statement.AnchorToken = tempStatement; procedure.Add(statement); } Expect(TokenCategory.END); Expect(TokenCategory.ENDLINE); return(procedure); }