-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabladeSimbolos.cpp
94 lines (75 loc) · 1.83 KB
/
TabladeSimbolos.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "TabladeSimbolos.h"
#include "EntradaTS.h"
#include "QMap"
TablaDeSimbolos::TablaDeSimbolos()
{
entradas.clear();
indice.clear();
}
void TablaDeSimbolos::insertar(QString s, EntradaTS *e)
{
this->entradas.insert(s,e);
this->indice.push_back(s);
}
bool TablaDeSimbolos::contiene(QString s)
{
return this->entradas.contains(s);
}
bool TablaDeSimbolos::contiene(int key)
{
return (key < this->entradas.size());
}
int TablaDeSimbolos::getIndex(QString s)
{
return this->indice.indexOf(s);
}
void TablaDeSimbolos::modificarLexema(QString lexViejo, QString lexNuevo)
{
EntradaTS * e = entradas.value(lexViejo);
indice.remove(this->getIndex(lexViejo));
entradas.remove(lexViejo);
e->lexema=lexNuevo;
this->insertar(lexNuevo, e);
}
int TablaDeSimbolos::size()
{
return this->entradas.size();
}
QList<QString> TablaDeSimbolos::keys()
{
return this->entradas.keys();
}
EntradaTS *TablaDeSimbolos::value(const QString key)
{
return this->entradas.value(key);
}
EntradaTS *TablaDeSimbolos::value(const int index)
{
return this->entradas.value(this->indice.value(index));
}
QString TablaDeSimbolos::obtenerTipo(QString lexema)
{
EntradaTS * e = this->value(lexema);
if (e!=NULL) {
return e->tipo;
}
return "indefinido";
}
void TablaDeSimbolos::eliminar(QString lexema)
{
if (this->contiene(lexema)) {
this->entradas.remove(lexema);
this->indice.remove(this->getIndex(lexema));
}
}
list<QString>TablaDeSimbolos::imprimir()
{
entradasParaImprimir.clear();
for (int i=0; i<indice.size(); i++) {
EntradaTS * e = entradas.value(indice.at(i));
QString aux = "\nNro. Entrada: " + QString::number(i+1) + " | ";
aux.append(e->toString());
entradasParaImprimir.push_back(aux);
}
return entradasParaImprimir;
};