3 import antlr.ASTFactory;
7 class ResNom extends TreeParser;
18 void resolver_identificadores_tipo(){
19 Identificador_Tipo elemento;
21 LinkedList<Identificador_Tipo> i;
22 i = t.identtiposinresolver.getIdentificadores();
23 ListIterator<Identificador_Tipo> li = i.listIterator();
25 elemento = (Identificador_Tipo) li.next();
26 nombre = elemento.getNombre();
27 if(t.ambitomodulo.getDeclaracion(nombre) == null){
28 //identificador de tipo no declarado
29 System.out.println("ERROR RN: identificador " + nombre + " no declarado");
34 AST resolver_acceso_simple(String numero){
35 int no = Integer.parseInt(numero);
36 //nombre y ambito contenedor del acceso
37 Acceso acc = t.accesossinresolver.getAcceso(no);
38 String nom = acc.getNombre();
39 Ambito amb = acc.getContenedor();
42 AST dec = #(#[ERROR, "error"]);
43 //comprobar si se ha declarado, buscando en la tabla de ambitos y declaraciones
44 if((sim = t.tablaambitos.buscar_simbolo(amb, nom)) == null){
45 //acceso simple no declarado
46 System.out.println("ERROR RN: acceso simple " + nom + " no declarado");
49 dec = sim.getDeclaracion(); //referencia adelantada
55 AST declaracion_tipo(AST ident){
56 AST tipo = #(#[ERROR, "error"]);
57 Ambito modulo = t.ambitomodulo;
58 Simbolo s = modulo.getDeclaracion(ident.getText());
60 ASTFactory f = new ASTFactory();
61 tipo = f.dupTree(s.getDeclaracion());
67 declaracion_modulo [Tabla_Global tab]:
69 resolver_identificadores_tipo();}
70 #(MODULO nombre_modulo definicion_modulo);
72 // =============================== del fichero anasem.g ============================
74 nombre_modulo : IDENT ;
82 importacion : #(IMPORTACION lista_ident);
83 lista_ident: (IDENT)+;
85 exportacion : #(EXPORTACION lista_declaraciones_clases);
87 implementacion : #(IMPLEMENTACION lista_declaraciones_clases);
89 lista_declaraciones_clases: (declaracion_clase)*
92 declaracion_clase : #(CLASE nombre_clase cualificador_clase definicion_clase)
95 cualificador_clase : INST | NO_INST ;
97 nombre_clase : IDENT ;
99 definicion_clase : declaraciones_elementos_clase
102 declaraciones_elementos_clase : (declaracion_elemento_clase)* ;
104 declaracion_elemento_clase :
105 #(METODO declaracion_metodo cualificador_elemento_clase)
106 | #(ATRIBUTO IDENT tipo cualificador_elemento_clase)
109 cualificador_elemento_clase: OCULTO | VISIBLE ;
111 declaracion_metodo : prototipo_metodo definicion_metodo;
113 prototipo_metodo: #(PROTOTIPO IDENT #(PARAMETROS declaracion_parametros)
114 #(RESULTADO (tipo | VACIO)));
116 declaracion_parametros : (declaracion_parametro)* ;
118 declaracion_parametro : #(PARAMETRO IDENT tipo) ;
120 definicion_metodo: #(DEFINICION #(VARIABLES_LOCALES declaracion_variables_locales) #(INSTRUCCIONES instrucciones))
123 declaracion_variables_locales : (declaracion_variable_local)* ;
125 declaracion_variable_local : #(VARIABLE_LOCAL IDENT tipo) ;
127 declaracion_error : ERROR;
129 instrucciones : (instruccion)* ;
131 instruccion : #(INSTRUCCION ( instruccion_simple | instruccion_compuesta))
134 instruccion_simple : llamada_metodo
141 instruccion_compuesta :
146 crear : #(CREAR expresion expresion);
147 escribir : #(ESCRIBIR expresion);
149 asignacion : #(ASIGNACION expresion expresion );
151 retorno: #(DEV expresion)
155 #(LLAMADA acceso #(EXPRESIONES lista_expresiones))
158 lista_expresiones: (expresion)* ;
160 condicion: #(SI expresion #(INSTRUCCIONES instrucciones)
161 (#(INSTRUCCIONES instrucciones))?)
164 iteracion : #(MIENTRAS expresion #(INSTRUCCIONES
168 #(O expresion expresion)
169 | #(Y expresion expresion)
171 | #(op1:MAYOR expresion expresion)
172 | #(op2:MAYOR_IGUAL expresion expresion)
173 | #(op3:MENOR expresion expresion)
174 | #(op4:MENOR_IGUAL expresion expresion)
175 | #(op5:IGUAL expresion expresion)
176 | #(op6:DISTINTO expresion expresion)
177 | #(MAS expresion expresion)
178 | #(MENOS expresion expresion)
179 | #(MENOSUNARIO expresion)
180 | #(POR expresion expresion)
181 | #(DIVISION expresion expresion)
182 | #(LLAMADA acceso #(EXPRESIONES lista_expresiones))
183 | #(ACCESO_TABLA acceso #(EXPRESIONES lista_expresiones_nv))
190 | #(ENTERO_A_REAL expresion)
191 | #(REAL_A_ENTERO expresion)
195 acceso : acceso_simple
196 | #(ACCESO_OBJETO acceso_simple a:IDENT);
198 acceso_simple : #(ACCESO_SIMPLE IDENT d:declaracion_acceso)
201 declaracion_acceso: declaracion_modulo[t]
203 | declaracion_elemento_clase
204 | declaracion_parametro
205 | declaracion_variable_local
208 {#declaracion_acceso = resolver_acceso_simple(i.getText());}
211 lista_expresiones_nv : (expresion)+;
214 tipo_predefinido_simple
215 | tipo_predefinido_compuesto
217 | i:IDENT {#tipo = declaracion_tipo(#i);}
220 tipo_predefinido_simple :
227 tipo_predefinido_compuesto : formacion;
229 formacion : #(FORMACION #(LISTA_ENTEROS lista_enteros)
230 (tipo_predefinido_simple | IDENT));
232 lista_enteros : (LIT_ENTERO)+ ;