Ejemplo n.º 1
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
            }
        }
Ejemplo n.º 2
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);
            }
        }