Example #1
0
 public EnvValues(EnvValues entorno)
 {
     tablaValores = new Dictionary<string, Valor>();
     previo = entorno;
     pila = new Stack<EnvValues>();
     id = cont++;
 }
Example #2
0
 public Parser(string path)
 {
     lex = new Lexer(path);
     entornoTipos = new EnvTypes(null);
     entornoValores = new EnvValues(null);
     pilaValores = new Stack<EnvValues>();
     pilaValores.Push(new EnvValues(null));
 }
Example #3
0
        Sentence function_declaration(Tipo retorno, string id)
        {
            EnvTypes savedEnvTypes = entornoTipos;
            entornoTipos = new EnvTypes(entornoTipos);

            //EnvValues savedEnvValues = entornoValores;
            //entornoValores = new EnvValues(entornoValores);
            EnvValues savedEnvValues = Parser.pilaValores.Peek();
            Parser.pilaValores.Push(new EnvValues(Parser.pilaValores.Peek()));

            match("(");
            Dictionary<string,Tipo> paramsTypeList = parameter_type_list();
            match(")");

            FunctionDefinition funcDefinition = new FunctionDefinition();
            funcionActual = funcDefinition;

            Sentence compoundStmnt = function_definition();

            funcDefinition.init(id, retorno, compoundStmnt);
            entornoTipos = savedEnvTypes;
            entornoValores = savedEnvValues;

            Parser.pilaValores.Pop();

            Funcion funcion = new Funcion(retorno, paramsTypeList);
            entornoTipos.put(id, funcion);

            ValorFuncion funcionVal = new ValorFuncion(funcDefinition);
            //entornoValores.put(id, funcionVal);
            Parser.pilaValores.Peek().put(id, funcionVal);

            funcionActual = null;

            if (id == "main")
            {
                main = funcDefinition;
            }

            return funcDefinition;
        }
Example #4
0
 void enum_initializer_listP(List<VariableDeclarator> vars, EnvValues savedEnvValues, EnvTypes savedEnvTypes)
 {
     if (peek(","))
     {
         match(",");
         VariableDeclarator varDec = enum_constant_expression(savedEnvValues, savedEnvTypes);
         vars.Add(varDec);
         enum_initializer_listP(vars, savedEnvValues, savedEnvTypes);
     }
     //null
 }
Example #5
0
 List<VariableDeclarator> enum_initializer_list(EnvValues savedEnvValues, EnvTypes savedEnvTypes)
 {
     List<VariableDeclarator> varDecList = new List<VariableDeclarator>();
     VariableDeclarator varDec = enum_constant_expression(savedEnvValues, savedEnvTypes);
     varDecList.Add(varDec);
     enum_initializer_listP(varDecList, savedEnvValues, savedEnvTypes);
     return varDecList;
 }
Example #6
0
        Sentence enum_initializer(string enumName)
        {
            if (peek("{"))
            {
                EnvTypes savedEnvTypes = entornoTipos;
                entornoTipos = new EnvTypes(entornoTipos);

                EnvValues savedEnvValues = entornoValores;
                entornoValores = new EnvValues(null);

                match("{");
                List<VariableDeclarator> varsDec = enum_initializer_list(savedEnvValues, savedEnvTypes);
                match("}");

                EnumerationDeclaration enumDeclaration = new EnumerationDeclaration(enumName, varsDec, savedEnvValues);
                ValorEnumeracion valEnum = new ValorEnumeracion();
                Enumeracion varEnum = new Enumeracion(entornoTipos);
                valEnum.valor = entornoValores;

                entornoTipos = savedEnvTypes;
                entornoTipos.put(enumName, varEnum);

                entornoValores = savedEnvValues;
                entornoValores.put(enumName, valEnum);
                return enumDeclaration;
            }
            else
            {
                Tipo varEnum = entornoTipos.get(enumName);
                Valor valEnum = entornoValores.get(enumName);

                string enumVarName = currentToken.Lexema;
                match(TokenType.ID);

                EnumerationVariableDeclaration enumVarDeclaration = new EnumerationVariableDeclaration(enumName, enumVarName, varEnum, valEnum);
                entornoTipos.put(enumVarName, varEnum);
                return enumVarDeclaration;
            }
        }
