Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARACION ::= DECLARACION:E1 coma VARIABLES:E2
- {:
- String id = E2.cad;
- if(parser.tabla.obtener(id)==null){
- Simbolo sim = new Simbolo(tipo, id);
- parser.tabla.agregar(id,sim);
- }else{
- //ERROR SEMANTICO
- System.out.println("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR");
- parser.txtConsola.append("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR\n");
- }
- :}
- | TIPO:E1 VARIABLES:E2
- {:
- String id = E2.cad;
- if(parser.tabla.obtener(id)==null){
- Simbolo sim = new Simbolo(tipo, id);
- parser.tabla.agregar(id,sim);
- }else{
- //ERROR SEMANTICO
- System.out.println("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR");
- parser.txtConsola.append("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR\n");
- }
- :}
- ;
- VARIABLES ::= id:E1 igual CONDXTRA:E2
- {:
- RESULT = new Nodo();
- RESULT.cad = E1;
- System.out.println(tipo + E1+"="+E2.temp);
- parser.txtConsola.append(tipo+" "+ E1+"="+E2.temp+"\n");
- if(tipo.equals("int")){
- parser.noInts = parser.noInts + 1;
- }else{
- parser.noBools = parser.noBools + 1;
- }
- :}
- | id:E1
- {:
- RESULT = new Nodo();
- RESULT.cad = E1;
- parser.txtConsola.append(tipo + " "+E1+"\n");
- if(tipo.equals("int")){
- parser.noInts = parser.noInts + 1;
- }else{
- parser.noBools = parser.noBools + 1;
- }
- :}
- ;
- TIPO ::= tint
- {:
- RESULT = new Nodo();
- RESULT.temp = "int";
- tipo = "int";
- :}
- | tboolean
- {:
- RESULT = new Nodo();
- RESULT.temp = "boolean";
- tipo = "boolean";
- :}
- ;
- DECLARACION_ARRAY ::= DECLARACION_ARRAY coma ARRAY:E1
- {:
- Simbolo sim = new Simbolo(tipo, E1.cad, E1.pos);
- parser.tabla.agregar(E1.cad, sim);
- :}
- | TIPO:E1 ARRAY:E2
- {:
- Simbolo sim = new Simbolo(tipo, E2.cad, E2.pos);
- parser.tabla.agregar(E2.cad,sim);
- :}
- ;
- ARRAY ::= ARRAY:E1 corchA num:E2 corchC
- {:
- E1.pos.add(Integer.parseInt(E2));
- RESULT = E1;
- :}
- | id:E1 corchA num:E2 corchC
- {:
- RESULT = new Nodo();
- if(parser.tabla.obtener(E1)==null){
- RESULT.cad = E1;
- RESULT.pos.add(Integer.parseInt(E2));
- parser.noArray = parser.noArray + 1;
- }else{
- //ERROR SEMANTICO
- System.out.println("ERROR SEMANTICO: Ya existe la variable que se quiere declarar");
- parser.txtConsola.append("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR\n");
- }
- :}
- ;
- ASIGNACION ::= id:E1 igual CONDXTRA:E2 puntocoma
- {:
- if(parser.tabla.obtener(E1)!=null){
- System.out.println(E1+"="+E2.temp);
- parser.txtConsola.append(E1+"="+E2.temp+"\n");
- }else{
- //ERROR SEMANTICO
- System.out.println("ERROR SEMANTICO: VARIABLE A LA QUE SE DESEA ASIGNAR NO ESTA DECLARADA");
- parser.txtConsola.append("ERROR SEMANTICO: VARIABLE A LA QUE SE DESEA ASIGNAR NO ESTA DECLARADA\n");
- }
- :}
- | LISTAPOS:E1 igual CONDXTRA:E2 puntocoma
- {:
- String tmp = "";
- if(E2.temp.contains("[")){
- tmp = generarTemp();
- System.out.println(tmp+"="+E2.temp);
- parser.txtConsola.append(tmp+"="+E2.temp+"\n");
- }else{
- tmp = E2.temp;
- }
- System.out.println(E1.cad+"["+E1.temp+"]"+"="+tmp);
- parser.txtConsola.append(E1.cad+"["+E1.temp+"]"+"="+tmp+"\n");
- :}
- ;
Add Comment
Please, Sign In to add comment