def interpretar(AST, consola, salidaSimbolos): global ts ts = None ts = TablaSimbolos() global errores errores = consola.toPlainText() if AST.main != None: ts.agregar(AST.main.name, AST.main.name, TIPO_RELATIVO.LABEL, TIPO_ESPECIFICO.MAIN, AST.main.instructions) for label in AST.labels: ts.agregar(label.name, label.name, TIPO_RELATIVO.LABEL, None, label.instructions) flag1 = False flag2 = False labeles = [AST.main] + AST.labels for label in labeles: for instruction in label.instructions: if isinstance(instruction, Set): if instruction.register.type_ == REGISTER.PARAM: flag1 = True elif isinstance(instruction, Goto): goto = ts.obtener(instruction.label) if goto != None: if goto.tipo_especifico == None: for instr in goto.valor: if isinstance(instr, Set): if instr.register.type_ == REGISTER.DEVUELTO: flag2 = True if flag2: ts.asignarLabelType(instruction.label, TIPO_ESPECIFICO.FUNCION) elif flag1: ts.asignarLabelType(instruction.label, TIPO_ESPECIFICO.PROCEDIMIENTO) else: ts.asignarLabelType(instruction.label, TIPO_ESPECIFICO.CONTROL) flag1 = False flag2 = False elif isinstance(instruction, If): gotoIf = instruction.goto goto = ts.obtener(gotoIf.label) if goto != None: if goto.tipo_especifico == None: for instr in goto.valor: if isinstance(instr, Set): if instr.register.type_ == REGISTER.DEVUELTO: flag2 = True if flag2: ts.asignarLabelType(gotoIf.label, TIPO_ESPECIFICO.FUNCION) elif flag1: ts.asignarLabelType(gotoIf.label, TIPO_ESPECIFICO.PROCEDIMIENTO) else: ts.asignarLabelType(gotoIf.label, TIPO_ESPECIFICO.CONTROL) flag1 = False flag2 = False i_main(AST.main, consola) ts.graph(salidaSimbolos)