예제 #1
0
        public Node lit_list()
        {
            //Console.WriteLine("lit_list");
            //Node lit_list = new Lit_list_();
            Node lit = new Lit_list_();

            if (CurrentToken == TokenCategory.FALSE)
            {
                lit = new False_();
                var r = Expect(TokenCategory.FALSE);
                lit.AnchorToken = r;
            }
            else if (CurrentToken == TokenCategory.TRUE)
            {
                lit = new True_();
                var r = Expect(TokenCategory.TRUE);
                lit.AnchorToken = r;
            }
            else if (CurrentToken == TokenCategory.CHARACTER)   //y si le ponemos que espera un valor
            {
                lit = new Character_();
                var r = Expect(TokenCategory.CHARACTER);
                lit.AnchorToken = r;
            }
            else if (CurrentToken == TokenCategory.INTEGER)
            {
                lit = new Integer_();
                var r = Expect(TokenCategory.INTEGER);
                lit.AnchorToken = r;
            }
            else if (CurrentToken == TokenCategory.BINARYINT)
            {
                lit = new Integer_();
                var r = Expect(TokenCategory.BINARYINT);
                lit.AnchorToken = r;
            }
            else if (CurrentToken == TokenCategory.OCTALINT)
            {
                lit = new Integer_();
                var r = Expect(TokenCategory.OCTALINT);
                lit.AnchorToken = r;
            }
            else if (CurrentToken == TokenCategory.HEXAINT)
            {
                lit = new Integer_();
                var r = Expect(TokenCategory.HEXAINT);
                lit.AnchorToken = r;
            }
            else
            {
                throw new SyntaxError(firstOfSimpleExpression, tokenStream.Current);//hay que arreglar estos diccionarios al final
            }
            //lit_list.Add(lit);
            while (CurrentToken == TokenCategory.COMA)
            {
                Expect(TokenCategory.COMA);
                lit.Add(lit_list());
            }
            return(lit);
        }
예제 #2
0
 public string Visit(Integer_ node, int modo)
 {
     if (modo != 7)
     {
         return("\t\tldc.i8 " + node.AnchorToken.lexeme + "\n");
     }
     else
     {
         try{
             return(node.AnchorToken.lexeme + " " + Visit((dynamic)node[0], 7));
         }
         catch (System.ArgumentOutOfRangeException e) {
             return(node.AnchorToken.lexeme);
         }
     }
     return(node.AnchorToken.lexeme);
 }
예제 #3
0
        public Node lit_simple()
        {
            //Console.WriteLine("lit_simple");
            Node  True = null;
            Token r;

            switch (CurrentToken)
            {
            case TokenCategory.TRUE:
                True             = new True_();
                r                = Expect(TokenCategory.TRUE);
                True.AnchorToken = r;
                return(True);

            case TokenCategory.FALSE:
                True             = new  False_();
                r                = Expect(TokenCategory.FALSE);
                True.AnchorToken = r;
                return(True);

            case TokenCategory.INTEGER:
                True             = new Integer_();
                r                = Expect(TokenCategory.INTEGER);
                True.AnchorToken = r;
                return(True);

            case TokenCategory.CHARACTER:
                True             = new Character_();
                r                = Expect(TokenCategory.CHARACTER);
                True.AnchorToken = r;
                return(True);

            default:
                throw new SyntaxError(TokenCategory.CHARACTER, tokenStream.Current);
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
 public string Visit(Integer_ node, int modo)
 {
     VisitChildren(node, modo);
     return(node.AnchorToken.lexeme);
 }