示例#1
0
        public Node stmt_()
        {
            //Console.WriteLine("stmt");
            Token r;

            switch (CurrentToken)
            {
            case TokenCategory.IF:
                //Console.WriteLine("stmt1");
                Node If = new If_();
                r = Expect(TokenCategory.IF);
                If.AnchorToken = r;
                Expect(TokenCategory.OPENP);
                If.Add(expr());
                Expect(TokenCategory.CLOSEP);
                Expect(TokenCategory.OPENB);
                If.Add(stmt_list());
                //Console.WriteLine("CLOSEB3");
                Expect(TokenCategory.CLOSEB);
                If.Add(else_if_list());
                If.Add(else_());
                return(If);

            case TokenCategory.SWITCH:
                //Console.WriteLine("stmt2");
                var Switch = new Switch_();
                r = Expect(TokenCategory.SWITCH);
                Switch.AnchorToken = r;
                Expect(TokenCategory.OPENP);
                Switch.Add(expr());
                Expect(TokenCategory.CLOSEP);
                Expect(TokenCategory.OPENB);
                Switch.Add(case_list());
                Switch.Add(default_());
                //Console.WriteLine("CLOSEB4");
                Expect(TokenCategory.CLOSEB);
                return(Switch);

            case TokenCategory.WHILE:
                //Console.WriteLine("stmt3");
                var While = new While_();
                r = Expect(TokenCategory.WHILE);
                While.AnchorToken = r;
                Expect(TokenCategory.OPENP);
                While.Add(expr());
                Expect(TokenCategory.CLOSEP);
                Expect(TokenCategory.OPENB);
                While.Add(stmt_list());
                //Console.WriteLine("CLOSEB11");
                Expect(TokenCategory.CLOSEB);
                return(While);

            /*       case TokenCategory.OPENP:
             *          Expect(TokenCategory.OPENP);
             *          expr();
             *          Expect(TokenCategory.CLOSEP);
             *          break;*/


            case TokenCategory.DO:     //OYE AQUI NO ES DO_WHILE???
                //Console.WriteLine("stmt4");
                var Do = new Do_();
                r = Expect(TokenCategory.DO);
                Do.AnchorToken = r;
                Expect(TokenCategory.OPENB);
                Do.Add(stmt_list());
                //Console.WriteLine("CLOSEB5");
                Expect(TokenCategory.CLOSEB);
                var While_ = new While_();
                var m      = Expect(TokenCategory.WHILE);
                While_.AnchorToken = m;
                Expect(TokenCategory.OPENP);
                While_.Add(expr());
                Do.Add(While_);
                Expect(TokenCategory.CLOSEP);
                //Console.WriteLine("semi4");
                Expect(TokenCategory.SEMICOLON);
                return(Do);

            case TokenCategory.FOR:
                //Console.WriteLine("stmt5");
                var For = new For_();
                r = Expect(TokenCategory.FOR);
                For.AnchorToken = r;
                Expect(TokenCategory.OPENP);
                var Id = new Id_();
                var n  = Expect(TokenCategory.IDENTIFIER);
                Id.AnchorToken = n;
                For.Add(Id);
                Expect(TokenCategory.IN);
                For.Add(expr());
                Expect(TokenCategory.CLOSEP);
                Expect(TokenCategory.OPENB);
                For.Add(stmt_list());
                //Console.WriteLine("CLOSEB6");
                Expect(TokenCategory.CLOSEB);
                return(For);

            case TokenCategory.BREAK:
                //Console.WriteLine("stmt6");
                var Break = new Break_();
                r = Expect(TokenCategory.BREAK);
                Break.AnchorToken = r;
                //Console.WriteLine("semi5");
                Expect(TokenCategory.SEMICOLON);
                return(Break);

            case TokenCategory.CONTINUE:
                //Console.WriteLine("stmt7");
                var Continue = new Continue_();
                r = Expect(TokenCategory.CONTINUE);
                Continue.AnchorToken = r;
                //Console.WriteLine("semi6");
                Expect(TokenCategory.SEMICOLON);
                return(Continue);

            case TokenCategory.RETURN:
                //Console.WriteLine("stmt8");
                var Return = new Return_();
                r = Expect(TokenCategory.RETURN);
                Return.AnchorToken = r;
                Return.Add(expr());
                //Console.WriteLine("semi7");
                Expect(TokenCategory.SEMICOLON);
                return(Return);

            case TokenCategory.SEMICOLON:
                //Console.WriteLine("stmt9");
                var empty = new Empty_();
                //Console.WriteLine("semi8");
                r = Expect(TokenCategory.SEMICOLON);
                empty.AnchorToken = r;
                return(empty);

            case TokenCategory.IDENTIFIER:
                //Console.WriteLine("stmt10");
                r = Expect(TokenCategory.IDENTIFIER);
                if (CurrentToken == TokenCategory.ASIGNATION)
                {
                    //Console.WriteLine("stmt11");
                    var id = new Id_();
                    id.AnchorToken = r;
                    Expect(TokenCategory.ASIGNATION);
                    id.Add(expr());
                    //Console.WriteLine("semi2");
                    Expect(TokenCategory.SEMICOLON);
                    return(id);
                }
                else if (CurrentToken == TokenCategory.OPENP)
                {
                    //Console.WriteLine("stmt12");
                    var Fun = new Fun_();
                    Fun.AnchorToken = r;
                    Expect(TokenCategory.OPENP);
                    if (CurrentToken != TokenCategory.CLOSEP)
                    {
                        //Console.WriteLine("stmt13");////////////MODIFICADO//////////////////////////////////////////
                        Fun.Add(expr_list());
                    }
                    //Console.WriteLine("stmt14");
                    Expect(TokenCategory.CLOSEP);
                    //Console.WriteLine("semi3");
                    Expect(TokenCategory.SEMICOLON);
                    return(Fun);
                }
                else
                {
                    throw new SyntaxError(TokenCategory.EQUAL, tokenStream.Current);
                }

            default:
                throw new SyntaxError(TokenCategory.IDENTIFIER, tokenStream.Current);
            }
        }
