Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -20,46 +20,66 @@ def sugerencia_nlp_error(error_msg):
|
|
20 |
"return_full_text": False
|
21 |
}
|
22 |
}
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
def main():
|
29 |
with open("entrada.txt", "r", encoding="utf-8") as f:
|
30 |
codigo = f.read()
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
"comentarios": comentarios_ext
|
52 |
}
|
53 |
|
54 |
with open("analisis.json", "w", encoding="utf-8") as f:
|
55 |
-
json.dump(
|
56 |
-
|
57 |
-
generador = GeneradorIntermedio()
|
58 |
-
intermedio = generador.generar(ast)
|
59 |
-
|
60 |
-
with open("codigo_intermedio.txt", "w", encoding="utf-8") as f:
|
61 |
-
for linea in intermedio:
|
62 |
-
f.write(linea + "\n")
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
main()
|
|
|
20 |
"return_full_text": False
|
21 |
}
|
22 |
}
|
23 |
+
try:
|
24 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload, timeout=10)
|
25 |
+
if response.status_code == 200:
|
26 |
+
return response.json()[0]["generated_text"].strip()
|
27 |
+
return f"(sin sugerencia: {response.status_code})"
|
28 |
+
except:
|
29 |
+
return "(sugerencia no disponible por error de conexi贸n)"
|
30 |
|
31 |
def main():
|
32 |
with open("entrada.txt", "r", encoding="utf-8") as f:
|
33 |
codigo = f.read()
|
34 |
|
35 |
+
errores_lexicos = []
|
36 |
+
errores_parser = []
|
37 |
+
errores_semanticos = []
|
38 |
+
variables = {}
|
39 |
+
comentarios_ext = []
|
40 |
|
41 |
+
try:
|
42 |
+
tokens = lexer(codigo)
|
43 |
+
parser = Parser(tokens)
|
44 |
+
ast = parser.parse()
|
45 |
|
46 |
+
# sem谩ntico solo si parseo con 茅xito
|
47 |
+
semantico = AnalizadorSemantico(ast)
|
48 |
+
resultado = semantico.analizar()
|
49 |
+
errores_semanticos = [
|
50 |
+
{"mensaje": err, "sugerencia": sugerencia_nlp_error(err)}
|
51 |
+
for err in resultado["errores_semanticos"]
|
52 |
+
]
|
53 |
+
variables = resultado["variables_declaradas"]
|
54 |
|
55 |
+
# c贸digo intermedio
|
56 |
+
generador = GeneradorIntermedio()
|
57 |
+
intermedio = generador.generar(ast)
|
58 |
+
with open("codigo_intermedio.txt", "w", encoding="utf-8") as f:
|
59 |
+
for linea in intermedio:
|
60 |
+
f.write(linea + "\n")
|
61 |
+
|
62 |
+
except SyntaxError as e:
|
63 |
+
errores_parser.append(str(e))
|
64 |
+
|
65 |
+
# comentarios NLP
|
66 |
+
try:
|
67 |
+
comentarios_ext = [
|
68 |
+
{"comentario": c, "sugerencia": s}
|
69 |
+
for c, s in procesar_comentarios(codigo)
|
70 |
+
]
|
71 |
+
except:
|
72 |
+
comentarios_ext = []
|
73 |
+
|
74 |
+
analisis = {
|
75 |
+
"variables_declaradas": variables,
|
76 |
+
"errores_parser": errores_parser,
|
77 |
+
"errores_semanticos": errores_semanticos,
|
78 |
"comentarios": comentarios_ext
|
79 |
}
|
80 |
|
81 |
with open("analisis.json", "w", encoding="utf-8") as f:
|
82 |
+
json.dump(analisis, f, indent=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
if __name__ == "__main__":
|
85 |
main()
|