示例#1
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;
        }
示例#2
0
        Sentence constant_declaration()
        {
            match("const");

            Tipo tipoVariables = variable_type();
            tipoVariables.isConstant = true;

            string idVariable = direct_variable_declarator();
            Tipo tipoVariable = variable_array(tipoVariables);

            Initializers const_init = const_variable_initializer();

            VariableSubDeclarator primerVariable = new VariableSubDeclarator(tipoVariable, idVariable);
            VariableDeclarator constDeclaracionVariable = new VariableDeclarator(primerVariable, const_init);
            match(";");
            entornoTipos.put(idVariable, tipoVariable);
            return constDeclaracionVariable;
        }
示例#3
0
        Sentence declaration_statement()
        {
            Tipo tipoVariables = variable_type();//tipo basico para todas las variables, si hay mas

            string idVariable = direct_variable_declarator();
            Tipo tipoVariable = variable_array(tipoVariables);

            VariableSubDeclarator primerVariable = new VariableSubDeclarator(tipoVariable, idVariable);

            VariableDeclarator primerDeclaracionVariable = new VariableDeclarator(primerVariable, null);//todavia no hemos visto inicializadores

            VariableDeclarations variableDeclarations = variable_declarator(primerDeclaracionVariable, tipoVariables);//para las variables que siguen

            return variableDeclarations;
        }
示例#4
0
        VariableDeclaration variable_declarators(VariableDeclaration beforeDeclaration, Tipo tipoVariables)
        {
            if (peek(","))
            {
                match(",");

                string idVariable = direct_variable_declarator();
                Tipo tipoVariable = variable_array(tipoVariables);
                Initializers init = variable_initializer();

                entornoTipos.put(idVariable, tipoVariable);//tablasimbolos

                VariableSubDeclarator variableActual = new VariableSubDeclarator(tipoVariable, idVariable);
                VariableDeclarator actualDeclaration = new VariableDeclarator(variableActual, init);
                VariableDeclarators variableDeclarators = new VariableDeclarators(beforeDeclaration, actualDeclaration);

                return variable_declarators(variableDeclarators, tipoVariables);
            }
            else
                return beforeDeclaration;//null
        }
示例#5
0
        VariableDeclarations variable_declarator(VariableDeclarator primerVariable, Tipo tipoVariables)
        {
            primerVariable.initialization = variable_initializer();//primer variable viene sin inicializador

            entornoTipos.put(primerVariable.declaration.id, primerVariable.declaration.tipo);//tablasimbolos

            VariableDeclaration listaDeclaracionVariables = variable_declarators(primerVariable, tipoVariables);

            return new VariableDeclarations(listaDeclaracionVariables);
        }
示例#6
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
            }
        }
示例#7
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);
            }
        }
示例#8
0
        Sentence variable_declaration()
        {
            Tipo tipoVariables = variable_type();//tipo basico para todas las variables, si hay mas

            string idVariable = direct_variable_declarator();
            Tipo tipoVariable = variable_array(tipoVariables);

            if (peek("("))
                return function_declaration(tipoVariable, idVariable);
            else
            {
                VariableSubDeclarator primerVariable = new VariableSubDeclarator(tipoVariable, idVariable);

                VariableDeclarator primerDeclaracionVariable = new VariableDeclarator(primerVariable, null);//todavia no hemos visto inicializadores

                VariableDeclarations variableDeclarations = variable_declarator(primerDeclaracionVariable, tipoVariables);//para las variables que siguen
                match(";");

                return variableDeclarations;
            }
        }