-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymbols.js
94 lines (83 loc) · 2.66 KB
/
Symbols.js
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
93
94
export class Symbols {
constructor() {
this.allVariables = {};
}
addVariable(nombre, valor, tipo, simbType, linea, columna) {
this.allVariables[nombre] = { valor, tipo, simbType, linea, columna };
}
updateVariable(nombre, valor) {
if (this.allVariables[nombre]) {
this.allVariables[nombre].valor = valor;
} else {
console.error(`Variable: ${nombre} - no se encuentra en la tabla de simbolos.`);
}
}
getVariable(nombre) {
return this.allVariables[nombre];
}
generateHTMLTable() {
let htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Symbol Table</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #829BB9;
color: white;
}
</style>
</head>
<body>
<table border="1">
<tr>
<th>ID</th>
<th>Tipo</th>
<th>Valor</th>
<th>Fila</th>
<th>Columna</th>
<th>Estructura</th>
</tr>`;
for (let nombre in this.allVariables) {
const variable = this.allVariables[nombre];
htmlContent += `
<tr>
<td>${nombre}</td>
<td>${variable.tipo}</td>
<td>${variable.valor}</td>
<td>${variable.linea}</td>
<td>${variable.columna}</td>
<td>${variable.simbType}</td>
</tr>`;
}
htmlContent += `
</table>
</body>
</html>`;
// documenta creado de esta manera usar unicamente javascript vanilla
// blob para crear el archivo
const blob = new Blob([htmlContent], { type: 'text/html' });
const url = URL.createObjectURL(blob);
// link para poder descargar
const a = document.createElement('a');
a.href = url;
a.download = 'SymTable.html';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// liberar la url
URL.revokeObjectURL(url);
console.log("tabla de simbolos creada");
}
};