public object MORE_ARRAY(ParseTreeNode actual, string name)
        {
            /*
             * MORE_ARRAY.Rule
             *  = DATA_TYPE
             | RESERV_ARRAY + COR_IZQ + EXPLOGICA + PUNTO + PUNTO + EXPLOGICA + COR_DER + RESERV_OF + MORE_ARRAY;
             |  ;
             */
            if (actual.ChildNodes.Count == 1)
            {
                return(actual.ChildNodes[0].ChildNodes[0].Token.Text);
            }
            else
            {
                var row = actual.ChildNodes[0].Token.Location.Line;
                var col = actual.ChildNodes[0].Token.Location.Column;

                ExpressionAST expressionAST = new ExpressionAST();
                var           limit_inf     = expressionAST.getExpresion(actual.ChildNodes[2]);
                var           limit_sup     = expressionAST.getExpresion(actual.ChildNodes[5]);

                var resultado = MORE_ARRAY(actual.ChildNodes[8], name);

                //Instruction exp = null;
                if (resultado is string)
                {
                    return(new ArraysMultiple(name, limit_inf, limit_sup, resultado.ToString(), resultado.ToString(), null, row, col, 1));
                }
                else
                {
                    var exp = (ArraysMultiple)resultado;
                    return(new ArraysMultiple(name, limit_inf, limit_sup, exp.DataType, exp.Auxiliar, exp, row, col, exp.Contador + 1));
                }
            }
        }
        public Instruction ARRAYs(ParseTreeNode actual, string name)
        {
            /*
             * ARRAY.Rule =
             * RESERV_ARRAY  + COR_IZQ + EXPLOGICA + PUNTO + PUNTO + EXPLOGICA + COR_DER + RESERV_OF + MORE_ARRAY + PUNTO_COMA;
             */
            ExpressionAST expressionAST = new ExpressionAST();
            var           limit_inf     = expressionAST.getExpresion(actual.ChildNodes[2]);
            var           limit_sup     = expressionAST.getExpresion(actual.ChildNodes[5]);

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

            var resultado = MORE_ARRAY(actual.ChildNodes[8], name);

            if (resultado is string)
            {
                return(new Arrays(name, limit_inf, limit_sup, resultado.ToString(), row, col));
            }
            else
            {
                var res = (ArraysMultiple)resultado;
                return(new ArraysMultiple(name, limit_inf, limit_sup, res.DataType, res.Auxiliar, res, row, col, res.Contador + 1));
            }
        }
        public ArrayList CALL_PARAMETERS(ParseTreeNode actual, ArrayList expresiones)
        {
            /*
             * CALL_PARAMETERS.Rule
             *  = EXPRESION + CALL_PARAMETERS
             | COMA + EXPRESION + CALL_PARAMETERS
             | Empty
             |  ;
             */
            if (actual.ChildNodes.Count > 0)
            {
                if (actual.ChildNodes.Count == 2)
                {
                    var expr = (expressionAST.getExpresion(actual.ChildNodes[0]));
                    expresiones.Add(expr);
                    expresiones = CALL_PARAMETERS(actual.ChildNodes[1], expresiones);
                }

                else
                {
                    var expr = expressionAST.getExpresion(actual.ChildNodes[1]);

                    expresiones.Add(expr);

                    expresiones = CALL_PARAMETERS(actual.ChildNodes[2], expresiones);
                }
            }
            return(expresiones);
        }
Example #4
0
        public LinkedList <Expression> WRITES(ParseTreeNode actual)
        {
            LinkedList <Expression> list = new LinkedList <Expression>();

            if (actual.ChildNodes.Count > 0)
            {
                var exp = expressionAST.getExpresion(actual.ChildNodes[0]);
                list.AddLast(exp);
                list = WRHITE_PARAMETER(actual.ChildNodes[1], list);
            }
            return(list);
        }
Example #5
0
        public LinkedList <Instruction> LIST_DECLARATIONS(ParseTreeNode actual, LinkedList <Instruction> lista_actual, ArrayList elementos_her)
        {
            /*
             * DECLARATION_LIST.Rule
             * = RESERV_VAR + IDENTIFIER + DECLARATION_BODY + VAR_DECLARATION + DECLARATION_LIST
             | Empty
             | ;
             */

            if (actual.ChildNodes.Count != 0)
            {
                //VERIFICA SI ES VAR O CONST
                var tipo = actual.ChildNodes[0];

                //ES CONST
                if (tipo.Term.ToString().Equals("RESERV_CONST"))
                {
                    var identifier = actual.ChildNodes[1].Token.Text;
                    lista_actual.AddLast(new Declaration(identifier, expressionAST.getExpresion(actual.ChildNodes[3]), 0, 0, true));
                    lista_actual = CONST_DECLARATION(actual.ChildNodes[5], lista_actual, elementos_her);
                    lista_actual = LIST_DECLARATIONS(actual.ChildNodes[6], lista_actual, elementos_her);
                }
                //ES VAR
                else
                {
                    var identifier = actual.ChildNodes[1].Token.Text;
                    elementos_her.Add(identifier);

                    lista_actual = DECLARATION_BODY(actual.ChildNodes[2], lista_actual, elementos_her);
                    lista_actual = VAR_DECLARATION(actual.ChildNodes[3], lista_actual, elementos_her);
                    lista_actual = LIST_DECLARATIONS(actual.ChildNodes[4], lista_actual, elementos_her);
                }

                return(lista_actual);
            }


            return(lista_actual);
        }
        public Switch SENTENCE_CASE(ParseTreeNode actual)
        {
            /*
             *  SENTENCE_CASE.Rule = RESERV_CASE  + LOGIC_EXPRESION + RESERV_OF + CASES + CASE_ELSE + RESERV_END + PUNTO_COMA;
             *
             *
             *
             * CASE_ELSE.Rule = RESERV_ELSE + INSTRUCTIONS
             | Empty
             |  ;
             */

            var       condicion   = expressionAST.getExpresion(actual.ChildNodes[1]);
            ArrayList lista_cases = new ArrayList();

            lista_cases = CASES(actual.ChildNodes[3], lista_cases);

            var else_case = CASE_ELSE(actual.ChildNodes[4]);

            var row    = actual.ChildNodes[0].Token.Location.Line;
            var column = actual.ChildNodes[0].Token.Location.Column;

            return(new Switch(condicion, lista_cases, else_case, row, column));
        }
        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));
        }
        public IF IFTHEN(ParseTreeNode actual)
        {
            /*
             * IFTHEN.Rule
             *  = RESERV_IF + EXPRESION
             + RESERV_THEN
             + IF_SENTENCE
             + ELIF;
             */
            IF            ifs           = new IF();
            ExpressionAST expressionAST = new ExpressionAST();
            var           row           = actual.ChildNodes[0].Token.Location.Line;
            var           col           = actual.ChildNodes[0].Token.Location.Column;

            var LOGIC_EXPRESION = expressionAST.getExpresion(actual.ChildNodes[1]);
            var SENTENCES       = IF_SENTENCE(actual.ChildNodes[3]);
            var ELSE            = ELIF(actual.ChildNodes[4]);


            return(new IF(LOGIC_EXPRESION, SENTENCES, ELSE, row, col));
        }