示例#2
0
        public Node expr_primary()
        {
            //Console.WriteLine("expr_primary");
            if (CurrentToken == TokenCategory.IDENTIFIER)
            {
                //Console.WriteLine("expr_primary1");
                var id = new Id_();
                var r  = Expect(TokenCategory.IDENTIFIER);
                id.AnchorToken = r;
                if (CurrentToken == TokenCategory.OPENP)
                {
                    //Console.WriteLine("expr_primary2");
                    Expect(TokenCategory.OPENP);
                    if (CurrentToken != TokenCategory.CLOSEP) /////////////////////////////MODIFICADO///////////////////////////
                    {
                        id.Add(expr_list());
                    }
                    Expect(TokenCategory.CLOSEP);
                    //Console.WriteLine("semi9");
                    //Expect(TokenCategory.SEMICOLON);
                }
                return(id);
            }
            else if (CurrentToken == TokenCategory.FALSE)
            {
                //Console.WriteLine("expr_primary3");
                var False = new False_();
                var r     = Expect(TokenCategory.FALSE);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.TRUE)
            {
                //Console.WriteLine("expr_primary4");
                var False = new True_();
                var r     = Expect(TokenCategory.TRUE);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.CHARACTER)
            {
                //Console.WriteLine("expr_primary5");
                var False = new Character_();
                var r     = Expect(TokenCategory.CHARACTER);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.INTEGER)
            {
                //Console.WriteLine("expr_primary6");
                var False = new Integer_();
                var r     = Expect(TokenCategory.INTEGER);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.BINARYINT)
            {
                //Console.WriteLine("expr_primary7");
                var False = new Integer_();
                var r     = Expect(TokenCategory.BINARYINT);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.OCTALINT)
            {
                //Console.WriteLine("expr_primary8");
                var False = new Integer_();
                var r     = Expect(TokenCategory.OCTALINT);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.HEXAINT)
            {
                //Console.WriteLine("expr_primary9");
                var False = new Integer_();
                var r     = Expect(TokenCategory.HEXAINT);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.STRING)
            {
                //Console.WriteLine("expr_primary10");
                var False = new String_();
                var r     = Expect(TokenCategory.STRING);
                False.AnchorToken = r;
                return(False);
            }
            else if (CurrentToken == TokenCategory.OPENP)
            {
                //Console.WriteLine("expr_primary11");
                var openp = new Openp_();
                var r     = Expect(TokenCategory.OPENP);
                openp.AnchorToken = r;
                //Console.WriteLine("CURRRRRRRREEEEENT" + CurrentToken);
                if (CurrentToken != TokenCategory.CLOSEP)
                {
                    openp.Add(expr());
                }

                Expect(TokenCategory.CLOSEP);
                return(openp);
            }
            else if (CurrentToken == TokenCategory.OPENB)
            {
                //Console.WriteLine("expr_primary12");
                var r = array_list();
                return(r);
            }
            else if (CurrentToken == TokenCategory.EXCLAMATION)
            {
                //Console.WriteLine("expr_primary13");
                var exclamation = new Exclamation_();
                var r           = Expect(TokenCategory.EXCLAMATION);
                exclamation.AnchorToken = r;
                if (CurrentToken == TokenCategory.IDENTIFIER)
                {
                    var id = new Id_();
                    var m  = Expect(TokenCategory.IDENTIFIER);
                    id.AnchorToken = m;
                    exclamation.Add(id);
                }
                return(exclamation);
            }
            else
            {
                throw new SyntaxError(firstOfSimpleExpression, tokenStream.Current);
            }
        }