Пример #1
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);
            }
        }
Пример #2
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
            }
        }
Пример #3
0
        Sentence statement()
        {
            switch (currentToken.Tipo)
            {
                case TokenType.STRING:
                case TokenType.BOOL:
                case TokenType.CHAR:
                case TokenType.FLOAT:
                case TokenType.INT:
                    Sentence decStmt = declaration_statement();
                    match(";");
                    return decStmt;

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

                    Tipo varRecord = entornoTipos.get(strId);
                    Valor valRecord = entornoValores.get(strId);

                    string strVarName = currentToken.Lexema;
                    match(TokenType.ID);
                    entornoTipos.put(strVarName, varRecord);

                    StructVariableDeclaration strVarDec = new StructVariableDeclaration(strId, strVarName, varRecord, valRecord);
                    match(";");
                    return strVarDec;

                case TokenType.ENUM:
                    Sentence sentence = enum_declaration();
                    match(";");
                    return sentence;

                case TokenType.DECREMENT:
                case TokenType.INCREMENT:
                case TokenType.ID:
                    Sentence expStmt = expression_statement();
                    match(";");
                    return expStmt;

                case TokenType.IF:
                    return if_statement();

                case TokenType.DO:
                    return do_while();

                case TokenType.WHILE:
                    return while_statement();

                case TokenType.FOR:
                    return for_statement();

                case TokenType.BREAK:
                    Sentence brkStmnt = break_statement();
                    match(";");
                    return brkStmnt;

                case TokenType.CONTINUE:
                    Sentence contStmnt = continue_statement();
                    match(";");
                    return contStmnt;

                case TokenType.RETURN:
                    Sentence ret = return_statement();
                    match(";");
                    return ret;

                case TokenType.CIN:
                    Sentence sCin = cin();
                    match(";");
                    return sCin;

                case TokenType.COUT:
                    Sentence sCout = cout();
                    match(";");
                    return sCout;

                default:
                    //return null;
                    Sentence empty = new EmptySentence();
                    match(";");
                    return empty;
            }
            //null
        }