Ethgoin's picture
third update to App.py
3fdac99 verified
raw
history blame
932 Bytes
import gradio as gr
import json
from lexer import lexer
from parser import Parser
from semantico import AnalizadorSemantico
def analizar_codigo(archivo_ruta):
try:
with open(archivo_ruta, "r", encoding="utf-8") as f:
contenido = f.read()
tokens = lexer(contenido)
parser = Parser(tokens)
ast = parser.parse()
analizador = AnalizadorSemantico(ast)
resultado = analizador.analizar()
errores = "\\n".join(resultado["errores_semanticos"])
return errores, json.dumps(resultado, indent=2)
except Exception as e:
return f"Error: {e}", "{}"
gr.Interface(
fn=analizar_codigo,
inputs=gr.File(label="Sube tu archivo de código (.txt)"),
outputs=[
gr.Textbox(label="Errores detectados"),
gr.Code(label="Contenido de analisis.json", language="json")
],
title="Analizador Semántico - Lenguaje de Robots"
).launch()