diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-11-16 20:07:28 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-11-16 20:07:28 -0600 |
commit | b20e23d221ac418deb8fa495fa375f715511f953 (patch) | |
tree | 9731460f5f3b95128f33e1a5bebaf92eeeae9c33 /compilador/tabla.py | |
parent | e4cf758129e81cf3e400a1432ec2d6604fe67a2d (diff) | |
download | javanol-b20e23d221ac418deb8fa495fa375f715511f953.tar.gz javanol-b20e23d221ac418deb8fa495fa375f715511f953.tar.bz2 javanol-b20e23d221ac418deb8fa495fa375f715511f953.zip |
Se añade tabla de símbolos a la interfaz
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: |