Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -36,28 +36,37 @@ def main():
|
|
| 36 |
errores_semanticos = []
|
| 37 |
variables = {}
|
| 38 |
comentarios_ext = []
|
|
|
|
| 39 |
|
| 40 |
try:
|
| 41 |
tokens = lexer(codigo)
|
| 42 |
parser = Parser(tokens)
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
intermedio = generador.generar(ast)
|
| 55 |
-
with open("codigo_intermedio.txt", "w", encoding="utf-8") as f:
|
| 56 |
-
for linea in intermedio:
|
| 57 |
-
f.write(linea + "\n")
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
try:
|
| 63 |
comentarios_ext = [
|
|
|
|
| 36 |
errores_semanticos = []
|
| 37 |
variables = {}
|
| 38 |
comentarios_ext = []
|
| 39 |
+
ast = []
|
| 40 |
|
| 41 |
try:
|
| 42 |
tokens = lexer(codigo)
|
| 43 |
parser = Parser(tokens)
|
| 44 |
+
try:
|
| 45 |
+
ast = parser.parse()
|
| 46 |
+
except SyntaxError as e:
|
| 47 |
+
errores_parser.append(str(e))
|
| 48 |
+
ast = []
|
| 49 |
+
except Exception as e:
|
| 50 |
+
errores_parser.append(f"Error en el lexer o parser: {str(e)}")
|
| 51 |
+
ast = []
|
| 52 |
|
| 53 |
+
if ast:
|
| 54 |
+
try:
|
| 55 |
+
semantico = AnalizadorSemantico(ast)
|
| 56 |
+
resultado = semantico.analizar()
|
| 57 |
+
errores_semanticos = [
|
| 58 |
+
{"mensaje": err, "sugerencia": sugerencia_nlp_error(err)}
|
| 59 |
+
for err in resultado["errores_semanticos"]
|
| 60 |
+
]
|
| 61 |
+
variables = resultado["variables_declaradas"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
generador = GeneradorIntermedio()
|
| 64 |
+
intermedio = generador.generar(ast)
|
| 65 |
+
with open("codigo_intermedio.txt", "w", encoding="utf-8") as f:
|
| 66 |
+
for linea in intermedio:
|
| 67 |
+
f.write(linea + "\n")
|
| 68 |
+
except Exception as e:
|
| 69 |
+
errores_semanticos.append({"mensaje": str(e), "sugerencia": "(no procesado)"})
|
| 70 |
|
| 71 |
try:
|
| 72 |
comentarios_ext = [
|