@designliquido/delegua 0.8.1 → 0.9.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/package.json +1 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.d.ts +2 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js +3 -0
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico.d.ts +2 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico.js +14 -0
- package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +2 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +3 -0
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.d.ts +2 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +12 -0
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -1
- package/fontes/bibliotecas/biblioteca-global.js +351 -177
- package/fontes/bibliotecas/biblioteca-global.js.map +1 -1
- package/fontes/construtos/acesso-indice-variavel.d.ts +1 -1
- package/fontes/construtos/acesso-indice-variavel.js +41 -1
- package/fontes/construtos/acesso-indice-variavel.js.map +1 -1
- package/fontes/construtos/acesso-metodo.d.ts +1 -1
- package/fontes/construtos/acesso-metodo.js +41 -1
- package/fontes/construtos/acesso-metodo.js.map +1 -1
- package/fontes/construtos/agrupamento.d.ts +1 -1
- package/fontes/construtos/agrupamento.js +41 -1
- package/fontes/construtos/agrupamento.js.map +1 -1
- package/fontes/construtos/atribuicao-sobrescrita.d.ts +2 -1
- package/fontes/construtos/atribuicao-sobrescrita.js +41 -1
- package/fontes/construtos/atribuicao-sobrescrita.js.map +1 -1
- package/fontes/construtos/atribuir.d.ts +1 -1
- package/fontes/construtos/atribuir.js +41 -1
- package/fontes/construtos/atribuir.js.map +1 -1
- package/fontes/construtos/binario.d.ts +1 -1
- package/fontes/construtos/binario.js +41 -1
- package/fontes/construtos/binario.js.map +1 -1
- package/fontes/construtos/chamada.d.ts +1 -1
- package/fontes/construtos/chamada.js +41 -1
- package/fontes/construtos/chamada.js.map +1 -1
- package/fontes/construtos/conjunto.d.ts +2 -1
- package/fontes/construtos/conjunto.js +41 -1
- package/fontes/construtos/conjunto.js.map +1 -1
- package/fontes/construtos/construto.d.ts +1 -1
- package/fontes/construtos/dicionario.d.ts +2 -1
- package/fontes/construtos/dicionario.js +41 -1
- package/fontes/construtos/dicionario.js.map +1 -1
- package/fontes/construtos/funcao.d.ts +1 -1
- package/fontes/construtos/funcao.js +41 -1
- package/fontes/construtos/funcao.js.map +1 -1
- package/fontes/construtos/isto.d.ts +2 -1
- package/fontes/construtos/isto.js +41 -1
- package/fontes/construtos/isto.js.map +1 -1
- package/fontes/construtos/literal.d.ts +1 -1
- package/fontes/construtos/literal.js +41 -1
- package/fontes/construtos/literal.js.map +1 -1
- package/fontes/construtos/logico.d.ts +2 -1
- package/fontes/construtos/logico.js +41 -1
- package/fontes/construtos/logico.js.map +1 -1
- package/fontes/construtos/super.d.ts +2 -2
- package/fontes/construtos/super.js +41 -1
- package/fontes/construtos/super.js.map +1 -1
- package/fontes/construtos/unario.d.ts +2 -1
- package/fontes/construtos/unario.js +41 -1
- package/fontes/construtos/unario.js.map +1 -1
- package/fontes/construtos/variavel.d.ts +1 -1
- package/fontes/construtos/variavel.js +41 -1
- package/fontes/construtos/variavel.js.map +1 -1
- package/fontes/construtos/vetor.d.ts +2 -1
- package/fontes/construtos/vetor.js +41 -1
- package/fontes/construtos/vetor.js.map +1 -1
- package/fontes/declaracoes/bloco.d.ts +1 -1
- package/fontes/declaracoes/bloco.js +41 -1
- package/fontes/declaracoes/bloco.js.map +1 -1
- package/fontes/declaracoes/classe.d.ts +2 -2
- package/fontes/declaracoes/classe.js +41 -1
- package/fontes/declaracoes/classe.js.map +1 -1
- package/fontes/declaracoes/continua.d.ts +2 -2
- package/fontes/declaracoes/continua.js +41 -1
- package/fontes/declaracoes/continua.js.map +1 -1
- package/fontes/declaracoes/declaracao.d.ts +2 -1
- package/fontes/declaracoes/declaracao.js +41 -1
- package/fontes/declaracoes/declaracao.js.map +1 -1
- package/fontes/declaracoes/enquanto.d.ts +2 -1
- package/fontes/declaracoes/enquanto.js +41 -1
- package/fontes/declaracoes/enquanto.js.map +1 -1
- package/fontes/declaracoes/escolha.d.ts +2 -1
- package/fontes/declaracoes/escolha.js +41 -1
- package/fontes/declaracoes/escolha.js.map +1 -1
- package/fontes/declaracoes/escreva.d.ts +1 -1
- package/fontes/declaracoes/escreva.js +41 -1
- package/fontes/declaracoes/escreva.js.map +1 -1
- package/fontes/declaracoes/expressao.d.ts +1 -1
- package/fontes/declaracoes/expressao.js +41 -1
- package/fontes/declaracoes/expressao.js.map +1 -1
- package/fontes/declaracoes/fazer.d.ts +2 -1
- package/fontes/declaracoes/fazer.js +41 -1
- package/fontes/declaracoes/fazer.js.map +1 -1
- package/fontes/declaracoes/funcao.d.ts +1 -1
- package/fontes/declaracoes/funcao.js +41 -1
- package/fontes/declaracoes/funcao.js.map +1 -1
- package/fontes/declaracoes/importar.d.ts +2 -1
- package/fontes/declaracoes/importar.js +41 -1
- package/fontes/declaracoes/importar.js.map +1 -1
- package/fontes/declaracoes/leia.d.ts +1 -1
- package/fontes/declaracoes/leia.js +44 -1
- package/fontes/declaracoes/leia.js.map +1 -1
- package/fontes/declaracoes/para.d.ts +2 -1
- package/fontes/declaracoes/para.js +41 -1
- package/fontes/declaracoes/para.js.map +1 -1
- package/fontes/declaracoes/retorna.d.ts +1 -1
- package/fontes/declaracoes/retorna.js +41 -1
- package/fontes/declaracoes/retorna.js.map +1 -1
- package/fontes/declaracoes/se.d.ts +1 -1
- package/fontes/declaracoes/se.js +41 -1
- package/fontes/declaracoes/se.js.map +1 -1
- package/fontes/declaracoes/sustar.d.ts +1 -1
- package/fontes/declaracoes/sustar.js +41 -1
- package/fontes/declaracoes/sustar.js.map +1 -1
- package/fontes/declaracoes/tente.d.ts +1 -1
- package/fontes/declaracoes/tente.js +41 -1
- package/fontes/declaracoes/tente.js.map +1 -1
- package/fontes/declaracoes/var.d.ts +1 -1
- package/fontes/declaracoes/var.js +41 -1
- package/fontes/declaracoes/var.js.map +1 -1
- package/fontes/delegua.d.ts +3 -3
- package/fontes/delegua.js +136 -61
- package/fontes/delegua.js.map +1 -1
- package/fontes/depuracao/servidor-depuracao.d.ts +4 -4
- package/fontes/depuracao/servidor-depuracao.js +121 -47
- package/fontes/depuracao/servidor-depuracao.js.map +1 -1
- package/fontes/estruturas/funcao-padrao.d.ts +1 -1
- package/fontes/estruturas/funcao-padrao.js +46 -2
- package/fontes/estruturas/funcao-padrao.js.map +1 -1
- package/fontes/estruturas/funcao.d.ts +1 -1
- package/fontes/estruturas/funcao.js +74 -28
- package/fontes/estruturas/funcao.js.map +1 -1
- package/fontes/interfaces/avaliador-sintatico-interface.d.ts +5 -4
- package/fontes/interfaces/delegua-interface.d.ts +2 -2
- package/fontes/interfaces/interpretador-com-depuracao-interface.d.ts +3 -4
- package/fontes/interfaces/interpretador-interface.d.ts +6 -5
- package/fontes/interpretador/dialetos/egua-classico.d.ts +31 -30
- package/fontes/interpretador/dialetos/egua-classico.js +906 -470
- package/fontes/interpretador/dialetos/egua-classico.js.map +1 -1
- package/fontes/interpretador/interpretador-com-depuracao.d.ts +6 -6
- package/fontes/interpretador/interpretador-com-depuracao.js +280 -155
- package/fontes/interpretador/interpretador-com-depuracao.js.map +1 -1
- package/fontes/interpretador/interpretador.d.ts +43 -34
- package/fontes/interpretador/interpretador.js +1045 -535
- package/fontes/interpretador/interpretador.js.map +1 -1
- package/fontes/lexador/lexador.js +2 -2
- package/fontes/lexador/lexador.js.map +1 -1
- package/fontes/lexador/palavras-reservadas.d.ts +22 -21
- package/fontes/lexador/palavras-reservadas.js +22 -21
- package/fontes/lexador/palavras-reservadas.js.map +1 -1
- package/fontes/resolvedor/dialetos/egua-classico.d.ts +25 -3
- package/fontes/resolvedor/dialetos/egua-classico.js +40 -0
- package/fontes/resolvedor/dialetos/egua-classico.js.map +1 -1
- package/fontes/tipos-de-simbolos/delegua.d.ts +2 -1
- package/fontes/tipos-de-simbolos/delegua.js +2 -1
- package/fontes/tipos-de-simbolos/delegua.js.map +1 -1
- package/fontes/tipos-de-simbolos/eguap.d.ts +1 -0
- package/fontes/tipos-de-simbolos/eguap.js +1 -0
- package/fontes/tipos-de-simbolos/eguap.js.map +1 -1
- package/package.json +1 -1
- package/testes/biblioteca-global.test.js +424 -181
- package/testes/biblioteca-global.test.js.map +1 -1
- package/testes/egua-classico/interpretador.test.js +379 -163
- package/testes/egua-classico/interpretador.test.js.map +1 -1
- package/testes/eguap/interpretador.test.js +388 -172
- package/testes/eguap/interpretador.test.js.map +1 -1
- package/testes/interpretador.test.js +876 -399
- package/testes/interpretador.test.js.map +1 -1
|
@@ -22,6 +22,42 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (_) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
25
61
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
63
|
};
|
|
@@ -84,23 +120,35 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
84
120
|
return Boolean(objeto);
|
|
85
121
|
return true;
|
|
86
122
|
};
|
|
87
|
-
InterpretadorEguaClassico.prototype.verificarOperandoNumero = function (operador,
|
|
88
|
-
if (typeof
|
|
123
|
+
InterpretadorEguaClassico.prototype.verificarOperandoNumero = function (operador, operando) {
|
|
124
|
+
if (typeof operando === 'number' || operando.tipo === 'número')
|
|
89
125
|
return;
|
|
90
126
|
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operador precisa ser um número.', operador.linha);
|
|
91
127
|
};
|
|
92
128
|
InterpretadorEguaClassico.prototype.visitarExpressaoUnaria = function (expr) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var direita, valor;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0: return [4 /*yield*/, this.avaliar(expr.direita)];
|
|
134
|
+
case 1:
|
|
135
|
+
direita = _a.sent();
|
|
136
|
+
valor = direita.hasOwnProperty('valor') ?
|
|
137
|
+
direita.valor :
|
|
138
|
+
direita;
|
|
139
|
+
switch (expr.operador.tipo) {
|
|
140
|
+
case delegua_1.default.SUBTRACAO:
|
|
141
|
+
this.verificarOperandoNumero(expr.operador, valor);
|
|
142
|
+
return [2 /*return*/, -valor];
|
|
143
|
+
case delegua_1.default.NEGACAO:
|
|
144
|
+
return [2 /*return*/, !this.eVerdadeiro(valor)];
|
|
145
|
+
case delegua_1.default.BIT_NOT:
|
|
146
|
+
return [2 /*return*/, ~valor];
|
|
147
|
+
}
|
|
148
|
+
return [2 /*return*/, null];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
104
152
|
};
|
|
105
153
|
InterpretadorEguaClassico.prototype.eIgual = function (esquerda, direita) {
|
|
106
154
|
if (esquerda.tipo) {
|
|
@@ -134,128 +182,172 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
134
182
|
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
|
|
135
183
|
};
|
|
136
184
|
InterpretadorEguaClassico.prototype.visitarExpressaoBinaria = function (expressao) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
var esquerda, direita, valorEsquerdo, valorDireito, tipoEsquerdo, tipoDireito, erro_1;
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
switch (_a.label) {
|
|
189
|
+
case 0:
|
|
190
|
+
_a.trys.push([0, 3, , 4]);
|
|
191
|
+
return [4 /*yield*/, this.avaliar(expressao.esquerda)];
|
|
192
|
+
case 1:
|
|
193
|
+
esquerda = _a.sent();
|
|
194
|
+
return [4 /*yield*/, this.avaliar(expressao.direita)];
|
|
195
|
+
case 2:
|
|
196
|
+
direita = _a.sent();
|
|
197
|
+
valorEsquerdo = esquerda.hasOwnProperty('valor')
|
|
198
|
+
? esquerda.valor
|
|
199
|
+
: esquerda;
|
|
200
|
+
valorDireito = direita.hasOwnProperty('valor')
|
|
201
|
+
? direita.valor
|
|
202
|
+
: direita;
|
|
203
|
+
tipoEsquerdo = esquerda.hasOwnProperty('tipo')
|
|
204
|
+
? esquerda.tipo
|
|
205
|
+
: (0, inferenciador_1.inferirTipoVariavel)(esquerda);
|
|
206
|
+
tipoDireito = direita.hasOwnProperty('tipo')
|
|
207
|
+
? direita.tipo
|
|
208
|
+
: (0, inferenciador_1.inferirTipoVariavel)(direita);
|
|
209
|
+
switch (expressao.operador.tipo) {
|
|
210
|
+
case delegua_1.default.EXPONENCIACAO:
|
|
211
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
212
|
+
return [2 /*return*/, Math.pow(valorEsquerdo, valorDireito)];
|
|
213
|
+
case delegua_1.default.MAIOR:
|
|
214
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
215
|
+
return [2 /*return*/, Number(valorEsquerdo) > Number(valorDireito)];
|
|
216
|
+
case delegua_1.default.MAIOR_IGUAL:
|
|
217
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
218
|
+
return [2 /*return*/, Number(valorEsquerdo) >= Number(valorDireito)];
|
|
219
|
+
case delegua_1.default.MENOR:
|
|
220
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
221
|
+
return [2 /*return*/, Number(valorEsquerdo) < Number(valorDireito)];
|
|
222
|
+
case delegua_1.default.MENOR_IGUAL:
|
|
223
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
224
|
+
return [2 /*return*/, Number(valorEsquerdo) <= Number(valorDireito)];
|
|
225
|
+
case delegua_1.default.SUBTRACAO:
|
|
226
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
227
|
+
return [2 /*return*/, Number(valorEsquerdo) - Number(valorDireito)];
|
|
228
|
+
case delegua_1.default.ADICAO:
|
|
229
|
+
if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
|
|
230
|
+
return [2 /*return*/, Number(esquerda) + Number(direita)];
|
|
231
|
+
}
|
|
232
|
+
else if (tipoEsquerdo === 'texto' &&
|
|
233
|
+
tipoDireito === 'texto') {
|
|
234
|
+
return [2 /*return*/, String(esquerda) + String(direita)];
|
|
235
|
+
}
|
|
236
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
|
|
237
|
+
case delegua_1.default.DIVISAO:
|
|
238
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
239
|
+
return [2 /*return*/, Number(valorEsquerdo) / Number(valorDireito)];
|
|
240
|
+
case delegua_1.default.MULTIPLICACAO:
|
|
241
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
242
|
+
return [2 /*return*/, Number(valorEsquerdo) * Number(valorDireito)];
|
|
243
|
+
case delegua_1.default.MODULO:
|
|
244
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
245
|
+
return [2 /*return*/, Number(valorEsquerdo) % Number(valorDireito)];
|
|
246
|
+
case delegua_1.default.BIT_AND:
|
|
247
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
248
|
+
return [2 /*return*/, Number(valorEsquerdo) & Number(valorDireito)];
|
|
249
|
+
case delegua_1.default.BIT_XOR:
|
|
250
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
251
|
+
return [2 /*return*/, Number(valorEsquerdo) ^ Number(valorDireito)];
|
|
252
|
+
case delegua_1.default.BIT_OR:
|
|
253
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
254
|
+
return [2 /*return*/, Number(valorEsquerdo) | Number(valorDireito)];
|
|
255
|
+
case delegua_1.default.MENOR_MENOR:
|
|
256
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
257
|
+
return [2 /*return*/, Number(valorEsquerdo) << Number(valorDireito)];
|
|
258
|
+
case delegua_1.default.MAIOR_MAIOR:
|
|
259
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
260
|
+
return [2 /*return*/, Number(valorEsquerdo) >> Number(valorDireito)];
|
|
261
|
+
case delegua_1.default.DIFERENTE:
|
|
262
|
+
return [2 /*return*/, !this.eIgual(valorEsquerdo, valorDireito)];
|
|
263
|
+
case delegua_1.default.IGUAL_IGUAL:
|
|
264
|
+
return [2 /*return*/, this.eIgual(valorEsquerdo, valorDireito)];
|
|
265
|
+
}
|
|
266
|
+
return [2 /*return*/, null];
|
|
267
|
+
case 3:
|
|
268
|
+
erro_1 = _a.sent();
|
|
269
|
+
return [2 /*return*/, Promise.reject(erro_1)];
|
|
270
|
+
case 4: return [2 /*return*/];
|
|
177
271
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
181
|
-
return Number(valorEsquerdo) / Number(valorDireito);
|
|
182
|
-
case delegua_1.default.MULTIPLICACAO:
|
|
183
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
184
|
-
return Number(valorEsquerdo) * Number(valorDireito);
|
|
185
|
-
case delegua_1.default.MODULO:
|
|
186
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
187
|
-
return Number(valorEsquerdo) % Number(valorDireito);
|
|
188
|
-
case delegua_1.default.BIT_AND:
|
|
189
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
190
|
-
return Number(valorEsquerdo) & Number(valorDireito);
|
|
191
|
-
case delegua_1.default.BIT_XOR:
|
|
192
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
193
|
-
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
194
|
-
case delegua_1.default.BIT_OR:
|
|
195
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
196
|
-
return Number(valorEsquerdo) | Number(valorDireito);
|
|
197
|
-
case delegua_1.default.MENOR_MENOR:
|
|
198
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
199
|
-
return Number(valorEsquerdo) << Number(valorDireito);
|
|
200
|
-
case delegua_1.default.MAIOR_MAIOR:
|
|
201
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
202
|
-
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
203
|
-
case delegua_1.default.DIFERENTE:
|
|
204
|
-
return !this.eIgual(valorEsquerdo, valorDireito);
|
|
205
|
-
case delegua_1.default.IGUAL_IGUAL:
|
|
206
|
-
return this.eIgual(valorEsquerdo, valorDireito);
|
|
207
|
-
}
|
|
208
|
-
return null;
|
|
272
|
+
});
|
|
273
|
+
});
|
|
209
274
|
};
|
|
210
275
|
InterpretadorEguaClassico.prototype.visitarExpressaoDeChamada = function (expressao) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
276
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
277
|
+
var variavelEntidadeChamada, entidadeChamada, argumentos, i, _a, _b, parametros, diferenca, i, novosArgumentos;
|
|
278
|
+
return __generator(this, function (_c) {
|
|
279
|
+
switch (_c.label) {
|
|
280
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
|
|
281
|
+
case 1:
|
|
282
|
+
variavelEntidadeChamada = _c.sent();
|
|
283
|
+
entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
|
|
284
|
+
? variavelEntidadeChamada.valor
|
|
285
|
+
: variavelEntidadeChamada;
|
|
286
|
+
argumentos = [];
|
|
287
|
+
i = 0;
|
|
288
|
+
_c.label = 2;
|
|
289
|
+
case 2:
|
|
290
|
+
if (!(i < expressao.argumentos.length)) return [3 /*break*/, 5];
|
|
291
|
+
_b = (_a = argumentos).push;
|
|
292
|
+
return [4 /*yield*/, this.avaliar(expressao.argumentos[i])];
|
|
293
|
+
case 3:
|
|
294
|
+
_b.apply(_a, [_c.sent()]);
|
|
295
|
+
_c.label = 4;
|
|
296
|
+
case 4:
|
|
297
|
+
i++;
|
|
298
|
+
return [3 /*break*/, 2];
|
|
299
|
+
case 5:
|
|
300
|
+
if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
|
|
301
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
|
|
302
|
+
}
|
|
303
|
+
if (entidadeChamada instanceof funcao_1.DeleguaFuncao) {
|
|
304
|
+
parametros = entidadeChamada.declaracao.parametros;
|
|
305
|
+
}
|
|
306
|
+
else if (entidadeChamada instanceof delegua_classe_1.DeleguaClasse) {
|
|
307
|
+
parametros = entidadeChamada.metodos.inicializacao
|
|
308
|
+
? entidadeChamada.metodos.inicializacao.declaracao.parametros
|
|
309
|
+
: [];
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
parametros = [];
|
|
313
|
+
}
|
|
314
|
+
// Isso aqui completa os parâmetros não preenchidos com nulos.
|
|
315
|
+
if (argumentos.length < entidadeChamada.aridade()) {
|
|
316
|
+
diferenca = entidadeChamada.aridade() - argumentos.length;
|
|
317
|
+
for (i = 0; i < diferenca; i++) {
|
|
318
|
+
argumentos.push(null);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
if (parametros &&
|
|
323
|
+
parametros.length > 0 &&
|
|
324
|
+
parametros[parametros.length - 1]['tipo'] === 'estrela') {
|
|
325
|
+
novosArgumentos = argumentos.slice(0, parametros.length - 1);
|
|
326
|
+
novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
|
|
327
|
+
argumentos = novosArgumentos;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
|
|
331
|
+
return [2 /*return*/, entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome)];
|
|
332
|
+
}
|
|
333
|
+
return [2 /*return*/, entidadeChamada.chamar(this, argumentos)];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
});
|
|
254
337
|
};
|
|
255
338
|
InterpretadorEguaClassico.prototype.visitarExpressaoDeAtribuicao = function (expressao) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
339
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
340
|
+
var valor;
|
|
341
|
+
return __generator(this, function (_a) {
|
|
342
|
+
switch (_a.label) {
|
|
343
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.valor)];
|
|
344
|
+
case 1:
|
|
345
|
+
valor = _a.sent();
|
|
346
|
+
this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
|
|
347
|
+
return [2 /*return*/, valor];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
});
|
|
259
351
|
};
|
|
260
352
|
InterpretadorEguaClassico.prototype.procurarVariavel = function (simbolo, expressao) {
|
|
261
353
|
return this.pilhaEscoposExecucao.obterVariavel(simbolo);
|
|
@@ -264,187 +356,360 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
264
356
|
return this.procurarVariavel(expressao.simbolo, expressao);
|
|
265
357
|
};
|
|
266
358
|
InterpretadorEguaClassico.prototype.visitarDeclaracaoDeExpressao = function (declaracao) {
|
|
267
|
-
return this
|
|
359
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
360
|
+
return __generator(this, function (_a) {
|
|
361
|
+
switch (_a.label) {
|
|
362
|
+
case 0: return [4 /*yield*/, this.avaliar(declaracao.expressao)];
|
|
363
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
});
|
|
268
367
|
};
|
|
269
368
|
InterpretadorEguaClassico.prototype.visitarExpressaoLogica = function (expressao) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
369
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
370
|
+
var esquerda, direita;
|
|
371
|
+
return __generator(this, function (_a) {
|
|
372
|
+
switch (_a.label) {
|
|
373
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.esquerda)];
|
|
374
|
+
case 1:
|
|
375
|
+
esquerda = _a.sent();
|
|
376
|
+
if (!(expressao.operador.tipo === delegua_1.default.EM)) return [3 /*break*/, 3];
|
|
377
|
+
return [4 /*yield*/, this.avaliar(expressao.direita)];
|
|
378
|
+
case 2:
|
|
379
|
+
direita = _a.sent();
|
|
380
|
+
if (Array.isArray(direita) || typeof direita === 'string') {
|
|
381
|
+
return [2 /*return*/, direita.includes(esquerda)];
|
|
382
|
+
}
|
|
383
|
+
else if (direita.constructor === Object) {
|
|
384
|
+
return [2 /*return*/, esquerda in direita];
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
|
|
388
|
+
}
|
|
389
|
+
_a.label = 3;
|
|
390
|
+
case 3:
|
|
391
|
+
// se um estado for verdadeiro, retorna verdadeiro
|
|
392
|
+
if (expressao.operador.tipo === delegua_1.default.OU) {
|
|
393
|
+
if (this.eVerdadeiro(esquerda))
|
|
394
|
+
return [2 /*return*/, esquerda];
|
|
395
|
+
}
|
|
396
|
+
// se um estado for falso, retorna falso
|
|
397
|
+
if (expressao.operador.tipo === delegua_1.default.E) {
|
|
398
|
+
if (!this.eVerdadeiro(esquerda))
|
|
399
|
+
return [2 /*return*/, esquerda];
|
|
400
|
+
}
|
|
401
|
+
return [4 /*yield*/, this.avaliar(expressao.direita)];
|
|
402
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
});
|
|
294
406
|
};
|
|
295
407
|
InterpretadorEguaClassico.prototype.visitarExpressaoSe = function (declaracao) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
408
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
409
|
+
var _a, i, atual, _b;
|
|
410
|
+
return __generator(this, function (_c) {
|
|
411
|
+
switch (_c.label) {
|
|
412
|
+
case 0:
|
|
413
|
+
_a = this.eVerdadeiro;
|
|
414
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicao)];
|
|
415
|
+
case 1:
|
|
416
|
+
if (!_a.apply(this, [_c.sent()])) return [3 /*break*/, 3];
|
|
417
|
+
return [4 /*yield*/, this.executar(declaracao.caminhoEntao)];
|
|
418
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
419
|
+
case 3:
|
|
420
|
+
i = 0;
|
|
421
|
+
_c.label = 4;
|
|
422
|
+
case 4:
|
|
423
|
+
if (!(i < declaracao.caminhosSeSenao.length)) return [3 /*break*/, 8];
|
|
424
|
+
atual = declaracao.caminhosSeSenao[i];
|
|
425
|
+
_b = this.eVerdadeiro;
|
|
426
|
+
return [4 /*yield*/, this.avaliar(atual.condicao)];
|
|
427
|
+
case 5:
|
|
428
|
+
if (!_b.apply(this, [_c.sent()])) return [3 /*break*/, 7];
|
|
429
|
+
return [4 /*yield*/, this.executar(atual.caminho)];
|
|
430
|
+
case 6: return [2 /*return*/, _c.sent()];
|
|
431
|
+
case 7:
|
|
432
|
+
i++;
|
|
433
|
+
return [3 /*break*/, 4];
|
|
434
|
+
case 8:
|
|
435
|
+
if (!(declaracao.caminhoSenao !== null)) return [3 /*break*/, 10];
|
|
436
|
+
return [4 /*yield*/, this.executar(declaracao.caminhoSenao)];
|
|
437
|
+
case 9: return [2 /*return*/, _c.sent()];
|
|
438
|
+
case 10: return [2 /*return*/, null];
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
309
442
|
};
|
|
310
443
|
InterpretadorEguaClassico.prototype.visitarExpressaoPara = function (declaracao) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
444
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
445
|
+
var _a, erro_2;
|
|
446
|
+
return __generator(this, function (_b) {
|
|
447
|
+
switch (_b.label) {
|
|
448
|
+
case 0:
|
|
449
|
+
if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
|
|
450
|
+
return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
|
|
451
|
+
case 1:
|
|
452
|
+
_b.sent();
|
|
453
|
+
_b.label = 2;
|
|
454
|
+
case 2:
|
|
455
|
+
if (!true) return [3 /*break*/, 10];
|
|
456
|
+
if (!(declaracao.condicao !== null)) return [3 /*break*/, 4];
|
|
457
|
+
_a = this.eVerdadeiro;
|
|
458
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicao)];
|
|
459
|
+
case 3:
|
|
460
|
+
if (!_a.apply(this, [_b.sent()])) {
|
|
461
|
+
return [3 /*break*/, 10];
|
|
462
|
+
}
|
|
463
|
+
_b.label = 4;
|
|
464
|
+
case 4:
|
|
465
|
+
_b.trys.push([4, 6, , 7]);
|
|
466
|
+
return [4 /*yield*/, this.executar(declaracao.corpo)];
|
|
467
|
+
case 5:
|
|
468
|
+
_b.sent();
|
|
469
|
+
return [3 /*break*/, 7];
|
|
470
|
+
case 6:
|
|
471
|
+
erro_2 = _b.sent();
|
|
472
|
+
throw erro_2;
|
|
473
|
+
case 7:
|
|
474
|
+
if (!(declaracao.incrementar !== null)) return [3 /*break*/, 9];
|
|
475
|
+
return [4 /*yield*/, this.avaliar(declaracao.incrementar)];
|
|
476
|
+
case 8:
|
|
477
|
+
_b.sent();
|
|
478
|
+
_b.label = 9;
|
|
479
|
+
case 9: return [3 /*break*/, 2];
|
|
480
|
+
case 10: return [2 /*return*/, null];
|
|
318
481
|
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
this.executar(declaracao.corpo);
|
|
322
|
-
}
|
|
323
|
-
catch (erro) {
|
|
324
|
-
throw erro;
|
|
325
|
-
}
|
|
326
|
-
if (declaracao.incrementar !== null) {
|
|
327
|
-
this.avaliar(declaracao.incrementar);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return null;
|
|
482
|
+
});
|
|
483
|
+
});
|
|
331
484
|
};
|
|
332
485
|
InterpretadorEguaClassico.prototype.visitarExpressaoFazer = function (declaracao) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
486
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
487
|
+
var erro_3, _a;
|
|
488
|
+
return __generator(this, function (_b) {
|
|
489
|
+
switch (_b.label) {
|
|
490
|
+
case 0:
|
|
491
|
+
_b.trys.push([0, 2, , 3]);
|
|
492
|
+
return [4 /*yield*/, this.executar(declaracao.caminhoFazer)];
|
|
493
|
+
case 1:
|
|
494
|
+
_b.sent();
|
|
495
|
+
return [3 /*break*/, 3];
|
|
496
|
+
case 2:
|
|
497
|
+
erro_3 = _b.sent();
|
|
498
|
+
throw erro_3;
|
|
499
|
+
case 3:
|
|
500
|
+
_a = this.eVerdadeiro;
|
|
501
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicaoEnquanto)];
|
|
502
|
+
case 4:
|
|
503
|
+
if (_a.apply(this, [_b.sent()])) return [3 /*break*/, 0];
|
|
504
|
+
_b.label = 5;
|
|
505
|
+
case 5: return [2 /*return*/];
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
});
|
|
341
509
|
};
|
|
342
510
|
InterpretadorEguaClassico.prototype.visitarExpressaoEscolha = function (declaracao) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
511
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
512
|
+
var condicaoEscolha, caminhos, caminhoPadrao, encontrado, i, caminho_1, j, k, erro_4, i, erro_5;
|
|
513
|
+
return __generator(this, function (_a) {
|
|
514
|
+
switch (_a.label) {
|
|
515
|
+
case 0: return [4 /*yield*/, this.avaliar(declaracao.identificadorOuLiteral)];
|
|
516
|
+
case 1:
|
|
517
|
+
condicaoEscolha = _a.sent();
|
|
518
|
+
caminhos = declaracao.caminhos;
|
|
519
|
+
caminhoPadrao = declaracao.caminhoPadrao;
|
|
520
|
+
encontrado = false;
|
|
521
|
+
_a.label = 2;
|
|
522
|
+
case 2:
|
|
523
|
+
_a.trys.push([2, 19, , 20]);
|
|
524
|
+
i = 0;
|
|
525
|
+
_a.label = 3;
|
|
526
|
+
case 3:
|
|
527
|
+
if (!(i < caminhos.length)) return [3 /*break*/, 14];
|
|
528
|
+
caminho_1 = caminhos[i];
|
|
529
|
+
j = 0;
|
|
530
|
+
_a.label = 4;
|
|
531
|
+
case 4:
|
|
532
|
+
if (!(j < caminho_1.condicoes.length)) return [3 /*break*/, 13];
|
|
533
|
+
return [4 /*yield*/, this.avaliar(caminho_1.condicoes[j])];
|
|
534
|
+
case 5:
|
|
535
|
+
if (!((_a.sent()) === condicaoEscolha)) return [3 /*break*/, 12];
|
|
352
536
|
encontrado = true;
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
537
|
+
_a.label = 6;
|
|
538
|
+
case 6:
|
|
539
|
+
_a.trys.push([6, 11, , 12]);
|
|
540
|
+
k = 0;
|
|
541
|
+
_a.label = 7;
|
|
542
|
+
case 7:
|
|
543
|
+
if (!(k < caminho_1.declaracoes.length)) return [3 /*break*/, 10];
|
|
544
|
+
return [4 /*yield*/, this.executar(caminho_1.declaracoes[k])];
|
|
545
|
+
case 8:
|
|
546
|
+
_a.sent();
|
|
547
|
+
_a.label = 9;
|
|
548
|
+
case 9:
|
|
549
|
+
k++;
|
|
550
|
+
return [3 /*break*/, 7];
|
|
551
|
+
case 10: return [3 /*break*/, 12];
|
|
552
|
+
case 11:
|
|
553
|
+
erro_4 = _a.sent();
|
|
554
|
+
throw erro_4;
|
|
555
|
+
case 12:
|
|
556
|
+
j++;
|
|
557
|
+
return [3 /*break*/, 4];
|
|
558
|
+
case 13:
|
|
559
|
+
i++;
|
|
560
|
+
return [3 /*break*/, 3];
|
|
561
|
+
case 14:
|
|
562
|
+
if (!(caminhoPadrao !== null && encontrado === false)) return [3 /*break*/, 18];
|
|
563
|
+
i = 0;
|
|
564
|
+
_a.label = 15;
|
|
565
|
+
case 15:
|
|
566
|
+
if (!(i < caminhoPadrao.declaracoes.length)) return [3 /*break*/, 18];
|
|
567
|
+
return [4 /*yield*/, this.executar(caminhoPadrao['declaracoes'][i])];
|
|
568
|
+
case 16:
|
|
569
|
+
_a.sent();
|
|
570
|
+
_a.label = 17;
|
|
571
|
+
case 17:
|
|
572
|
+
i++;
|
|
573
|
+
return [3 /*break*/, 15];
|
|
574
|
+
case 18: return [3 /*break*/, 20];
|
|
575
|
+
case 19:
|
|
576
|
+
erro_5 = _a.sent();
|
|
577
|
+
throw erro_5;
|
|
578
|
+
case 20: return [2 /*return*/];
|
|
362
579
|
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
for (var i = 0; i < caminhoPadrao.declaracoes.length; i++) {
|
|
366
|
-
this.executar(caminhoPadrao['declaracoes'][i]);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
catch (erro) {
|
|
371
|
-
throw erro;
|
|
372
|
-
}
|
|
580
|
+
});
|
|
581
|
+
});
|
|
373
582
|
};
|
|
374
583
|
InterpretadorEguaClassico.prototype.visitarExpressaoTente = function (declaracao) {
|
|
375
|
-
|
|
376
|
-
var sucesso
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
584
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
585
|
+
var sucesso, erro_6;
|
|
586
|
+
return __generator(this, function (_a) {
|
|
587
|
+
switch (_a.label) {
|
|
588
|
+
case 0:
|
|
589
|
+
_a.trys.push([0, , 10, 13]);
|
|
590
|
+
sucesso = true;
|
|
591
|
+
_a.label = 1;
|
|
592
|
+
case 1:
|
|
593
|
+
_a.trys.push([1, 3, , 7]);
|
|
594
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoTente)];
|
|
595
|
+
case 2:
|
|
596
|
+
_a.sent();
|
|
597
|
+
return [3 /*break*/, 7];
|
|
598
|
+
case 3:
|
|
599
|
+
erro_6 = _a.sent();
|
|
600
|
+
sucesso = false;
|
|
601
|
+
if (!(declaracao.caminhoPegue !== null)) return [3 /*break*/, 5];
|
|
602
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoPegue)];
|
|
603
|
+
case 4:
|
|
604
|
+
_a.sent();
|
|
605
|
+
return [3 /*break*/, 6];
|
|
606
|
+
case 5:
|
|
607
|
+
this.erros.push(erro_6);
|
|
608
|
+
_a.label = 6;
|
|
609
|
+
case 6: return [3 /*break*/, 7];
|
|
610
|
+
case 7:
|
|
611
|
+
if (!(sucesso && declaracao.caminhoSenao !== null)) return [3 /*break*/, 9];
|
|
612
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoSenao)];
|
|
613
|
+
case 8:
|
|
614
|
+
_a.sent();
|
|
615
|
+
_a.label = 9;
|
|
616
|
+
case 9: return [3 /*break*/, 13];
|
|
617
|
+
case 10:
|
|
618
|
+
if (!(declaracao.caminhoFinalmente !== null)) return [3 /*break*/, 12];
|
|
619
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoFinalmente)];
|
|
620
|
+
case 11:
|
|
621
|
+
_a.sent();
|
|
622
|
+
_a.label = 12;
|
|
623
|
+
case 12: return [7 /*endfinally*/];
|
|
624
|
+
case 13: return [2 /*return*/];
|
|
384
625
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
if (sucesso && declaracao.caminhoSenao !== null) {
|
|
390
|
-
this.executarBloco(declaracao.caminhoSenao);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
finally {
|
|
394
|
-
if (declaracao.caminhoFinalmente !== null)
|
|
395
|
-
this.executarBloco(declaracao.caminhoFinalmente);
|
|
396
|
-
}
|
|
626
|
+
});
|
|
627
|
+
});
|
|
397
628
|
};
|
|
398
629
|
InterpretadorEguaClassico.prototype.visitarExpressaoEnquanto = function (declaracao) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
630
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
631
|
+
var _a, erro_7;
|
|
632
|
+
return __generator(this, function (_b) {
|
|
633
|
+
switch (_b.label) {
|
|
634
|
+
case 0:
|
|
635
|
+
_a = this.eVerdadeiro;
|
|
636
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicao)];
|
|
637
|
+
case 1:
|
|
638
|
+
if (!_a.apply(this, [_b.sent()])) return [3 /*break*/, 6];
|
|
639
|
+
_b.label = 2;
|
|
640
|
+
case 2:
|
|
641
|
+
_b.trys.push([2, 4, , 5]);
|
|
642
|
+
return [4 /*yield*/, this.executar(declaracao.corpo)];
|
|
643
|
+
case 3:
|
|
644
|
+
_b.sent();
|
|
645
|
+
return [3 /*break*/, 5];
|
|
646
|
+
case 4:
|
|
647
|
+
erro_7 = _b.sent();
|
|
648
|
+
throw erro_7;
|
|
649
|
+
case 5: return [3 /*break*/, 0];
|
|
650
|
+
case 6: return [2 /*return*/, null];
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
});
|
|
408
654
|
};
|
|
409
655
|
InterpretadorEguaClassico.prototype.visitarExpressaoImportar = function (declaracao) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
656
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
657
|
+
var caminhoRelativo, caminhoTotal, dados, delegua, exportar, eDicionario, novoModulo, chaves, i;
|
|
658
|
+
return __generator(this, function (_a) {
|
|
659
|
+
switch (_a.label) {
|
|
660
|
+
case 0: return [4 /*yield*/, this.avaliar(declaracao.caminho)];
|
|
661
|
+
case 1:
|
|
662
|
+
caminhoRelativo = _a.sent();
|
|
663
|
+
caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
|
|
664
|
+
dados = (0, importar_biblioteca_1.default)(caminhoRelativo);
|
|
665
|
+
if (dados)
|
|
666
|
+
return [2 /*return*/, dados];
|
|
667
|
+
try {
|
|
668
|
+
if (!fs.existsSync(caminhoTotal)) {
|
|
669
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível encontrar arquivo importado.', declaracao.linha);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
catch (erro) {
|
|
673
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível ler o arquivo.', declaracao.linha);
|
|
674
|
+
}
|
|
675
|
+
dados = fs.readFileSync(caminhoTotal).toString();
|
|
676
|
+
delegua = new delegua_2.Delegua(this.Delegua.dialeto, false);
|
|
677
|
+
delegua.executar(dados);
|
|
678
|
+
exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
|
|
679
|
+
eDicionario = function (objeto) { return objeto.constructor === Object; };
|
|
680
|
+
if (eDicionario(exportar)) {
|
|
681
|
+
novoModulo = new modulo_1.DeleguaModulo();
|
|
682
|
+
chaves = Object.keys(exportar);
|
|
683
|
+
for (i = 0; i < chaves.length; i++) {
|
|
684
|
+
novoModulo[chaves[i]] = exportar[chaves[i]];
|
|
685
|
+
}
|
|
686
|
+
return [2 /*return*/, novoModulo];
|
|
687
|
+
}
|
|
688
|
+
return [2 /*return*/, exportar];
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
});
|
|
438
692
|
};
|
|
439
693
|
InterpretadorEguaClassico.prototype.visitarExpressaoEscreva = function (declaracao) {
|
|
440
|
-
|
|
441
|
-
var valor
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
694
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
695
|
+
var valor, erro_8;
|
|
696
|
+
return __generator(this, function (_a) {
|
|
697
|
+
switch (_a.label) {
|
|
698
|
+
case 0:
|
|
699
|
+
_a.trys.push([0, 2, , 3]);
|
|
700
|
+
return [4 /*yield*/, this.avaliar(declaracao.argumentos[0])];
|
|
701
|
+
case 1:
|
|
702
|
+
valor = _a.sent();
|
|
703
|
+
console.log(this.paraTexto(valor));
|
|
704
|
+
return [2 /*return*/, null];
|
|
705
|
+
case 2:
|
|
706
|
+
erro_8 = _a.sent();
|
|
707
|
+
this.erros.push(erro_8);
|
|
708
|
+
return [3 /*break*/, 3];
|
|
709
|
+
case 3: return [2 /*return*/];
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
});
|
|
448
713
|
};
|
|
449
714
|
/**
|
|
450
715
|
* Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
|
|
@@ -457,20 +722,37 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
457
722
|
* @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
|
|
458
723
|
*/
|
|
459
724
|
InterpretadorEguaClassico.prototype.executarBloco = function (declaracoes, ambiente) {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
725
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
726
|
+
var escopoExecucao, retornoUltimoEscopo;
|
|
727
|
+
return __generator(this, function (_a) {
|
|
728
|
+
switch (_a.label) {
|
|
729
|
+
case 0:
|
|
730
|
+
escopoExecucao = {
|
|
731
|
+
declaracoes: declaracoes,
|
|
732
|
+
declaracaoAtual: 0,
|
|
733
|
+
ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
|
|
734
|
+
};
|
|
735
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
736
|
+
return [4 /*yield*/, this.executarUltimoEscopo()];
|
|
737
|
+
case 1:
|
|
738
|
+
retornoUltimoEscopo = _a.sent();
|
|
739
|
+
if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
|
|
740
|
+
throw retornoUltimoEscopo;
|
|
741
|
+
}
|
|
742
|
+
return [2 /*return*/, retornoUltimoEscopo];
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
});
|
|
471
746
|
};
|
|
472
747
|
InterpretadorEguaClassico.prototype.visitarExpressaoBloco = function (declaracao) {
|
|
473
|
-
return this
|
|
748
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
749
|
+
return __generator(this, function (_a) {
|
|
750
|
+
switch (_a.label) {
|
|
751
|
+
case 0: return [4 /*yield*/, this.executarBloco(declaracao.declaracoes)];
|
|
752
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
});
|
|
474
756
|
};
|
|
475
757
|
/**
|
|
476
758
|
* Executa expressão de definição de variável.
|
|
@@ -478,14 +760,25 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
478
760
|
* @returns Sempre retorna nulo.
|
|
479
761
|
*/
|
|
480
762
|
InterpretadorEguaClassico.prototype.visitarExpressaoVar = function (declaracao) {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
763
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
764
|
+
var valorOuOutraVariavel;
|
|
765
|
+
return __generator(this, function (_a) {
|
|
766
|
+
switch (_a.label) {
|
|
767
|
+
case 0:
|
|
768
|
+
valorOuOutraVariavel = null;
|
|
769
|
+
if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
|
|
770
|
+
return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
|
|
771
|
+
case 1:
|
|
772
|
+
valorOuOutraVariavel = _a.sent();
|
|
773
|
+
_a.label = 2;
|
|
774
|
+
case 2:
|
|
775
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
|
|
776
|
+
? valorOuOutraVariavel.valor
|
|
777
|
+
: valorOuOutraVariavel);
|
|
778
|
+
return [2 /*return*/, null];
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
});
|
|
489
782
|
};
|
|
490
783
|
InterpretadorEguaClassico.prototype.visitarExpressaoContinua = function (declaracao) {
|
|
491
784
|
return new quebras_1.ContinuarQuebra();
|
|
@@ -494,164 +787,270 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
494
787
|
return new quebras_1.SustarQuebra();
|
|
495
788
|
};
|
|
496
789
|
InterpretadorEguaClassico.prototype.visitarExpressaoRetornar = function (declaracao) {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
790
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
791
|
+
var valor;
|
|
792
|
+
return __generator(this, function (_a) {
|
|
793
|
+
switch (_a.label) {
|
|
794
|
+
case 0:
|
|
795
|
+
valor = null;
|
|
796
|
+
if (!(declaracao.valor != null)) return [3 /*break*/, 2];
|
|
797
|
+
return [4 /*yield*/, this.avaliar(declaracao.valor)];
|
|
798
|
+
case 1:
|
|
799
|
+
valor = _a.sent();
|
|
800
|
+
_a.label = 2;
|
|
801
|
+
case 2: return [2 /*return*/, new quebras_1.RetornoQuebra(valor)];
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
});
|
|
501
805
|
};
|
|
502
806
|
InterpretadorEguaClassico.prototype.visitarExpressaoDeleguaFuncao = function (expressao) {
|
|
503
807
|
return new funcao_1.DeleguaFuncao(null, expressao);
|
|
504
808
|
};
|
|
505
809
|
InterpretadorEguaClassico.prototype.visitarExpressaoAtribuicaoSobrescrita = function (expressao) {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
810
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
811
|
+
var objeto, indice, valor;
|
|
812
|
+
return __generator(this, function (_a) {
|
|
813
|
+
switch (_a.label) {
|
|
814
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
|
|
815
|
+
case 1:
|
|
816
|
+
objeto = _a.sent();
|
|
817
|
+
return [4 /*yield*/, this.avaliar(expressao.indice)];
|
|
818
|
+
case 2:
|
|
819
|
+
indice = _a.sent();
|
|
820
|
+
return [4 /*yield*/, this.avaliar(expressao.valor)];
|
|
821
|
+
case 3:
|
|
822
|
+
valor = _a.sent();
|
|
823
|
+
if (Array.isArray(objeto)) {
|
|
824
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
825
|
+
while (indice < 0) {
|
|
826
|
+
indice += objeto.length;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
while (objeto.length < indice) {
|
|
830
|
+
objeto.push(null);
|
|
831
|
+
}
|
|
832
|
+
objeto[indice] = valor;
|
|
833
|
+
}
|
|
834
|
+
else if (objeto.constructor === Object ||
|
|
835
|
+
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
836
|
+
objeto instanceof funcao_1.DeleguaFuncao ||
|
|
837
|
+
objeto instanceof delegua_classe_1.DeleguaClasse ||
|
|
838
|
+
objeto instanceof modulo_1.DeleguaModulo) {
|
|
839
|
+
objeto[indice] = valor;
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
843
|
+
}
|
|
844
|
+
return [2 /*return*/];
|
|
513
845
|
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
objeto.push(null);
|
|
517
|
-
}
|
|
518
|
-
objeto[indice] = valor;
|
|
519
|
-
}
|
|
520
|
-
else if (objeto.constructor === Object ||
|
|
521
|
-
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
522
|
-
objeto instanceof funcao_1.DeleguaFuncao ||
|
|
523
|
-
objeto instanceof delegua_classe_1.DeleguaClasse ||
|
|
524
|
-
objeto instanceof modulo_1.DeleguaModulo) {
|
|
525
|
-
objeto[indice] = valor;
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
529
|
-
}
|
|
846
|
+
});
|
|
847
|
+
});
|
|
530
848
|
};
|
|
531
849
|
InterpretadorEguaClassico.prototype.visitarExpressaoAcessoIndiceVariavel = function (expressao) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
850
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
851
|
+
var variavelObjeto, objeto, indice, valorIndice;
|
|
852
|
+
return __generator(this, function (_a) {
|
|
853
|
+
switch (_a.label) {
|
|
854
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
|
|
855
|
+
case 1:
|
|
856
|
+
variavelObjeto = _a.sent();
|
|
857
|
+
objeto = variavelObjeto.hasOwnProperty('valor')
|
|
858
|
+
? variavelObjeto.valor
|
|
859
|
+
: variavelObjeto;
|
|
860
|
+
return [4 /*yield*/, this.avaliar(expressao.indice)];
|
|
861
|
+
case 2:
|
|
862
|
+
indice = _a.sent();
|
|
863
|
+
valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
|
|
864
|
+
if (Array.isArray(objeto)) {
|
|
865
|
+
if (!Number.isInteger(valorIndice)) {
|
|
866
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
867
|
+
}
|
|
868
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
869
|
+
while (indice < 0) {
|
|
870
|
+
indice += objeto.length;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (indice >= objeto.length) {
|
|
874
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
|
|
875
|
+
}
|
|
876
|
+
return [2 /*return*/, objeto[indice]];
|
|
877
|
+
}
|
|
878
|
+
else if (objeto.constructor === Object ||
|
|
879
|
+
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
880
|
+
objeto instanceof funcao_1.DeleguaFuncao ||
|
|
881
|
+
objeto instanceof delegua_classe_1.DeleguaClasse ||
|
|
882
|
+
objeto instanceof modulo_1.DeleguaModulo) {
|
|
883
|
+
return [2 /*return*/, objeto[indice] || null];
|
|
884
|
+
}
|
|
885
|
+
else if (typeof objeto === 'string') {
|
|
886
|
+
if (!Number.isInteger(indice)) {
|
|
887
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
888
|
+
}
|
|
889
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
890
|
+
while (indice < 0) {
|
|
891
|
+
indice += objeto.length;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (indice >= objeto.length) {
|
|
895
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
|
|
896
|
+
}
|
|
897
|
+
return [2 /*return*/, objeto.charAt(indice)];
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
901
|
+
}
|
|
902
|
+
return [2 /*return*/];
|
|
566
903
|
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
|
|
570
|
-
}
|
|
571
|
-
return objeto.charAt(indice);
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
575
|
-
}
|
|
904
|
+
});
|
|
905
|
+
});
|
|
576
906
|
};
|
|
577
907
|
InterpretadorEguaClassico.prototype.visitarExpressaoDefinir = function (expressao) {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
908
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
909
|
+
var objeto, valor;
|
|
910
|
+
return __generator(this, function (_a) {
|
|
911
|
+
switch (_a.label) {
|
|
912
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
|
|
913
|
+
case 1:
|
|
914
|
+
objeto = _a.sent();
|
|
915
|
+
if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) &&
|
|
916
|
+
objeto.constructor !== Object) {
|
|
917
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
|
|
918
|
+
}
|
|
919
|
+
return [4 /*yield*/, this.avaliar(expressao.valor)];
|
|
920
|
+
case 2:
|
|
921
|
+
valor = _a.sent();
|
|
922
|
+
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
923
|
+
objeto.set(expressao.nome, valor);
|
|
924
|
+
return [2 /*return*/, valor];
|
|
925
|
+
}
|
|
926
|
+
else if (objeto.constructor === Object) {
|
|
927
|
+
objeto[expressao.simbolo.lexema] = valor;
|
|
928
|
+
}
|
|
929
|
+
return [2 /*return*/];
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
});
|
|
591
933
|
};
|
|
592
934
|
InterpretadorEguaClassico.prototype.visitarExpressaoFuncao = function (declaracao) {
|
|
593
935
|
var funcao = new funcao_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
594
936
|
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
595
937
|
};
|
|
596
938
|
InterpretadorEguaClassico.prototype.visitarExpressaoClasse = function (declaracao) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
939
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
940
|
+
var superClasse, variavelSuperClasse, metodos, definirMetodos, i, metodoAtual, eInicializador, funcao, deleguaClasse;
|
|
941
|
+
return __generator(this, function (_a) {
|
|
942
|
+
switch (_a.label) {
|
|
943
|
+
case 0:
|
|
944
|
+
superClasse = null;
|
|
945
|
+
if (!(declaracao.superClasse !== null)) return [3 /*break*/, 2];
|
|
946
|
+
return [4 /*yield*/, this.avaliar(declaracao.superClasse)];
|
|
947
|
+
case 1:
|
|
948
|
+
variavelSuperClasse = _a.sent();
|
|
949
|
+
superClasse = variavelSuperClasse.valor;
|
|
950
|
+
if (!(superClasse instanceof delegua_classe_1.DeleguaClasse)) {
|
|
951
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
|
|
952
|
+
}
|
|
953
|
+
_a.label = 2;
|
|
954
|
+
case 2:
|
|
955
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
|
|
956
|
+
if (declaracao.superClasse !== null) {
|
|
957
|
+
this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
|
|
958
|
+
}
|
|
959
|
+
metodos = {};
|
|
960
|
+
definirMetodos = declaracao.metodos;
|
|
961
|
+
for (i = 0; i < declaracao.metodos.length; i++) {
|
|
962
|
+
metodoAtual = definirMetodos[i];
|
|
963
|
+
eInicializador = metodoAtual.simbolo.lexema === 'construtor';
|
|
964
|
+
funcao = new funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
|
|
965
|
+
metodos[metodoAtual.simbolo.lexema] = funcao;
|
|
966
|
+
}
|
|
967
|
+
deleguaClasse = new delegua_classe_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
|
|
968
|
+
// TODO: Recolocar isso se for necessário.
|
|
969
|
+
/* if (superClasse !== null) {
|
|
970
|
+
this.ambiente = this.ambiente.enclosing;
|
|
971
|
+
} */
|
|
972
|
+
this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
|
|
973
|
+
return [2 /*return*/, null];
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
});
|
|
624
977
|
};
|
|
625
978
|
InterpretadorEguaClassico.prototype.visitarExpressaoAcessoMetodo = function (expressao) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
979
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
980
|
+
var variavelObjeto, objeto;
|
|
981
|
+
return __generator(this, function (_a) {
|
|
982
|
+
switch (_a.label) {
|
|
983
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
|
|
984
|
+
case 1:
|
|
985
|
+
variavelObjeto = _a.sent();
|
|
986
|
+
objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
|
|
987
|
+
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
988
|
+
return [2 /*return*/, objeto.get(expressao.simbolo) || null];
|
|
989
|
+
}
|
|
990
|
+
else if (objeto.constructor === Object) {
|
|
991
|
+
return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
|
|
992
|
+
}
|
|
993
|
+
else if (objeto instanceof modulo_1.DeleguaModulo) {
|
|
994
|
+
return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
|
|
995
|
+
}
|
|
996
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
});
|
|
638
1000
|
};
|
|
639
1001
|
InterpretadorEguaClassico.prototype.visitarExpressaoIsto = function (expressao) {
|
|
640
1002
|
return this.procurarVariavel(expressao.palavraChave, expressao);
|
|
641
1003
|
};
|
|
642
1004
|
InterpretadorEguaClassico.prototype.visitarExpressaoDicionario = function (expressao) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
1005
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1006
|
+
var dicionario, i, _a, _b;
|
|
1007
|
+
return __generator(this, function (_c) {
|
|
1008
|
+
switch (_c.label) {
|
|
1009
|
+
case 0:
|
|
1010
|
+
dicionario = {};
|
|
1011
|
+
i = 0;
|
|
1012
|
+
_c.label = 1;
|
|
1013
|
+
case 1:
|
|
1014
|
+
if (!(i < expressao.chaves.length)) return [3 /*break*/, 5];
|
|
1015
|
+
_a = dicionario;
|
|
1016
|
+
return [4 /*yield*/, this.avaliar(expressao.chaves[i])];
|
|
1017
|
+
case 2:
|
|
1018
|
+
_b = _c.sent();
|
|
1019
|
+
return [4 /*yield*/, this.avaliar(expressao.valores[i])];
|
|
1020
|
+
case 3:
|
|
1021
|
+
_a[_b] = _c.sent();
|
|
1022
|
+
_c.label = 4;
|
|
1023
|
+
case 4:
|
|
1024
|
+
i++;
|
|
1025
|
+
return [3 /*break*/, 1];
|
|
1026
|
+
case 5: return [2 /*return*/, dicionario];
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
});
|
|
648
1030
|
};
|
|
649
1031
|
InterpretadorEguaClassico.prototype.visitarExpressaoVetor = function (expressao) {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
1032
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1033
|
+
var valores, i, _a, _b;
|
|
1034
|
+
return __generator(this, function (_c) {
|
|
1035
|
+
switch (_c.label) {
|
|
1036
|
+
case 0:
|
|
1037
|
+
valores = [];
|
|
1038
|
+
i = 0;
|
|
1039
|
+
_c.label = 1;
|
|
1040
|
+
case 1:
|
|
1041
|
+
if (!(i < expressao.valores.length)) return [3 /*break*/, 4];
|
|
1042
|
+
_b = (_a = valores).push;
|
|
1043
|
+
return [4 /*yield*/, this.avaliar(expressao.valores[i])];
|
|
1044
|
+
case 2:
|
|
1045
|
+
_b.apply(_a, [_c.sent()]);
|
|
1046
|
+
_c.label = 3;
|
|
1047
|
+
case 3:
|
|
1048
|
+
i++;
|
|
1049
|
+
return [3 /*break*/, 1];
|
|
1050
|
+
case 4: return [2 /*return*/, valores];
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
655
1054
|
};
|
|
656
1055
|
InterpretadorEguaClassico.prototype.visitarExpressaoSuper = function (expressao) {
|
|
657
1056
|
var distancia = this.locais.get(expressao);
|
|
@@ -687,7 +1086,14 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
687
1086
|
};
|
|
688
1087
|
InterpretadorEguaClassico.prototype.executar = function (declaracao, mostrarResultado) {
|
|
689
1088
|
if (mostrarResultado === void 0) { mostrarResultado = false; }
|
|
690
|
-
return
|
|
1089
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1090
|
+
return __generator(this, function (_a) {
|
|
1091
|
+
switch (_a.label) {
|
|
1092
|
+
case 0: return [4 /*yield*/, declaracao.aceitar(this)];
|
|
1093
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
});
|
|
691
1097
|
};
|
|
692
1098
|
/**
|
|
693
1099
|
* Executa o último escopo empilhado no topo na pilha de escopos do Interpretador.
|
|
@@ -703,36 +1109,66 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
703
1109
|
* @returns O resultado da execução do escopo, se houver.
|
|
704
1110
|
*/
|
|
705
1111
|
InterpretadorEguaClassico.prototype.executarUltimoEscopo = function () {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
1112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1113
|
+
var ultimoEscopo, retornoExecucao, erro_9;
|
|
1114
|
+
return __generator(this, function (_a) {
|
|
1115
|
+
switch (_a.label) {
|
|
1116
|
+
case 0:
|
|
1117
|
+
ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
|
|
1118
|
+
_a.label = 1;
|
|
1119
|
+
case 1:
|
|
1120
|
+
_a.trys.push([1, 6, 7, 8]);
|
|
1121
|
+
retornoExecucao = void 0;
|
|
1122
|
+
_a.label = 2;
|
|
1123
|
+
case 2:
|
|
1124
|
+
if (!(!(retornoExecucao instanceof quebras_1.Quebra) &&
|
|
1125
|
+
ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length)) return [3 /*break*/, 5];
|
|
1126
|
+
return [4 /*yield*/, this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual])];
|
|
1127
|
+
case 3:
|
|
1128
|
+
retornoExecucao = _a.sent();
|
|
1129
|
+
_a.label = 4;
|
|
1130
|
+
case 4:
|
|
1131
|
+
ultimoEscopo.declaracaoAtual++;
|
|
1132
|
+
return [3 /*break*/, 2];
|
|
1133
|
+
case 5: return [2 /*return*/, retornoExecucao];
|
|
1134
|
+
case 6:
|
|
1135
|
+
erro_9 = _a.sent();
|
|
1136
|
+
return [2 /*return*/, erro_9];
|
|
1137
|
+
case 7:
|
|
1138
|
+
this.pilhaEscoposExecucao.removerUltimo();
|
|
1139
|
+
return [7 /*endfinally*/];
|
|
1140
|
+
case 8: return [2 /*return*/];
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
});
|
|
721
1144
|
};
|
|
722
1145
|
InterpretadorEguaClassico.prototype.interpretar = function (declaracoes) {
|
|
723
|
-
this
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
1146
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1147
|
+
var retornoResolvedor, escopoExecucao;
|
|
1148
|
+
return __generator(this, function (_a) {
|
|
1149
|
+
switch (_a.label) {
|
|
1150
|
+
case 0:
|
|
1151
|
+
this.erros = [];
|
|
1152
|
+
retornoResolvedor = this.resolvedor.resolver(declaracoes);
|
|
1153
|
+
this.locais = retornoResolvedor.locais;
|
|
1154
|
+
escopoExecucao = {
|
|
1155
|
+
declaracoes: declaracoes,
|
|
1156
|
+
declaracaoAtual: 0,
|
|
1157
|
+
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
1158
|
+
};
|
|
1159
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
1160
|
+
return [4 /*yield*/, this.executarUltimoEscopo()];
|
|
1161
|
+
case 1:
|
|
1162
|
+
_a.sent();
|
|
1163
|
+
return [2 /*return*/, {
|
|
1164
|
+
erros: this.erros,
|
|
1165
|
+
}];
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
});
|
|
1169
|
+
};
|
|
1170
|
+
InterpretadorEguaClassico.prototype.finalizacao = function () {
|
|
1171
|
+
this.funcaoDeRetorno();
|
|
736
1172
|
};
|
|
737
1173
|
return InterpretadorEguaClassico;
|
|
738
1174
|
}());
|