public AST getImportacion(){
return importacion;
}
+
+ public String referenciaCiclica(TablaModulos mods){
+ String ref = "";
+ String ref2 = "";
+ AST arbol = null;
+ String minombre =nombre;
+ if(importacion != null)
+ arbol = importacion.getFirstChild();
+ else return ref;
+ while(arbol != null){
+ Modulo mod = mods.get(arbol.getText());
+ if(mod.getNombre().equals(nombre)){
+ return nombre + "->" + mod.getNombre();
+ }
+ ref2 = referenciaCiclica(mod, mods);
+ if(!ref2.equals("")){
+ return nombre + "->" + ref2;
+ }
+ arbol = arbol.getNextSibling();
+ }
+
+ return ref;
+ }
+
+ public String referenciaCiclica(Modulo mod, TablaModulos mods){
+ if(mod.getNombre().equals(nombre)){
+ return mod.getNombre();
+ }
+ AST arbol = mod.getImportacion();
+ if(arbol != null)
+ arbol = arbol.getFirstChild();
+ else return "";
+ while(arbol != null){
+ Modulo mod1 = mods.get(arbol.getText());
+ if(mod1.getNombre().equals(nombre)){
+ return mod.getNombre() + "->" + mod1.getNombre();
+ }else{
+ String ref2 =referenciaCiclica(mod1, mods);
+ if(!ref2.equals("")){
+ return mod.getNombre() + "->" + ref2;
+ }
+ }
+ arbol = arbol.getNextSibling();
+ }
+ return "";
+ }
}
li = nombres_modulos.listIterator();
while(li.hasNext()){
ResNom resnom = new ResNom();
+ resnom.setASTNodeClass("ArbolLineas");
nombre_modulo = li.next();
+ String nom2 = nombre_modulo.substring(0, nombre_modulo.length()-4);
+ Modulo mod2 = mods.get(nom2);
+ String refciclica = mod2.referenciaCiclica(mods);
+ if(!refciclica.equals("")){
+ System.out.println("Referencia ciclica: " + refciclica);
+ }
System.out.println("RN modulo: " + nombre_modulo);
resnom.declaracion_modulo(arbol.get(nombre_modulo), tab.get(nombre_modulo), mods);
arbol.put(nombre_modulo, resnom.getAST());
+
+ //ASTFrame frame = new ASTFrame(nombre_modulo, arbol.get(nombre_modulo));
+ //frame.setSize(600, 600);
+ //frame.setVisible(true);
}
- //ASTFrame frame = new ASTFrame("Princial", arbol.get("principal.mod"));
- //frame.setVisible(true);
+
//anasem.declaracion_modulo(arbol);
} catch (ANTLRException ae) {
header{
import java.util.*;
- import antlr.ASTFactory;
-
+ import antlr.ASTFactory;
}
class ResNom extends TreeParser;
tipo_predefinido_simple
| tipo_predefinido_compuesto
| declaracion_error
-| IDENT
+| i:IDENT {#tipo = declaracion_tipo(#i);}
;
tipo_predefinido_simple :
+elemento2.mod;\r
elemento.mod;\r
-pila.mod;\r
-principal.mod;\r
+pila2.mod;\r
\r
modulo elemento\r
\r
+importacion: pila2\r
exportacion:\r
\r
inst clase Elemento\r
--- /dev/null
+modulo elemento2
+
+importacion: elemento
+exportacion:
+inst clase Elemento
+{
+ consultar() dev entero
+ {
+ dev e; // ERROR variable no declarada
+ }
+ oculto entero e;
+ modificar(entero n)
+ {
+ e := haceralgo();
+ }
+ haceralgo() dev entero
+ {
+ dev 10;
+ }
+
+}
+implementacion:
+inst clase Elemento2
+{
+ consultar() dev entero
+ {
+ dev e; // ERROR variable no declarada
+ }
+ oculto entero e;
+ modificar(entero n)
+ {
+ e := haceralgo();
+ }
+ haceralgo() dev entero
+ {
+ dev 10;
+ }
+
+}
\ No newline at end of file
\r
estaLlena() dev logico\r
{\r
+ TipoErr c;\r
+ apilar1(c);\r
si (cima = 100) entonces\r
dev cierto;\r
sino\r
--- /dev/null
+modulo pila2
+
+importacion: elemento2
+
+exportacion:
+// Pila con 100 elementos como maximo
+inst clase Pila
+{
+ oculto Elemento el;
+ Elemento2 e2;
+ oculto entero cima;
+ entero x;
+ iniciar()
+ {
+ cima := 0;
+ }
+ estaLlena() dev logico
+ {
+ // aa
+ // bb
+ si (cima = 100.1) entonces // ERROR Semántico
+ dev cierto;
+ sino
+ dev falso;
+ finsi
+ apilar(0, 0);
+ }
+ apilar(Elemento elem, entero i)
+ {
+ si (no estaLlena()) entonces
+ cima := cima + 1;
+ el := elem;
+ finsi
+ i := 1; // ERROR Semántico
+ e2.haceralgo();
+ }
+ estaVacia() dev logico
+ {
+ si (cima = 0) entonces
+ dev cierto;
+ sino
+ dev falso;
+ finsi
+ }
+ desapilar() dev Elemento
+ {
+ si (no estaVacia(1)) entonces // ERROR Semántico
+ cima := cima - realaentero(1.0);
+ dev el;
+ sino
+ dev el;
+ finsi
+ }
+}
+clase Programa
+{
+ inicio()
+ {
+ Elemento ed;
+ Pila p;
+ TipoErr k; // ERROR tipo no declarado
+ entero i;
+ p := crear(Pila);
+ p.iniciar();
+ i := p.cima;
+ i := Pila; //ERROR
+ i:=1;
+ mientras (i < 10) hacer
+ ed := crear(Pila); // ERROR Semántico
+ ed.modificar(i);
+ p.apilar(ed, i);
+ i:=i+1;
+ finmientras
+ }
+ }
+implementacion:
\ No newline at end of file