Spaces:
Running
Running
| class GeneradorIntermedio: | |
| def generar(self, ast): | |
| codigo = [] | |
| temp_count = 0 | |
| def nueva_temp(): | |
| nonlocal temp_count | |
| temp = f"t{temp_count}" | |
| temp_count += 1 | |
| return temp | |
| for nodo in ast: | |
| if nodo["type"] == "assign": | |
| temp = nueva_temp() | |
| codigo.append(f"{temp} = {nodo['value']['value']}") | |
| codigo.append(f"{nodo['var']} = {temp}") | |
| elif nodo["type"] == "function": | |
| if nodo["arg"] is not None: | |
| temp = nueva_temp() | |
| codigo.append(f"PARAM {nodo['arg']['value']}") | |
| codigo.append(f"CALL {nodo['name']}") | |
| else: | |
| codigo.append(f"CALL {nodo['name']}") | |
| return codigo |