Example #7
0
        VariableDeclarator enum_constant_expression(EnvValues savedEnvValues, EnvTypes savedEnvTypes)
        {
            string varName = variable_name();

            EnvValues savedEnvValues2 = entornoValores;
            entornoValores = savedEnvValues;
            VariableInitializer varInit = enum_constant_expressionP();
            entornoValores = savedEnvValues2;

            VariableSubDeclarator varSubDec = new VariableSubDeclarator(new Entero(), varName);

            entornoTipos.put(varName, new Entero());
            savedEnvTypes.put(varName, new Entero());
            VariableDeclarator varDeclarator = new VariableDeclarator(varSubDec, varInit);
            return varDeclarator;
        }
Example #8
0
        Sentence variable_declaration_listP(Sentence primerDeclaracionVariable, EnvTypes savedEnvTypes, EnvValues savedEnvValues)
        {
            switch (currentToken.Tipo)
            {
                case TokenType.STRING:
                case TokenType.BOOL:
                case TokenType.CHAR:
                case TokenType.FLOAT:
                case TokenType.INT:
                    Tipo tipoVariables = variable_type();
                    string idVariable = direct_variable_declarator();
                    Tipo tipoVariable = variable_array(tipoVariables);
                    match(";");

                    VariableSubDeclarator segundaVariable = new VariableSubDeclarator(tipoVariable, idVariable);
                    VariableDeclarator segundaDeclaracionVariable = new VariableDeclarator(segundaVariable, null);

                    SentenceSenquence stSeq = new SentenceSenquence(primerDeclaracionVariable, segundaDeclaracionVariable);
                    entornoTipos.put(idVariable, tipoVariable);
                    return variable_declaration_listP(stSeq, savedEnvTypes, savedEnvValues);

                case TokenType.STRUCT:
                    string structName = struct_declarator();

                    Tipo varRecord = savedEnvTypes.get(structName);
                    Valor valRecord = savedEnvValues.get(structName);

                    string structVarName = variable_name();
                    match(";");

                    StructVariableDeclaration strVarDec = new StructVariableDeclaration(structName, structVarName, varRecord, valRecord);

                    SentenceSenquence stSeq2 = new SentenceSenquence(primerDeclaracionVariable, strVarDec);
                    entornoTipos.put(structVarName, varRecord);
                    return variable_declaration_listP(stSeq2, savedEnvTypes, savedEnvValues);

                case TokenType.ENUM:
                    string enumName = enum_declarator();
                    Tipo varEnum = savedEnvTypes.get(enumName);
                    Valor valEnum = savedEnvValues.get(enumName);

                    string enumVarName = currentToken.Lexema;
                    match(TokenType.ID);

                    entornoTipos.put(enumName, varEnum);
                    EnumerationVariableDeclaration enumVarDec = new EnumerationVariableDeclaration(enumName, enumVarName, varEnum, valEnum);
                    SentenceSenquence stSeq3 = new SentenceSenquence(primerDeclaracionVariable, enumVarDec);
                    return variable_declaration_listP(stSeq3, savedEnvTypes, savedEnvValues);

                default:
                    return primerDeclaracionVariable;//null
            }
        }
Example #9
0
        Sentence do_while()
        {
            EnvTypes savedEnvTypes = entornoTipos;
            entornoTipos = new EnvTypes(entornoTipos);

            EnvValues savedEnvValues = entornoValores;
            entornoValores = new EnvValues(entornoValores);

            DoWhileStatement doWhileStmnt = new DoWhileStatement();
            Sentence cicloAnterior = cicloActual;
            cicloActual = doWhileStmnt;

            match("do");
            Sentence stmnt = compound_statement();
            match("while");
            match("(");
            Expr expresion = expr();
            match(")");
            match(";");

            doWhileStmnt.DoWhileInit(expresion, stmnt);
            cicloActual = cicloAnterior;

            entornoTipos = savedEnvTypes;
            entornoValores = savedEnvValues;
            return doWhileStmnt;
        }
