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