Ejemplo n.º 1
0
        public Sentence IF_SENTENCE(ParseTreeNode actual)
        {
            /*
             * IF_SENTENCE.Rule = INSTRUCTIONS_BODY
             | Empty
             |  ;
             |
             */
            Sentence sentence = new Sentence();

            if (actual.ChildNodes.Count > 0)
            {
                var lista_instrucciones = instructionAST.INSTRUCTIONS_BODY(actual.ChildNodes[0]);
                sentence = new Sentence(lista_instrucciones);
            }

            return(sentence);
        }
        public LinkedList <Instruction> getFunciones(ParseTreeNode actual, LinkedList <Instruction> lista_funciones, ArrayList elementos_her)
        {
            /*
             * FUNCTION_LIST.Rule
             *  = RESERV_FUNCTION + IDENTIFIER + PAR_IZQ + PARAMETER + PAR_DER + DOS_PUNTOS + DATA_TYPE + PUNTO_COMA
             + DECLARATION_LIST_HIJA
             + INSTRUCTIONS_BODY
             + PUNTO_COMA
             + FUNCTION_LIST
             | Empty
             |  ;
             */
            int row = actual.ChildNodes[0].Token.Location.Line;
            int col = actual.ChildNodes[0].Token.Location.Column;

            LinkedList <Instruction> parametros    = new LinkedList <Instruction>();
            LinkedList <Instruction> declaraciones = new LinkedList <Instruction>();

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

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



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

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


            var function_instructions = instructionAST.INSTRUCTIONS_BODY(actual.ChildNodes[9]);

            lista_funciones.AddLast(new Function(identifier, parametros, declaraciones, function_type.ToLower(), new Sentence(function_instructions), false, row, col));

            elementos_her.Clear();
            lista_funciones = FUNCTION_LIST(actual.ChildNodes[11], lista_funciones, elementos_her);

            return(lista_funciones);
        }
Ejemplo n.º 3
0
        public While WHILE(ParseTreeNode actual)
        {
            //WHILE.Rule = RESERV_WHILE + LOGIC_EXPRESION + RESERV_DO + INSTRUCTIONS_BODY;

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

            int row = actual.ChildNodes[0].Token.Location.Line;
            int col = actual.ChildNodes[0].Token.Location.Column;


            InstructionAST instructionAST = new InstructionAST();

            LinkedList <Instruction> lista_instrucciones = instructionAST.INSTRUCTIONS_BODY(actual.ChildNodes[3]);

            return(new While(condition, new Sentence(lista_instrucciones), row, col));
        }
Ejemplo n.º 4
0
        public FOR SENCECIA_FOR(ParseTreeNode actual)
        {
            /*
             * 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]);
            var row                 = actual.ChildNodes[0].Token.Location.Line;
            var col                 = actual.ChildNodes[0].Token.Location.Column;

            return(new FOR(ident, inicio, fin, new Sentence(lista_instrucciones), direccion, row, col));
        }