Example #10
0
        Sentence struct_declarationP(string structName)
        {
            if (peek("{"))
            {
                match("{");
                EnvTypes savedEnvTypes = entornoTipos;
                entornoTipos = new EnvTypes(null);

                EnvValues savedEnvValues = entornoValores;
                entornoValores = new EnvValues(null);

                Sentence strVarDecs = variable_declaration_list(savedEnvTypes, savedEnvValues);
                match("}");

                Registro record = new Registro(entornoTipos);
                ValorRegistro Valrec = new ValorRegistro();
                Valrec.valor = entornoValores;

                entornoTipos = savedEnvTypes;
                entornoTipos.put(structName, record);

                entornoValores = savedEnvValues;
                entornoValores.put(structName, Valrec);

                return strVarDecs;
            }
            else
            {
                Tipo varRecord = entornoTipos.get(structName);
                Valor valRecord = entornoValores.get(structName);

                string strVarName = variable_name();

                entornoTipos.put(strVarName, varRecord);
                //entornoValores.put(strVarName, valRecord);
                return new StructVariableDeclaration(structName, strVarName, varRecord, valRecord);
            }
        }
Example #11
0
        Sentence variable_declaration_list(EnvTypes savedEnvTypes, EnvValues savedEnvValues)
        {
            switch (currentToken.Tipo)
            {
                case TokenType.STRING:
                case TokenType.BOOL:
                case TokenType.CHAR:
                case TokenType.FLOAT:
                case TokenType.INT:
                    Tipo tipoVariables = variable_type();
                    string idVariable = direct_variable_declarator();
                    Tipo tipoVariable = variable_array(tipoVariables);
                    match(";");

                    VariableSubDeclarator primerVariable = new VariableSubDeclarator(tipoVariable, idVariable);
                    VariableDeclarator primerDeclaracionVariable = new VariableDeclarator(primerVariable, null);

                    entornoTipos.put(idVariable, tipoVariable);
                    return variable_declaration_listP(primerDeclaracionVariable, savedEnvTypes, savedEnvValues);

                case TokenType.STRUCT:
                    string structName = struct_declarator();

                    Tipo varRecord = savedEnvTypes.get(structName);
                    Valor valRecord = savedEnvValues.get(structName);

                    string structVarName = variable_name();
                    match(";");

                    StructVariableDeclaration strVarDec = new StructVariableDeclaration(structName, structVarName, varRecord,valRecord);

                    entornoTipos.put(structVarName, varRecord);
                    return variable_declaration_listP(strVarDec, savedEnvTypes, savedEnvValues);

                case TokenType.ENUM:
                    string enumName = enum_declarator();
                    Tipo varEnum = savedEnvTypes.get(enumName);
                    Valor valEnum = savedEnvValues.get(enumName);

                    string enumVarName = currentToken.Lexema;
                    match(TokenType.ID);

                    entornoTipos.put(enumName, varEnum);
                    EnumerationVariableDeclaration enumVarDec = new EnumerationVariableDeclaration(enumName, enumVarName, varEnum, valEnum);

                    return variable_declaration_listP(enumVarDec, savedEnvTypes, savedEnvValues);

                default:
                    throw new Exception("Error en la declaracion de variables de struct linea: " + Lexer.line + " columna: " + Lexer.column + " currenttoken = " + currentToken.Lexema);
            }
        }
Example #12
0
 public Tipo()
 {
     ownerEnv = Parser.entornoValores;
 }
Example #13
0
        public FunctionDefinition()
        {
            entornoTiposLocal = Parser.entornoTipos;
            entornoValoresLocal = Parser.pilaValores.Peek();

            ValorRetorno = null;
            returned = false;
        }
Example #14
0
        public FunctionDefinition(string nombreFuncion, Tipo ret, Sentence cpStmnt)
        {
            idFuncion = nombreFuncion;
            Tiporetorno = ret;
            compoundStatement = cpStmnt;
            entornoTiposLocal = Parser.entornoTipos;
            entornoValoresLocal = Parser.entornoValores;

            ValorRetorno = null;
            returned = false;
        }
Example #15
0
        public EnumerationVariableDeclaration(string enumName, string enumVarName, Tipo tipoenum, Valor valEnum)
        {
            enumerationName = enumName;
            enumerationVarName = enumVarName;
            tipo = tipoenum;

            valorEnum = valEnum;
            entornoValoresActual = Parser.entornoValores;
        }
Example #16
0
 public EnumerationDeclaration(string id, List<VariableDeclarator> vars, EnvValues entorno)
 {
     enumId = id;
     variables = vars;
     entornoValoresEnum = Parser.entornoValores;
     entornoLocal = entorno;
 }