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; }
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; }
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; }
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 }
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 } }
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); } }
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; } }
public VariableDeclarator(VariableSubDeclarator dec, Initializers init) { declaration = dec; initialization = init; }