Guest User

Untitled

a guest
Jan 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. DECLARACION ::= DECLARACION:E1 coma VARIABLES:E2
  2. {:
  3. String id = E2.cad;
  4. if(parser.tabla.obtener(id)==null){
  5. Simbolo sim = new Simbolo(tipo, id);
  6. parser.tabla.agregar(id,sim);
  7. }else{
  8. //ERROR SEMANTICO
  9. System.out.println("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR");
  10.  
  11. parser.txtConsola.append("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR\n");
  12. }
  13. :}
  14. | TIPO:E1 VARIABLES:E2
  15. {:
  16. String id = E2.cad;
  17. if(parser.tabla.obtener(id)==null){
  18. Simbolo sim = new Simbolo(tipo, id);
  19. parser.tabla.agregar(id,sim);
  20. }else{
  21. //ERROR SEMANTICO
  22. System.out.println("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR");
  23. parser.txtConsola.append("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR\n");
  24. }
  25. :}
  26. ;
  27.  
  28. VARIABLES ::= id:E1 igual CONDXTRA:E2
  29. {:
  30. RESULT = new Nodo();
  31. RESULT.cad = E1;
  32. System.out.println(tipo + E1+"="+E2.temp);
  33.  
  34. parser.txtConsola.append(tipo+" "+ E1+"="+E2.temp+"\n");
  35.  
  36. if(tipo.equals("int")){
  37. parser.noInts = parser.noInts + 1;
  38. }else{
  39. parser.noBools = parser.noBools + 1;
  40. }
  41. :}
  42. | id:E1
  43. {:
  44. RESULT = new Nodo();
  45. RESULT.cad = E1;
  46.  
  47. parser.txtConsola.append(tipo + " "+E1+"\n");
  48.  
  49. if(tipo.equals("int")){
  50. parser.noInts = parser.noInts + 1;
  51. }else{
  52. parser.noBools = parser.noBools + 1;
  53. }
  54. :}
  55. ;
  56.  
  57. TIPO ::= tint
  58. {:
  59. RESULT = new Nodo();
  60. RESULT.temp = "int";
  61. tipo = "int";
  62. :}
  63. | tboolean
  64. {:
  65. RESULT = new Nodo();
  66. RESULT.temp = "boolean";
  67. tipo = "boolean";
  68. :}
  69. ;
  70.  
  71. DECLARACION_ARRAY ::= DECLARACION_ARRAY coma ARRAY:E1
  72. {:
  73. Simbolo sim = new Simbolo(tipo, E1.cad, E1.pos);
  74. parser.tabla.agregar(E1.cad, sim);
  75. :}
  76. | TIPO:E1 ARRAY:E2
  77. {:
  78. Simbolo sim = new Simbolo(tipo, E2.cad, E2.pos);
  79. parser.tabla.agregar(E2.cad,sim);
  80. :}
  81. ;
  82.  
  83. ARRAY ::= ARRAY:E1 corchA num:E2 corchC
  84. {:
  85. E1.pos.add(Integer.parseInt(E2));
  86. RESULT = E1;
  87. :}
  88. | id:E1 corchA num:E2 corchC
  89. {:
  90. RESULT = new Nodo();
  91. if(parser.tabla.obtener(E1)==null){
  92. RESULT.cad = E1;
  93. RESULT.pos.add(Integer.parseInt(E2));
  94.  
  95. parser.noArray = parser.noArray + 1;
  96. }else{
  97. //ERROR SEMANTICO
  98. System.out.println("ERROR SEMANTICO: Ya existe la variable que se quiere declarar");
  99. parser.txtConsola.append("ERROR SEMANTICO: YA EXISTE LA VARIABLE QUE SE QUIERE DECLARAR\n");
  100. }
  101. :}
  102. ;
  103.  
  104. ASIGNACION ::= id:E1 igual CONDXTRA:E2 puntocoma
  105. {:
  106. if(parser.tabla.obtener(E1)!=null){
  107. System.out.println(E1+"="+E2.temp);
  108.  
  109. parser.txtConsola.append(E1+"="+E2.temp+"\n");
  110. }else{
  111. //ERROR SEMANTICO
  112. System.out.println("ERROR SEMANTICO: VARIABLE A LA QUE SE DESEA ASIGNAR NO ESTA DECLARADA");
  113. parser.txtConsola.append("ERROR SEMANTICO: VARIABLE A LA QUE SE DESEA ASIGNAR NO ESTA DECLARADA\n");
  114. }
  115. :}
  116. | LISTAPOS:E1 igual CONDXTRA:E2 puntocoma
  117. {:
  118. String tmp = "";
  119. if(E2.temp.contains("[")){
  120. tmp = generarTemp();
  121. System.out.println(tmp+"="+E2.temp);
  122.  
  123. parser.txtConsola.append(tmp+"="+E2.temp+"\n");
  124. }else{
  125. tmp = E2.temp;
  126. }
  127. System.out.println(E1.cad+"["+E1.temp+"]"+"="+tmp);
  128.  
  129. parser.txtConsola.append(E1.cad+"["+E1.temp+"]"+"="+tmp+"\n");
  130. :}
  131. ;
Add Comment
Please, Sign In to add comment