public Node Program()
        {
            var node = new ProgramNode();

            while (CurrentToken != TokenCategory.EOF)
            {
                if (CurrentToken == TokenCategory.VAR)
                {
                    node.Add(VarDef());
                }
                else
                {
                    node.Add(FunDef());
                }
            }
            Expect(TokenCategory.EOF);
            return(node);
        }
Example #2
0
        public Node Program()
        {
            var program_node = new ProgramNode();

            program_node.Add(new ConstantListNode());
            if (Has(TokenCategory.CONST))
            {
                var node = program_node.Last();
                node.AnchorToken = Expect(TokenCategory.CONST);
                node.Add(OneOrMore(TokenCategory.IDENTIFIER, ConstantDeclaration));
            }
            ;

            program_node.Add(new VariableDeclarationNode());
            if (Has(TokenCategory.VAR))
            {
                var node = program_node.Last();
                node.AnchorToken = Expect(TokenCategory.VAR);
                node.Add(OneOrMore(TokenCategory.IDENTIFIER, VariableDeclaration));
            }

            program_node.Add(new ProcedureListNode());
            if (Has(TokenCategory.PROCEDURE))
            {
                var node = program_node.Last();
                node.Add(ZeroOrMore(TokenCategory.PROCEDURE, ProcedureDeclaration));
            }

            program_node.AnchorToken = Expect(TokenCategory.PROGRAM);

            program_node.Add(new StatementListNode());
            if (Has(firstOfStatement))
            {
                var node = program_node.Last();
                node.Add(ZeroOrMore(firstOfStatement, Statement));
            }

            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOLON);
            return(program_node);
        }