diff options
Diffstat (limited to 'compilador/tabla.py')
-rw-r--r-- | compilador/tabla.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/compilador/tabla.py b/compilador/tabla.py index c8ca424..637b9a6 100644 --- a/compilador/tabla.py +++ b/compilador/tabla.py @@ -1,3 +1,4 @@ +import json, os from enum import Enum from dataclasses import dataclass from typing import Any @@ -63,6 +64,22 @@ class TablaLex: self.tabla[i] = tok return + def exportar(self, output_file): + data = [] + for t in self.tabla: + data.append({ + 'tipo': t.tipo, + 'nombre': t.nombre, + 'valor': str(t.valor), + 'numlinea': t.numlinea + }) + output = json.dumps(data) + if os.path.exists(output_file): + os.remove(output_file) + with open(output_file, 'w+') as f: + f.truncate(0) + f.write(output) + def __str__(self): output = "" for t in self.tabla: |