Esempio n. 1
0
        public Sentence_Trad IF_SENTENCE(ParseTreeNode actual, int cant_tabs)
        {
            /*
             * IF_SENTENCE.Rule = INSTRUCTIONS_BODY
             | Empty
             |  ;
             |
             */
            Sentence_Trad sentence = new Sentence_Trad();

            if (actual.ChildNodes.Count > 0)
            {
                var lista_instrucciones = instrucciones.INSTRUCTIONS_BODY(actual.ChildNodes[0], cant_tabs + 1);
                sentence = new Sentence_Trad(lista_instrucciones);
            }

            return(sentence);
        }
        public LinkedList <Instruction_Trad> getFunciones(ParseTreeNode actual,
                                                          LinkedList <Instruction_Trad> lista_funciones, ArrayList parametros_her, int cant_tabs)
        {
            /*
             * FUNCTION_LIST.Rule
             *  = RESERV_FUNCTION + IDENTIFIER + PAR_IZQ + PARAMETER + PAR_DER + DOS_PUNTOS + DATA_TYPE + PUNTO_COMA
             + DECLARATION_LIST_HIJA
             + FUNCION_HIJA
             + INSTRUCTIONS_BODY
             + PUNTO_COMA
             + FUNCTION_LIST
             | Empty
             |  ;
             */
            LinkedList <Instruction_Trad> parametros     = new LinkedList <Instruction_Trad>();
            LinkedList <Instruction_Trad> declaraciones  = new LinkedList <Instruction_Trad>();
            LinkedList <Instruction_Trad> fuciones_hijas = new LinkedList <Instruction_Trad>();



            var reserv_fun = actual.ChildNodes[0].Token.Text;

            var identifier = actual.ChildNodes[1].Token.Text;

            parametros = PARAMETER(actual.ChildNodes[3], parametros, parametros_her);

            var function_type = actual.ChildNodes[6].ChildNodes[0].Token.Text;

            declaraciones = declarationAST.LIST_DECLARATIONS(actual.ChildNodes[8], declaraciones, new ArrayList(), cant_tabs + 1);

            fuciones_hijas = FUNCION_HIJA(actual.ChildNodes[9], fuciones_hijas, cant_tabs, identifier);

            var function_instructions = instructionAST.INSTRUCTIONS_BODY(actual.ChildNodes[10], cant_tabs + 1);

            lista_funciones.AddLast(new Function_Trad(identifier, parametros, declaraciones, fuciones_hijas,
                                                      function_type, new Sentence_Trad(function_instructions), false, cant_tabs, false, ""));


            parametros_her.Clear();

            lista_funciones = FUNCTION_LIST(actual.ChildNodes[12], lista_funciones, parametros_her, cant_tabs);

            return(lista_funciones);
        }
        public While_Trad WHILE(ParseTreeNode actual, int cant_tabs)
        {
            //WHILE.Rule = RESERV_WHILE + LOGIC_EXPRESION + RESERV_DO + INSTRUCTIONS_BODY;

            var condition = (new ExpressionTraduccion()).getExpresion(actual.ChildNodes[1]);

            InstructionTraduccion instructionAST = new InstructionTraduccion();

            LinkedList <Instruction_Trad> lista_instrucciones = instructionAST.INSTRUCTIONS_BODY(actual.ChildNodes[3], cant_tabs + 1);

            return(new While_Trad(condition, new Sentence_Trad(lista_instrucciones), cant_tabs));
        }
Esempio n. 4
0
        public For_Trad SENCECIA_FOR(ParseTreeNode actual, int cant_tabs)
        {
            /*
             * FOR.Rule
             *  = RESERV_FOR + IDENTIFIER + DOS_PUNTOS + EQUALS + LOGIC_EXPRESION + TODOWN + LOGIC_EXPRESION
             + RESERV_DO
             + INSTRUCTIONS_BODY //+ PUNTO_COMA
             +  ;
             +
             + TODOWN.Rule
             +  = RESERV_TO
             | RESERV_DOWN + RESERV_TO
             |  ;
             */
            var ident               = actual.ChildNodes[1].Token.Text;
            var inicio              = expressionAST.getExpresion(actual.ChildNodes[4]);
            var direccion           = actual.ChildNodes[5].ChildNodes[0].Token.Text;
            var fin                 = expressionAST.getExpresion(actual.ChildNodes[6]);
            var lista_instrucciones = instructionAST.INSTRUCTIONS_BODY(actual.ChildNodes[8], cant_tabs + 1);

            return(new For_Trad(ident, inicio, fin, new Sentence_Trad(lista_instrucciones), direccion, cant_tabs));
        }