Пример #1
0
        public Node ParameterDeclaration()
        {
            var paramList = new ParameterDeclarationList();

            while (CurrentToken == TokenCategory.IDENTIFIER)
            {
                var  tempList = new VariableDeclarationList();
                Node idToken  = new Identifier()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                };

                tempList.Add(idToken);

                while (CurrentToken == TokenCategory.COMMA)
                {
                    Expect(TokenCategory.COMMA);
                    tempList.Add(new Identifier()
                    {
                        AnchorToken = Expect(TokenCategory.IDENTIFIER)
                    });
                }
                Expect(TokenCategory.DECLARATION);
                var tipo = Type();
                //declarationList.Add(Type());
                foreach (var node in tempList)
                {
                    tipo.Add(node);
                }
                paramList.Add(tipo);
                Expect(TokenCategory.ENDLINE);
            }

            return(paramList);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }