@designliquido/delegua 0.8.1 → 0.9.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 +4 -3
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js +4 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico.d.ts +4 -3
- package/fontes/avaliador-sintatico/avaliador-sintatico.js +17 -3
- package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +4 -3
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +6 -3
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.d.ts +4 -3
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +15 -3
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.d.ts +2 -2
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js.map +1 -1
- package/fontes/avaliador-sintatico/retornos/retorno-declaracao.d.ts +2 -2
- package/fontes/avaliador-sintatico/retornos/retorno-primario.d.ts +2 -2
- package/fontes/bibliotecas/biblioteca-global.js +352 -178
- 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 +44 -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 +44 -1
- package/fontes/construtos/acesso-metodo.js.map +1 -1
- package/fontes/construtos/agrupamento.d.ts +1 -1
- package/fontes/construtos/agrupamento.js +44 -1
- package/fontes/construtos/agrupamento.js.map +1 -1
- package/fontes/construtos/atribuicao-sobrescrita.d.ts +2 -1
- package/fontes/construtos/atribuicao-sobrescrita.js +44 -1
- package/fontes/construtos/atribuicao-sobrescrita.js.map +1 -1
- package/fontes/construtos/atribuir.d.ts +1 -1
- package/fontes/construtos/atribuir.js +44 -1
- package/fontes/construtos/atribuir.js.map +1 -1
- package/fontes/construtos/binario.d.ts +1 -1
- package/fontes/construtos/binario.js +44 -1
- package/fontes/construtos/binario.js.map +1 -1
- package/fontes/construtos/chamada.d.ts +1 -1
- package/fontes/construtos/chamada.js +44 -1
- package/fontes/construtos/chamada.js.map +1 -1
- package/fontes/construtos/construto.d.ts +1 -1
- package/fontes/construtos/{conjunto.d.ts → definir-valor.d.ts} +3 -2
- package/fontes/construtos/definir-valor.js +61 -0
- package/fontes/construtos/definir-valor.js.map +1 -0
- package/fontes/construtos/dicionario.d.ts +2 -1
- package/fontes/construtos/dicionario.js +44 -1
- package/fontes/construtos/dicionario.js.map +1 -1
- package/fontes/construtos/funcao.d.ts +2 -2
- package/fontes/construtos/funcao.js +47 -7
- package/fontes/construtos/funcao.js.map +1 -1
- package/fontes/construtos/index.d.ts +1 -1
- package/fontes/construtos/index.js +1 -1
- package/fontes/construtos/index.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 +44 -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 +44 -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 +44 -1
- package/fontes/construtos/vetor.js.map +1 -1
- package/fontes/declaracoes/bloco.d.ts +1 -1
- package/fontes/declaracoes/bloco.js +44 -1
- package/fontes/declaracoes/bloco.js.map +1 -1
- package/fontes/declaracoes/classe.d.ts +2 -2
- package/fontes/declaracoes/classe.js +44 -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 +44 -1
- package/fontes/declaracoes/enquanto.js.map +1 -1
- package/fontes/declaracoes/escolha.d.ts +2 -1
- package/fontes/declaracoes/escolha.js +44 -1
- package/fontes/declaracoes/escolha.js.map +1 -1
- package/fontes/declaracoes/escreva.d.ts +1 -1
- package/fontes/declaracoes/escreva.js +44 -1
- package/fontes/declaracoes/escreva.js.map +1 -1
- package/fontes/declaracoes/expressao.d.ts +1 -1
- package/fontes/declaracoes/expressao.js +44 -1
- package/fontes/declaracoes/expressao.js.map +1 -1
- package/fontes/declaracoes/fazer.d.ts +2 -1
- package/fontes/declaracoes/fazer.js +44 -1
- package/fontes/declaracoes/fazer.js.map +1 -1
- package/fontes/declaracoes/funcao.d.ts +2 -2
- package/fontes/declaracoes/funcao.js +48 -8
- package/fontes/declaracoes/funcao.js.map +1 -1
- package/fontes/declaracoes/importar.d.ts +2 -1
- package/fontes/declaracoes/importar.js +44 -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 +44 -1
- package/fontes/declaracoes/para.js.map +1 -1
- package/fontes/declaracoes/retorna.d.ts +1 -1
- package/fontes/declaracoes/retorna.js +44 -1
- package/fontes/declaracoes/retorna.js.map +1 -1
- package/fontes/declaracoes/se.d.ts +1 -1
- package/fontes/declaracoes/se.js +44 -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 +44 -1
- package/fontes/declaracoes/tente.js.map +1 -1
- package/fontes/declaracoes/var.d.ts +1 -1
- package/fontes/declaracoes/var.js +44 -1
- package/fontes/declaracoes/var.js.map +1 -1
- package/fontes/delegua.d.ts +3 -3
- package/fontes/delegua.js +138 -63
- 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/delegua-classe.d.ts +1 -1
- package/fontes/estruturas/{funcao.d.ts → delegua-funcao.d.ts} +4 -4
- package/fontes/estruturas/delegua-funcao.js +126 -0
- package/fontes/estruturas/delegua-funcao.js.map +1 -0
- 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/index.d.ts +1 -1
- package/fontes/estruturas/index.js +1 -1
- package/fontes/estruturas/index.js.map +1 -1
- package/fontes/interfaces/avaliador-sintatico-interface.d.ts +7 -6
- 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 +10 -9
- package/fontes/interfaces/resolvedor-interface.d.ts +1 -1
- package/fontes/interpretador/dialetos/egua-classico.d.ts +35 -33
- package/fontes/interpretador/dialetos/egua-classico.js +911 -474
- 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 +41 -36
- package/fontes/interpretador/interpretador.js +1034 -536
- 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 +27 -4
- package/fontes/resolvedor/dialetos/egua-classico.js +42 -1
- 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 +380 -164
- 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 +877 -400
- package/testes/interpretador.test.js.map +1 -1
- package/fontes/construtos/conjunto.js +0 -18
- package/fontes/construtos/conjunto.js.map +0 -1
- package/fontes/estruturas/funcao.js +0 -80
- package/fontes/estruturas/funcao.js.map +0 -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
|
};
|
|
@@ -48,8 +84,11 @@ var primitivas_vetor_1 = __importDefault(require("../bibliotecas/primitivas-veto
|
|
|
48
84
|
var Interpretador = /** @class */ (function () {
|
|
49
85
|
function Interpretador(importador, diretorioBase, performance, funcaoDeRetorno) {
|
|
50
86
|
if (performance === void 0) { performance = false; }
|
|
87
|
+
if (funcaoDeRetorno === void 0) { funcaoDeRetorno = null; }
|
|
51
88
|
this.funcaoDeRetorno = null;
|
|
89
|
+
this.interfaceDeEntrada = null;
|
|
52
90
|
this.resultadoInterpretador = [];
|
|
91
|
+
this.interfaceEntradaSaida = null;
|
|
53
92
|
this.regexInterpolacao = /\$\{([a-z_][\w]*)\}/gi;
|
|
54
93
|
this.importador = importador;
|
|
55
94
|
this.diretorioBase = diretorioBase;
|
|
@@ -69,10 +108,22 @@ var Interpretador = /** @class */ (function () {
|
|
|
69
108
|
/**
|
|
70
109
|
* Execução da leitura de valores da entrada configurada no
|
|
71
110
|
* início da aplicação.
|
|
72
|
-
* @param expressao
|
|
111
|
+
* @param expressao Expressão do tipo Leia
|
|
112
|
+
* @returns Promise com o resultado da leitura.
|
|
73
113
|
*/
|
|
74
114
|
Interpretador.prototype.visitarExpressaoLeia = function (expressao) {
|
|
75
|
-
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var mensagem;
|
|
117
|
+
var _this = this;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
mensagem = expressao.argumentos && expressao.argumentos[0] ? expressao.argumentos[0].valor : '';
|
|
120
|
+
return [2 /*return*/, new Promise(function (resolucao) {
|
|
121
|
+
return _this.interfaceEntradaSaida.question(mensagem, function (resposta) {
|
|
122
|
+
resolucao(resposta);
|
|
123
|
+
});
|
|
124
|
+
})];
|
|
125
|
+
});
|
|
126
|
+
});
|
|
76
127
|
};
|
|
77
128
|
/**
|
|
78
129
|
* Retira a interpolação de um texto.
|
|
@@ -119,10 +170,24 @@ var Interpretador = /** @class */ (function () {
|
|
|
119
170
|
return expressao.valor;
|
|
120
171
|
};
|
|
121
172
|
Interpretador.prototype.avaliar = function (expressao) {
|
|
122
|
-
return
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
return __generator(this, function (_a) {
|
|
175
|
+
switch (_a.label) {
|
|
176
|
+
case 0: return [4 /*yield*/, expressao.aceitar(this)];
|
|
177
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
123
181
|
};
|
|
124
182
|
Interpretador.prototype.visitarExpressaoAgrupamento = function (expressao) {
|
|
125
|
-
return this
|
|
183
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
184
|
+
return __generator(this, function (_a) {
|
|
185
|
+
switch (_a.label) {
|
|
186
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.expressao)];
|
|
187
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
126
191
|
};
|
|
127
192
|
Interpretador.prototype.eVerdadeiro = function (objeto) {
|
|
128
193
|
if (objeto === null)
|
|
@@ -132,22 +197,34 @@ var Interpretador = /** @class */ (function () {
|
|
|
132
197
|
return true;
|
|
133
198
|
};
|
|
134
199
|
Interpretador.prototype.verificarOperandoNumero = function (operador, operando) {
|
|
135
|
-
if (typeof operando === 'number')
|
|
200
|
+
if (typeof operando === 'number' || operando.tipo === 'número')
|
|
136
201
|
return;
|
|
137
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operando precisa ser um número.', operador.linha);
|
|
202
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operando precisa ser um número.', Number(operador.linha));
|
|
138
203
|
};
|
|
139
204
|
Interpretador.prototype.visitarExpressaoUnaria = function (expressao) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
var direita, valor;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.direita)];
|
|
210
|
+
case 1:
|
|
211
|
+
direita = _a.sent();
|
|
212
|
+
valor = direita.hasOwnProperty('valor') ?
|
|
213
|
+
direita.valor :
|
|
214
|
+
direita;
|
|
215
|
+
switch (expressao.operador.tipo) {
|
|
216
|
+
case delegua_1.default.SUBTRACAO:
|
|
217
|
+
this.verificarOperandoNumero(expressao.operador, valor);
|
|
218
|
+
return [2 /*return*/, -valor];
|
|
219
|
+
case delegua_1.default.NEGACAO:
|
|
220
|
+
return [2 /*return*/, !this.eVerdadeiro(valor)];
|
|
221
|
+
case delegua_1.default.BIT_NOT:
|
|
222
|
+
return [2 /*return*/, ~valor];
|
|
223
|
+
}
|
|
224
|
+
return [2 /*return*/, null];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
151
228
|
};
|
|
152
229
|
Interpretador.prototype.eIgual = function (esquerda, direita) {
|
|
153
230
|
if (esquerda === null && direita === null)
|
|
@@ -189,80 +266,98 @@ var Interpretador = /** @class */ (function () {
|
|
|
189
266
|
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
|
|
190
267
|
};
|
|
191
268
|
Interpretador.prototype.visitarExpressaoBinaria = function (expressao) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
var esquerda, direita, valorEsquerdo, valorDireito, tipoEsquerdo, tipoDireito, erro_1;
|
|
271
|
+
return __generator(this, function (_a) {
|
|
272
|
+
switch (_a.label) {
|
|
273
|
+
case 0:
|
|
274
|
+
_a.trys.push([0, 3, , 4]);
|
|
275
|
+
return [4 /*yield*/, this.avaliar(expressao.esquerda)];
|
|
276
|
+
case 1:
|
|
277
|
+
esquerda = _a.sent();
|
|
278
|
+
return [4 /*yield*/, this.avaliar(expressao.direita)];
|
|
279
|
+
case 2:
|
|
280
|
+
direita = _a.sent();
|
|
281
|
+
valorEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('valor'))
|
|
282
|
+
? esquerda.valor
|
|
283
|
+
: esquerda;
|
|
284
|
+
valorDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('valor'))
|
|
285
|
+
? direita.valor
|
|
286
|
+
: direita;
|
|
287
|
+
tipoEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('tipo'))
|
|
288
|
+
? esquerda.tipo
|
|
289
|
+
: (0, inferenciador_1.inferirTipoVariavel)(esquerda);
|
|
290
|
+
tipoDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('tipo'))
|
|
291
|
+
? direita.tipo
|
|
292
|
+
: (0, inferenciador_1.inferirTipoVariavel)(direita);
|
|
293
|
+
switch (expressao.operador.tipo) {
|
|
294
|
+
case delegua_1.default.EXPONENCIACAO:
|
|
295
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
296
|
+
return [2 /*return*/, Math.pow(valorEsquerdo, valorDireito)];
|
|
297
|
+
case delegua_1.default.MAIOR:
|
|
298
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
299
|
+
return [2 /*return*/, Number(valorEsquerdo) > Number(valorDireito)];
|
|
300
|
+
case delegua_1.default.MAIOR_IGUAL:
|
|
301
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
302
|
+
return [2 /*return*/, Number(valorEsquerdo) >= Number(valorDireito)];
|
|
303
|
+
case delegua_1.default.MENOR:
|
|
304
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
305
|
+
return [2 /*return*/, Number(valorEsquerdo) < Number(valorDireito)];
|
|
306
|
+
case delegua_1.default.MENOR_IGUAL:
|
|
307
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
308
|
+
return [2 /*return*/, Number(valorEsquerdo) <= Number(valorDireito)];
|
|
309
|
+
case delegua_1.default.SUBTRACAO:
|
|
310
|
+
case delegua_1.default.MENOS_IGUAL:
|
|
311
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
312
|
+
return [2 /*return*/, Number(valorEsquerdo) - Number(valorDireito)];
|
|
313
|
+
case delegua_1.default.ADICAO:
|
|
314
|
+
case delegua_1.default.MAIS_IGUAL:
|
|
315
|
+
if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
|
|
316
|
+
return [2 /*return*/, Number(valorEsquerdo) + Number(valorDireito)];
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
return [2 /*return*/, String(valorEsquerdo) + String(valorDireito)];
|
|
320
|
+
}
|
|
321
|
+
case delegua_1.default.DIVISAO:
|
|
322
|
+
case delegua_1.default.DIVISAO_IGUAL:
|
|
323
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
324
|
+
return [2 /*return*/, Number(valorEsquerdo) / Number(valorDireito)];
|
|
325
|
+
case delegua_1.default.MULTIPLICACAO:
|
|
326
|
+
case delegua_1.default.MULTIPLICACAO_IGUAL:
|
|
327
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
328
|
+
return [2 /*return*/, Number(valorEsquerdo) * Number(valorDireito)];
|
|
329
|
+
case delegua_1.default.MODULO:
|
|
330
|
+
case delegua_1.default.MODULO_IGUAL:
|
|
331
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
332
|
+
return [2 /*return*/, Number(valorEsquerdo) % Number(valorDireito)];
|
|
333
|
+
case delegua_1.default.BIT_AND:
|
|
334
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
335
|
+
return [2 /*return*/, Number(valorEsquerdo) & Number(valorDireito)];
|
|
336
|
+
case delegua_1.default.BIT_XOR:
|
|
337
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
338
|
+
return [2 /*return*/, Number(valorEsquerdo) ^ Number(valorDireito)];
|
|
339
|
+
case delegua_1.default.BIT_OR:
|
|
340
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
341
|
+
return [2 /*return*/, Number(valorEsquerdo) | Number(valorDireito)];
|
|
342
|
+
case delegua_1.default.MENOR_MENOR:
|
|
343
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
344
|
+
return [2 /*return*/, Number(valorEsquerdo) << Number(valorDireito)];
|
|
345
|
+
case delegua_1.default.MAIOR_MAIOR:
|
|
346
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
347
|
+
return [2 /*return*/, Number(valorEsquerdo) >> Number(valorDireito)];
|
|
348
|
+
case delegua_1.default.DIFERENTE:
|
|
349
|
+
return [2 /*return*/, !this.eIgual(valorEsquerdo, valorDireito)];
|
|
350
|
+
case delegua_1.default.IGUAL_IGUAL:
|
|
351
|
+
return [2 /*return*/, this.eIgual(valorEsquerdo, valorDireito)];
|
|
352
|
+
}
|
|
353
|
+
return [3 /*break*/, 4];
|
|
354
|
+
case 3:
|
|
355
|
+
erro_1 = _a.sent();
|
|
356
|
+
return [2 /*return*/, Promise.reject(erro_1)];
|
|
357
|
+
case 4: return [2 /*return*/];
|
|
233
358
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
237
|
-
return Number(valorEsquerdo) / Number(valorDireito);
|
|
238
|
-
case delegua_1.default.MULTIPLICACAO:
|
|
239
|
-
case delegua_1.default.MULTIPLICACAO_IGUAL:
|
|
240
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
241
|
-
return Number(valorEsquerdo) * Number(valorDireito);
|
|
242
|
-
case delegua_1.default.MODULO:
|
|
243
|
-
case delegua_1.default.MODULO_IGUAL:
|
|
244
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
245
|
-
return Number(valorEsquerdo) % Number(valorDireito);
|
|
246
|
-
case delegua_1.default.BIT_AND:
|
|
247
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
248
|
-
return Number(valorEsquerdo) & Number(valorDireito);
|
|
249
|
-
case delegua_1.default.BIT_XOR:
|
|
250
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
251
|
-
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
252
|
-
case delegua_1.default.BIT_OR:
|
|
253
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
254
|
-
return Number(valorEsquerdo) | Number(valorDireito);
|
|
255
|
-
case delegua_1.default.MENOR_MENOR:
|
|
256
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
257
|
-
return Number(valorEsquerdo) << Number(valorDireito);
|
|
258
|
-
case delegua_1.default.MAIOR_MAIOR:
|
|
259
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
260
|
-
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
261
|
-
case delegua_1.default.DIFERENTE:
|
|
262
|
-
return !this.eIgual(valorEsquerdo, valorDireito);
|
|
263
|
-
case delegua_1.default.IGUAL_IGUAL:
|
|
264
|
-
return this.eIgual(valorEsquerdo, valorDireito);
|
|
265
|
-
}
|
|
359
|
+
});
|
|
360
|
+
});
|
|
266
361
|
};
|
|
267
362
|
/**
|
|
268
363
|
* Executa uma chamada de função, método ou classe.
|
|
@@ -270,65 +365,99 @@ var Interpretador = /** @class */ (function () {
|
|
|
270
365
|
* @returns O resultado da chamada.
|
|
271
366
|
*/
|
|
272
367
|
Interpretador.prototype.visitarExpressaoDeChamada = function (expressao) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
368
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
369
|
+
var variavelEntidadeChamada, entidadeChamada, argumentos, i, _a, _b, argumentosResolvidos, _i, _c, argumento, valorResolvido, parametros, diferenca, i, novosArgumentos, erro_2;
|
|
370
|
+
return __generator(this, function (_d) {
|
|
371
|
+
switch (_d.label) {
|
|
372
|
+
case 0:
|
|
373
|
+
_d.trys.push([0, 11, , 12]);
|
|
374
|
+
return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
|
|
375
|
+
case 1:
|
|
376
|
+
variavelEntidadeChamada = _d.sent();
|
|
377
|
+
entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
|
|
378
|
+
? variavelEntidadeChamada.valor
|
|
379
|
+
: variavelEntidadeChamada;
|
|
380
|
+
argumentos = [];
|
|
381
|
+
i = 0;
|
|
382
|
+
_d.label = 2;
|
|
383
|
+
case 2:
|
|
384
|
+
if (!(i < expressao.argumentos.length)) return [3 /*break*/, 5];
|
|
385
|
+
_b = (_a = argumentos).push;
|
|
386
|
+
return [4 /*yield*/, this.avaliar(expressao.argumentos[i])];
|
|
387
|
+
case 3:
|
|
388
|
+
_b.apply(_a, [_d.sent()]);
|
|
389
|
+
_d.label = 4;
|
|
390
|
+
case 4:
|
|
391
|
+
i++;
|
|
392
|
+
return [3 /*break*/, 2];
|
|
393
|
+
case 5:
|
|
394
|
+
if (!(entidadeChamada instanceof estruturas_1.Chamavel)) {
|
|
395
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha))];
|
|
396
|
+
}
|
|
397
|
+
if (!(entidadeChamada instanceof metodo_primitiva_1.MetodoPrimitiva)) return [3 /*break*/, 10];
|
|
398
|
+
argumentosResolvidos = [];
|
|
399
|
+
_i = 0, _c = expressao.argumentos;
|
|
400
|
+
_d.label = 6;
|
|
401
|
+
case 6:
|
|
402
|
+
if (!(_i < _c.length)) return [3 /*break*/, 9];
|
|
403
|
+
argumento = _c[_i];
|
|
404
|
+
return [4 /*yield*/, this.avaliar(argumento)];
|
|
405
|
+
case 7:
|
|
406
|
+
valorResolvido = _d.sent();
|
|
407
|
+
argumentosResolvidos.push(valorResolvido.hasOwnProperty('valor')
|
|
408
|
+
? valorResolvido.valor
|
|
409
|
+
: valorResolvido);
|
|
410
|
+
_d.label = 8;
|
|
411
|
+
case 8:
|
|
412
|
+
_i++;
|
|
413
|
+
return [3 /*break*/, 6];
|
|
414
|
+
case 9: return [2 /*return*/, entidadeChamada.chamar(argumentosResolvidos)];
|
|
415
|
+
case 10:
|
|
416
|
+
parametros = void 0;
|
|
417
|
+
if (entidadeChamada instanceof estruturas_1.DeleguaFuncao) {
|
|
418
|
+
parametros = entidadeChamada.declaracao.parametros;
|
|
419
|
+
}
|
|
420
|
+
else if (entidadeChamada instanceof estruturas_1.DeleguaClasse) {
|
|
421
|
+
parametros = entidadeChamada.metodos.inicializacao
|
|
422
|
+
? entidadeChamada.metodos.inicializacao.declaracao.parametros
|
|
423
|
+
: [];
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
parametros = [];
|
|
427
|
+
}
|
|
428
|
+
// Completar os parâmetros não preenchidos com nulos.
|
|
429
|
+
if (argumentos.length < entidadeChamada.aridade()) {
|
|
430
|
+
diferenca = entidadeChamada.aridade() - argumentos.length;
|
|
431
|
+
for (i = 0; i < diferenca; i++) {
|
|
432
|
+
argumentos.push(null);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
if (parametros &&
|
|
437
|
+
parametros.length > 0 &&
|
|
438
|
+
parametros[parametros.length - 1].tipo === 'estrela') {
|
|
439
|
+
novosArgumentos = argumentos.slice(0, parametros.length - 1);
|
|
440
|
+
novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
|
|
441
|
+
argumentos = novosArgumentos;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (entidadeChamada instanceof estruturas_1.FuncaoPadrao) {
|
|
445
|
+
try {
|
|
446
|
+
return [2 /*return*/, entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome)];
|
|
447
|
+
}
|
|
448
|
+
catch (erro) {
|
|
449
|
+
this.erros.push(erro);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return [2 /*return*/, entidadeChamada.chamar(this, argumentos)];
|
|
453
|
+
case 11:
|
|
454
|
+
erro_2 = _d.sent();
|
|
455
|
+
console.log(erro_2);
|
|
456
|
+
return [3 /*break*/, 12];
|
|
457
|
+
case 12: return [2 /*return*/];
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
});
|
|
332
461
|
};
|
|
333
462
|
/**
|
|
334
463
|
* Execução de uma expressão de atribuição.
|
|
@@ -336,9 +465,18 @@ var Interpretador = /** @class */ (function () {
|
|
|
336
465
|
* @returns O valor atribuído.
|
|
337
466
|
*/
|
|
338
467
|
Interpretador.prototype.visitarExpressaoDeAtribuicao = function (expressao) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
468
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
469
|
+
var valor;
|
|
470
|
+
return __generator(this, function (_a) {
|
|
471
|
+
switch (_a.label) {
|
|
472
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.valor)];
|
|
473
|
+
case 1:
|
|
474
|
+
valor = _a.sent();
|
|
475
|
+
this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
|
|
476
|
+
return [2 /*return*/, valor];
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
});
|
|
342
480
|
};
|
|
343
481
|
Interpretador.prototype.procurarVariavel = function (simbolo) {
|
|
344
482
|
return this.pilhaEscoposExecucao.obterVariavel(simbolo);
|
|
@@ -347,33 +485,53 @@ var Interpretador = /** @class */ (function () {
|
|
|
347
485
|
return this.procurarVariavel(expressao.simbolo);
|
|
348
486
|
};
|
|
349
487
|
Interpretador.prototype.visitarDeclaracaoDeExpressao = function (declaracao) {
|
|
350
|
-
return this
|
|
488
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
489
|
+
return __generator(this, function (_a) {
|
|
490
|
+
switch (_a.label) {
|
|
491
|
+
case 0: return [4 /*yield*/, this.avaliar(declaracao.expressao)];
|
|
492
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
});
|
|
351
496
|
};
|
|
352
497
|
Interpretador.prototype.visitarExpressaoLogica = function (expressao) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
498
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
499
|
+
var esquerda, direita;
|
|
500
|
+
return __generator(this, function (_a) {
|
|
501
|
+
switch (_a.label) {
|
|
502
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.esquerda)];
|
|
503
|
+
case 1:
|
|
504
|
+
esquerda = _a.sent();
|
|
505
|
+
if (!(expressao.operador.tipo === delegua_1.default.EM)) return [3 /*break*/, 3];
|
|
506
|
+
return [4 /*yield*/, this.avaliar(expressao.direita)];
|
|
507
|
+
case 2:
|
|
508
|
+
direita = _a.sent();
|
|
509
|
+
if (Array.isArray(direita) || typeof direita === 'string') {
|
|
510
|
+
return [2 /*return*/, direita.includes(esquerda)];
|
|
511
|
+
}
|
|
512
|
+
else if (direita.constructor === Object) {
|
|
513
|
+
return [2 /*return*/, esquerda in direita];
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
|
|
517
|
+
}
|
|
518
|
+
_a.label = 3;
|
|
519
|
+
case 3:
|
|
520
|
+
// se um estado for verdadeiro, retorna verdadeiro
|
|
521
|
+
if (expressao.operador.tipo === delegua_1.default.OU) {
|
|
522
|
+
if (this.eVerdadeiro(esquerda))
|
|
523
|
+
return [2 /*return*/, esquerda];
|
|
524
|
+
}
|
|
525
|
+
// se um estado for falso, retorna falso
|
|
526
|
+
if (expressao.operador.tipo === delegua_1.default.E) {
|
|
527
|
+
if (!this.eVerdadeiro(esquerda))
|
|
528
|
+
return [2 /*return*/, esquerda];
|
|
529
|
+
}
|
|
530
|
+
return [4 /*yield*/, this.avaliar(expressao.direita)];
|
|
531
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
});
|
|
377
535
|
};
|
|
378
536
|
/**
|
|
379
537
|
* Executa uma expressão Se, que tem uma condição, pode ter um bloco
|
|
@@ -382,146 +540,288 @@ var Interpretador = /** @class */ (function () {
|
|
|
382
540
|
* @returns O resultado da avaliação do bloco cuja condição é verdadeira.
|
|
383
541
|
*/
|
|
384
542
|
Interpretador.prototype.visitarExpressaoSe = function (declaracao) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
543
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
544
|
+
var _a, i, atual, _b;
|
|
545
|
+
return __generator(this, function (_c) {
|
|
546
|
+
switch (_c.label) {
|
|
547
|
+
case 0:
|
|
548
|
+
_a = this.eVerdadeiro;
|
|
549
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicao)];
|
|
550
|
+
case 1:
|
|
551
|
+
if (!_a.apply(this, [_c.sent()])) return [3 /*break*/, 3];
|
|
552
|
+
return [4 /*yield*/, this.executar(declaracao.caminhoEntao)];
|
|
553
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
554
|
+
case 3:
|
|
555
|
+
i = 0;
|
|
556
|
+
_c.label = 4;
|
|
557
|
+
case 4:
|
|
558
|
+
if (!(i < declaracao.caminhosSeSenao.length)) return [3 /*break*/, 8];
|
|
559
|
+
atual = declaracao.caminhosSeSenao[i];
|
|
560
|
+
_b = this.eVerdadeiro;
|
|
561
|
+
return [4 /*yield*/, this.avaliar(atual.condicao)];
|
|
562
|
+
case 5:
|
|
563
|
+
if (!_b.apply(this, [_c.sent()])) return [3 /*break*/, 7];
|
|
564
|
+
return [4 /*yield*/, this.executar(atual.caminho)];
|
|
565
|
+
case 6: return [2 /*return*/, _c.sent()];
|
|
566
|
+
case 7:
|
|
567
|
+
i++;
|
|
568
|
+
return [3 /*break*/, 4];
|
|
569
|
+
case 8:
|
|
570
|
+
if (!(declaracao.caminhoSenao !== null)) return [3 /*break*/, 10];
|
|
571
|
+
return [4 /*yield*/, this.executar(declaracao.caminhoSenao)];
|
|
572
|
+
case 9: return [2 /*return*/, _c.sent()];
|
|
573
|
+
case 10: return [2 /*return*/, null];
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
});
|
|
398
577
|
};
|
|
399
578
|
Interpretador.prototype.visitarExpressaoPara = function (declaracao) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
579
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
580
|
+
var retornoExecucao, _a, _b, erro_3;
|
|
581
|
+
return __generator(this, function (_c) {
|
|
582
|
+
switch (_c.label) {
|
|
583
|
+
case 0:
|
|
584
|
+
if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
|
|
585
|
+
return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
|
|
586
|
+
case 1:
|
|
587
|
+
_c.sent();
|
|
588
|
+
_c.label = 2;
|
|
589
|
+
case 2:
|
|
590
|
+
if (!!(retornoExecucao instanceof quebras_1.Quebra)) return [3 /*break*/, 11];
|
|
591
|
+
_a = declaracao.condicao !== null;
|
|
592
|
+
if (!_a) return [3 /*break*/, 4];
|
|
593
|
+
_b = this.eVerdadeiro;
|
|
594
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicao)];
|
|
595
|
+
case 3:
|
|
596
|
+
_a = !_b.apply(this, [_c.sent()]);
|
|
597
|
+
_c.label = 4;
|
|
598
|
+
case 4:
|
|
599
|
+
if (_a) {
|
|
600
|
+
return [3 /*break*/, 11];
|
|
601
|
+
}
|
|
602
|
+
_c.label = 5;
|
|
603
|
+
case 5:
|
|
604
|
+
_c.trys.push([5, 7, , 8]);
|
|
605
|
+
return [4 /*yield*/, this.executar(declaracao.corpo)];
|
|
606
|
+
case 6:
|
|
607
|
+
retornoExecucao = _c.sent();
|
|
608
|
+
return [3 /*break*/, 8];
|
|
609
|
+
case 7:
|
|
610
|
+
erro_3 = _c.sent();
|
|
611
|
+
return [2 /*return*/, Promise.reject(erro_3)];
|
|
612
|
+
case 8:
|
|
613
|
+
if (!(declaracao.incrementar !== null)) return [3 /*break*/, 10];
|
|
614
|
+
return [4 /*yield*/, this.avaliar(declaracao.incrementar)];
|
|
615
|
+
case 9:
|
|
616
|
+
_c.sent();
|
|
617
|
+
_c.label = 10;
|
|
618
|
+
case 10: return [3 /*break*/, 2];
|
|
619
|
+
case 11: return [2 /*return*/, null];
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
});
|
|
420
623
|
};
|
|
421
624
|
Interpretador.prototype.visitarExpressaoFazer = function (declaracao) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
625
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
626
|
+
var retornoExecucao, erro_4, _a, _b;
|
|
627
|
+
return __generator(this, function (_c) {
|
|
628
|
+
switch (_c.label) {
|
|
629
|
+
case 0:
|
|
630
|
+
_c.trys.push([0, 2, , 3]);
|
|
631
|
+
return [4 /*yield*/, this.executar(declaracao.caminhoFazer)];
|
|
632
|
+
case 1:
|
|
633
|
+
retornoExecucao = _c.sent();
|
|
634
|
+
return [3 /*break*/, 3];
|
|
635
|
+
case 2:
|
|
636
|
+
erro_4 = _c.sent();
|
|
637
|
+
return [2 /*return*/, Promise.reject(erro_4)];
|
|
638
|
+
case 3:
|
|
639
|
+
_a = !(retornoExecucao instanceof quebras_1.Quebra);
|
|
640
|
+
if (!_a) return [3 /*break*/, 5];
|
|
641
|
+
_b = this.eVerdadeiro;
|
|
642
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicaoEnquanto)];
|
|
643
|
+
case 4:
|
|
644
|
+
_a = _b.apply(this, [_c.sent()]);
|
|
645
|
+
_c.label = 5;
|
|
646
|
+
case 5:
|
|
647
|
+
if (_a) return [3 /*break*/, 0];
|
|
648
|
+
_c.label = 6;
|
|
649
|
+
case 6: return [2 /*return*/];
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
});
|
|
432
653
|
};
|
|
433
654
|
Interpretador.prototype.visitarExpressaoEscolha = function (declaracao) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
655
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
656
|
+
var condicaoEscolha, caminhos, caminhoPadrao, encontrado, i, caminho_1, j, erro_5, erro_6;
|
|
657
|
+
return __generator(this, function (_a) {
|
|
658
|
+
switch (_a.label) {
|
|
659
|
+
case 0: return [4 /*yield*/, this.avaliar(declaracao.identificadorOuLiteral)];
|
|
660
|
+
case 1:
|
|
661
|
+
condicaoEscolha = _a.sent();
|
|
662
|
+
caminhos = declaracao.caminhos;
|
|
663
|
+
caminhoPadrao = declaracao.caminhoPadrao;
|
|
664
|
+
encontrado = false;
|
|
665
|
+
_a.label = 2;
|
|
666
|
+
case 2:
|
|
667
|
+
_a.trys.push([2, 14, , 15]);
|
|
668
|
+
i = 0;
|
|
669
|
+
_a.label = 3;
|
|
670
|
+
case 3:
|
|
671
|
+
if (!(i < caminhos.length)) return [3 /*break*/, 11];
|
|
672
|
+
caminho_1 = caminhos[i];
|
|
673
|
+
j = 0;
|
|
674
|
+
_a.label = 4;
|
|
675
|
+
case 4:
|
|
676
|
+
if (!(j < caminho_1.condicoes.length)) return [3 /*break*/, 10];
|
|
677
|
+
return [4 /*yield*/, this.avaliar(caminho_1.condicoes[j])];
|
|
678
|
+
case 5:
|
|
679
|
+
if (!((_a.sent()) === condicaoEscolha)) return [3 /*break*/, 9];
|
|
443
680
|
encontrado = true;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
681
|
+
_a.label = 6;
|
|
682
|
+
case 6:
|
|
683
|
+
_a.trys.push([6, 8, , 9]);
|
|
684
|
+
return [4 /*yield*/, this.executarBloco(caminho_1.declaracoes)];
|
|
685
|
+
case 7:
|
|
686
|
+
_a.sent();
|
|
687
|
+
return [3 /*break*/, 9];
|
|
688
|
+
case 8:
|
|
689
|
+
erro_5 = _a.sent();
|
|
690
|
+
return [2 /*return*/, Promise.reject(erro_5)];
|
|
691
|
+
case 9:
|
|
692
|
+
j++;
|
|
693
|
+
return [3 /*break*/, 4];
|
|
694
|
+
case 10:
|
|
695
|
+
i++;
|
|
696
|
+
return [3 /*break*/, 3];
|
|
697
|
+
case 11:
|
|
698
|
+
if (!(caminhoPadrao !== null && encontrado === false)) return [3 /*break*/, 13];
|
|
699
|
+
return [4 /*yield*/, this.executarBloco(caminhoPadrao.declaracoes)];
|
|
700
|
+
case 12:
|
|
701
|
+
_a.sent();
|
|
702
|
+
_a.label = 13;
|
|
703
|
+
case 13: return [3 /*break*/, 15];
|
|
704
|
+
case 14:
|
|
705
|
+
erro_6 = _a.sent();
|
|
706
|
+
throw erro_6;
|
|
707
|
+
case 15: return [2 /*return*/];
|
|
451
708
|
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
this.executarBloco(caminhoPadrao.declaracoes);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
catch (erro) {
|
|
458
|
-
throw erro;
|
|
459
|
-
}
|
|
709
|
+
});
|
|
710
|
+
});
|
|
460
711
|
};
|
|
461
712
|
Interpretador.prototype.visitarExpressaoTente = function (declaracao) {
|
|
462
|
-
|
|
463
|
-
var sucesso
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
713
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
714
|
+
var sucesso, erro_7;
|
|
715
|
+
return __generator(this, function (_a) {
|
|
716
|
+
switch (_a.label) {
|
|
717
|
+
case 0:
|
|
718
|
+
_a.trys.push([0, , 10, 13]);
|
|
719
|
+
sucesso = true;
|
|
720
|
+
_a.label = 1;
|
|
721
|
+
case 1:
|
|
722
|
+
_a.trys.push([1, 3, , 7]);
|
|
723
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoTente)];
|
|
724
|
+
case 2:
|
|
725
|
+
_a.sent();
|
|
726
|
+
return [3 /*break*/, 7];
|
|
727
|
+
case 3:
|
|
728
|
+
erro_7 = _a.sent();
|
|
729
|
+
sucesso = false;
|
|
730
|
+
if (!(declaracao.caminhoPegue !== null)) return [3 /*break*/, 5];
|
|
731
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoPegue)];
|
|
732
|
+
case 4:
|
|
733
|
+
_a.sent();
|
|
734
|
+
return [3 /*break*/, 6];
|
|
735
|
+
case 5:
|
|
736
|
+
this.erros.push(erro_7);
|
|
737
|
+
_a.label = 6;
|
|
738
|
+
case 6: return [3 /*break*/, 7];
|
|
739
|
+
case 7:
|
|
740
|
+
if (!(sucesso && declaracao.caminhoSenao !== null)) return [3 /*break*/, 9];
|
|
741
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoSenao)];
|
|
742
|
+
case 8:
|
|
743
|
+
_a.sent();
|
|
744
|
+
_a.label = 9;
|
|
745
|
+
case 9: return [3 /*break*/, 13];
|
|
746
|
+
case 10:
|
|
747
|
+
if (!(declaracao.caminhoFinalmente !== null)) return [3 /*break*/, 12];
|
|
748
|
+
return [4 /*yield*/, this.executarBloco(declaracao.caminhoFinalmente)];
|
|
749
|
+
case 11:
|
|
750
|
+
_a.sent();
|
|
751
|
+
_a.label = 12;
|
|
752
|
+
case 12: return [7 /*endfinally*/];
|
|
753
|
+
case 13: return [2 /*return*/];
|
|
474
754
|
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
this.executarBloco(declaracao.caminhoSenao);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
finally {
|
|
481
|
-
if (declaracao.caminhoFinalmente !== null)
|
|
482
|
-
this.executarBloco(declaracao.caminhoFinalmente);
|
|
483
|
-
}
|
|
755
|
+
});
|
|
756
|
+
});
|
|
484
757
|
};
|
|
485
758
|
Interpretador.prototype.visitarExpressaoEnquanto = function (declaracao) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
759
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
760
|
+
var retornoExecucao, _a, _b, erro_8;
|
|
761
|
+
return __generator(this, function (_c) {
|
|
762
|
+
switch (_c.label) {
|
|
763
|
+
case 0:
|
|
764
|
+
_a = !(retornoExecucao instanceof quebras_1.Quebra);
|
|
765
|
+
if (!_a) return [3 /*break*/, 2];
|
|
766
|
+
_b = this.eVerdadeiro;
|
|
767
|
+
return [4 /*yield*/, this.avaliar(declaracao.condicao)];
|
|
768
|
+
case 1:
|
|
769
|
+
_a = _b.apply(this, [_c.sent()]);
|
|
770
|
+
_c.label = 2;
|
|
771
|
+
case 2:
|
|
772
|
+
if (!_a) return [3 /*break*/, 7];
|
|
773
|
+
_c.label = 3;
|
|
774
|
+
case 3:
|
|
775
|
+
_c.trys.push([3, 5, , 6]);
|
|
776
|
+
return [4 /*yield*/, this.executar(declaracao.corpo)];
|
|
777
|
+
case 4:
|
|
778
|
+
retornoExecucao = _c.sent();
|
|
779
|
+
return [3 /*break*/, 6];
|
|
780
|
+
case 5:
|
|
781
|
+
erro_8 = _c.sent();
|
|
782
|
+
throw erro_8;
|
|
783
|
+
case 6: return [3 /*break*/, 0];
|
|
784
|
+
case 7: return [2 /*return*/, null];
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
});
|
|
497
788
|
};
|
|
498
789
|
Interpretador.prototype.visitarExpressaoImportar = function (declaracao) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
790
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
791
|
+
var caminhoRelativo, caminhoTotal, nomeArquivo, conteudoImportacao, retornoInterpretador, funcoesChamaveis, eDicionario, novoModulo, chaves, i;
|
|
792
|
+
return __generator(this, function (_a) {
|
|
793
|
+
switch (_a.label) {
|
|
794
|
+
case 0: return [4 /*yield*/, this.avaliar(declaracao.caminho)];
|
|
795
|
+
case 1:
|
|
796
|
+
caminhoRelativo = _a.sent();
|
|
797
|
+
caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
|
|
798
|
+
nomeArquivo = caminho.basename(caminhoTotal);
|
|
799
|
+
if (!caminhoTotal.endsWith('.egua') &&
|
|
800
|
+
!caminhoTotal.endsWith('.delegua')) {
|
|
801
|
+
try {
|
|
802
|
+
return [2 /*return*/, (0, importar_biblioteca_1.default)(caminhoRelativo)];
|
|
803
|
+
}
|
|
804
|
+
catch (erro) {
|
|
805
|
+
this.erros.push(erro);
|
|
806
|
+
return [2 /*return*/, null];
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
conteudoImportacao = this.importador.importar(caminhoRelativo);
|
|
810
|
+
retornoInterpretador = this.interpretar(conteudoImportacao.retornoAvaliadorSintatico.declaracoes, true);
|
|
811
|
+
funcoesChamaveis = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
|
|
812
|
+
eDicionario = function (objeto) { return objeto.constructor === Object; };
|
|
813
|
+
if (eDicionario(funcoesChamaveis)) {
|
|
814
|
+
novoModulo = new estruturas_1.DeleguaModulo();
|
|
815
|
+
chaves = Object.keys(funcoesChamaveis);
|
|
816
|
+
for (i = 0; i < chaves.length; i++) {
|
|
817
|
+
novoModulo.componentes[chaves[i]] = funcoesChamaveis[chaves[i]];
|
|
818
|
+
}
|
|
819
|
+
return [2 /*return*/, novoModulo];
|
|
820
|
+
}
|
|
821
|
+
return [2 /*return*/, funcoesChamaveis];
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
});
|
|
525
825
|
};
|
|
526
826
|
/**
|
|
527
827
|
* Execução de uma escrita na saída configurada, que pode ser `console` (padrão) ou
|
|
@@ -530,24 +830,42 @@ var Interpretador = /** @class */ (function () {
|
|
|
530
830
|
* @returns Sempre nulo, por convenção de visita.
|
|
531
831
|
*/
|
|
532
832
|
Interpretador.prototype.visitarExpressaoEscreva = function (declaracao) {
|
|
533
|
-
|
|
534
|
-
var valor
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
833
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
834
|
+
var valor, _i, _a, argumento, resultadoAvaliacao, formatoTexto, erro_9;
|
|
835
|
+
return __generator(this, function (_b) {
|
|
836
|
+
switch (_b.label) {
|
|
837
|
+
case 0:
|
|
838
|
+
_b.trys.push([0, 5, , 6]);
|
|
839
|
+
valor = void 0;
|
|
840
|
+
_i = 0, _a = declaracao.argumentos;
|
|
841
|
+
_b.label = 1;
|
|
842
|
+
case 1:
|
|
843
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
844
|
+
argumento = _a[_i];
|
|
845
|
+
return [4 /*yield*/, this.avaliar(argumento)];
|
|
846
|
+
case 2:
|
|
847
|
+
resultadoAvaliacao = _b.sent();
|
|
848
|
+
valor = (resultadoAvaliacao === null || resultadoAvaliacao === void 0 ? void 0 : resultadoAvaliacao.hasOwnProperty('valor'))
|
|
849
|
+
? resultadoAvaliacao.valor
|
|
850
|
+
: resultadoAvaliacao;
|
|
851
|
+
_b.label = 3;
|
|
852
|
+
case 3:
|
|
853
|
+
_i++;
|
|
854
|
+
return [3 /*break*/, 1];
|
|
855
|
+
case 4:
|
|
856
|
+
formatoTexto = this.paraTexto(valor);
|
|
857
|
+
// Por enquanto `escreva` não devolve resultado no interpretador.
|
|
858
|
+
// this.resultadoInterpretador.push(formatoTexto);
|
|
859
|
+
this.funcaoDeRetorno(formatoTexto);
|
|
860
|
+
return [2 /*return*/, null];
|
|
861
|
+
case 5:
|
|
862
|
+
erro_9 = _b.sent();
|
|
863
|
+
this.erros.push(erro_9);
|
|
864
|
+
return [3 /*break*/, 6];
|
|
865
|
+
case 6: return [2 /*return*/];
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
});
|
|
551
869
|
};
|
|
552
870
|
/**
|
|
553
871
|
* Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
|
|
@@ -559,20 +877,37 @@ var Interpretador = /** @class */ (function () {
|
|
|
559
877
|
* @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
|
|
560
878
|
*/
|
|
561
879
|
Interpretador.prototype.executarBloco = function (declaracoes, ambiente) {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
880
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
881
|
+
var escopoExecucao, retornoUltimoEscopo;
|
|
882
|
+
return __generator(this, function (_a) {
|
|
883
|
+
switch (_a.label) {
|
|
884
|
+
case 0:
|
|
885
|
+
escopoExecucao = {
|
|
886
|
+
declaracoes: declaracoes,
|
|
887
|
+
declaracaoAtual: 0,
|
|
888
|
+
ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
|
|
889
|
+
};
|
|
890
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
891
|
+
return [4 /*yield*/, this.executarUltimoEscopo()];
|
|
892
|
+
case 1:
|
|
893
|
+
retornoUltimoEscopo = _a.sent();
|
|
894
|
+
if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
|
|
895
|
+
return [2 /*return*/, Promise.reject(retornoUltimoEscopo)];
|
|
896
|
+
}
|
|
897
|
+
return [2 /*return*/, retornoUltimoEscopo];
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
});
|
|
573
901
|
};
|
|
574
902
|
Interpretador.prototype.visitarExpressaoBloco = function (declaracao) {
|
|
575
|
-
return this
|
|
903
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
904
|
+
return __generator(this, function (_a) {
|
|
905
|
+
switch (_a.label) {
|
|
906
|
+
case 0: return [4 /*yield*/, this.executarBloco(declaracao.declaracoes)];
|
|
907
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
});
|
|
576
911
|
};
|
|
577
912
|
/**
|
|
578
913
|
* Executa expressão de definição de variável.
|
|
@@ -580,14 +915,25 @@ var Interpretador = /** @class */ (function () {
|
|
|
580
915
|
* @returns Sempre retorna nulo.
|
|
581
916
|
*/
|
|
582
917
|
Interpretador.prototype.visitarExpressaoVar = function (declaracao) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
918
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
919
|
+
var valorOuOutraVariavel;
|
|
920
|
+
return __generator(this, function (_a) {
|
|
921
|
+
switch (_a.label) {
|
|
922
|
+
case 0:
|
|
923
|
+
valorOuOutraVariavel = null;
|
|
924
|
+
if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
|
|
925
|
+
return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
|
|
926
|
+
case 1:
|
|
927
|
+
valorOuOutraVariavel = _a.sent();
|
|
928
|
+
_a.label = 2;
|
|
929
|
+
case 2:
|
|
930
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
|
|
931
|
+
? valorOuOutraVariavel.valor
|
|
932
|
+
: valorOuOutraVariavel);
|
|
933
|
+
return [2 /*return*/, null];
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
});
|
|
591
937
|
};
|
|
592
938
|
Interpretador.prototype.visitarExpressaoContinua = function (declaracao) {
|
|
593
939
|
return new quebras_1.ContinuarQuebra();
|
|
@@ -596,100 +942,150 @@ var Interpretador = /** @class */ (function () {
|
|
|
596
942
|
return new quebras_1.SustarQuebra();
|
|
597
943
|
};
|
|
598
944
|
Interpretador.prototype.visitarExpressaoRetornar = function (declaracao) {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
945
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
946
|
+
var valor;
|
|
947
|
+
return __generator(this, function (_a) {
|
|
948
|
+
switch (_a.label) {
|
|
949
|
+
case 0:
|
|
950
|
+
valor = null;
|
|
951
|
+
if (!(declaracao.valor != null)) return [3 /*break*/, 2];
|
|
952
|
+
return [4 /*yield*/, this.avaliar(declaracao.valor)];
|
|
953
|
+
case 1:
|
|
954
|
+
valor = _a.sent();
|
|
955
|
+
_a.label = 2;
|
|
956
|
+
case 2: return [2 /*return*/, new quebras_1.RetornoQuebra(valor)];
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
});
|
|
603
960
|
};
|
|
604
961
|
Interpretador.prototype.visitarExpressaoDeleguaFuncao = function (expressao) {
|
|
605
962
|
return new estruturas_1.DeleguaFuncao(null, expressao);
|
|
606
963
|
};
|
|
607
964
|
Interpretador.prototype.visitarExpressaoAtribuicaoSobrescrita = function (expressao) {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
965
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
966
|
+
var promises, objeto, indice, valor;
|
|
967
|
+
return __generator(this, function (_a) {
|
|
968
|
+
switch (_a.label) {
|
|
969
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
970
|
+
this.avaliar(expressao.objeto),
|
|
971
|
+
this.avaliar(expressao.indice),
|
|
972
|
+
this.avaliar(expressao.valor)
|
|
973
|
+
])];
|
|
974
|
+
case 1:
|
|
975
|
+
promises = _a.sent();
|
|
976
|
+
objeto = promises[0];
|
|
977
|
+
indice = promises[1];
|
|
978
|
+
valor = promises[2];
|
|
979
|
+
if (Array.isArray(objeto)) {
|
|
980
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
981
|
+
while (indice < 0) {
|
|
982
|
+
indice += objeto.length;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
while (objeto.length < indice) {
|
|
986
|
+
objeto.push(null);
|
|
987
|
+
}
|
|
988
|
+
objeto[indice] = valor;
|
|
989
|
+
}
|
|
990
|
+
else if (objeto.constructor === Object ||
|
|
991
|
+
objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
992
|
+
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
993
|
+
objeto instanceof estruturas_1.DeleguaClasse ||
|
|
994
|
+
objeto instanceof estruturas_1.DeleguaModulo) {
|
|
995
|
+
objeto[indice] = valor;
|
|
996
|
+
}
|
|
997
|
+
else {
|
|
998
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha))];
|
|
999
|
+
}
|
|
1000
|
+
return [2 /*return*/];
|
|
615
1001
|
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
objeto.push(null);
|
|
619
|
-
}
|
|
620
|
-
objeto[indice] = valor;
|
|
621
|
-
}
|
|
622
|
-
else if (objeto.constructor === Object ||
|
|
623
|
-
objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
624
|
-
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
625
|
-
objeto instanceof estruturas_1.DeleguaClasse ||
|
|
626
|
-
objeto instanceof estruturas_1.DeleguaModulo) {
|
|
627
|
-
objeto[indice] = valor;
|
|
628
|
-
}
|
|
629
|
-
else {
|
|
630
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
631
|
-
}
|
|
1002
|
+
});
|
|
1003
|
+
});
|
|
632
1004
|
};
|
|
633
1005
|
Interpretador.prototype.visitarExpressaoAcessoIndiceVariavel = function (expressao) {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
1006
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1007
|
+
var variavelObjeto, objeto, indice, valorIndice;
|
|
1008
|
+
return __generator(this, function (_a) {
|
|
1009
|
+
switch (_a.label) {
|
|
1010
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
|
|
1011
|
+
case 1:
|
|
1012
|
+
variavelObjeto = _a.sent();
|
|
1013
|
+
objeto = variavelObjeto.hasOwnProperty('valor')
|
|
1014
|
+
? variavelObjeto.valor
|
|
1015
|
+
: variavelObjeto;
|
|
1016
|
+
return [4 /*yield*/, this.avaliar(expressao.indice)];
|
|
1017
|
+
case 2:
|
|
1018
|
+
indice = _a.sent();
|
|
1019
|
+
valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
|
|
1020
|
+
if (Array.isArray(objeto)) {
|
|
1021
|
+
if (!Number.isInteger(valorIndice)) {
|
|
1022
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha))];
|
|
1023
|
+
}
|
|
1024
|
+
if (valorIndice < 0 && objeto.length !== 0) {
|
|
1025
|
+
while (valorIndice < 0) {
|
|
1026
|
+
valorIndice += objeto.length;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if (valorIndice >= objeto.length) {
|
|
1030
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
|
|
1031
|
+
}
|
|
1032
|
+
return [2 /*return*/, objeto[valorIndice]];
|
|
1033
|
+
}
|
|
1034
|
+
else if (objeto.constructor === Object ||
|
|
1035
|
+
objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
1036
|
+
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
1037
|
+
objeto instanceof estruturas_1.DeleguaClasse ||
|
|
1038
|
+
objeto instanceof estruturas_1.DeleguaModulo) {
|
|
1039
|
+
return [2 /*return*/, objeto[valorIndice] || null];
|
|
1040
|
+
}
|
|
1041
|
+
else if (typeof objeto === 'string') {
|
|
1042
|
+
if (!Number.isInteger(valorIndice)) {
|
|
1043
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha))];
|
|
1044
|
+
}
|
|
1045
|
+
if (valorIndice < 0 && objeto.length !== 0) {
|
|
1046
|
+
while (valorIndice < 0) {
|
|
1047
|
+
valorIndice += objeto.length;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if (valorIndice >= objeto.length) {
|
|
1051
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha))];
|
|
1052
|
+
}
|
|
1053
|
+
return [2 /*return*/, objeto.charAt(valorIndice)];
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha))];
|
|
1057
|
+
}
|
|
1058
|
+
return [2 /*return*/];
|
|
668
1059
|
}
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
|
|
672
|
-
}
|
|
673
|
-
return objeto.charAt(valorIndice);
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
677
|
-
}
|
|
1060
|
+
});
|
|
1061
|
+
});
|
|
678
1062
|
};
|
|
679
|
-
Interpretador.prototype.
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
1063
|
+
Interpretador.prototype.visitarExpressaoDefinirValor = function (expressao) {
|
|
1064
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1065
|
+
var objeto, valor;
|
|
1066
|
+
return __generator(this, function (_a) {
|
|
1067
|
+
switch (_a.label) {
|
|
1068
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
|
|
1069
|
+
case 1:
|
|
1070
|
+
objeto = _a.sent();
|
|
1071
|
+
if (!(objeto instanceof estruturas_1.ObjetoDeleguaClasse) &&
|
|
1072
|
+
objeto.constructor !== Object) {
|
|
1073
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha))];
|
|
1074
|
+
}
|
|
1075
|
+
return [4 /*yield*/, this.avaliar(expressao.valor)];
|
|
1076
|
+
case 2:
|
|
1077
|
+
valor = _a.sent();
|
|
1078
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
|
|
1079
|
+
objeto.set(expressao.nome, valor);
|
|
1080
|
+
return [2 /*return*/, valor];
|
|
1081
|
+
}
|
|
1082
|
+
else if (objeto.constructor === Object) {
|
|
1083
|
+
objeto[expressao.simbolo.lexema] = valor;
|
|
1084
|
+
}
|
|
1085
|
+
return [2 /*return*/];
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
});
|
|
693
1089
|
};
|
|
694
1090
|
Interpretador.prototype.visitarExpressaoFuncao = function (declaracao) {
|
|
695
1091
|
var funcao = new estruturas_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
@@ -701,33 +1097,44 @@ var Interpretador = /** @class */ (function () {
|
|
|
701
1097
|
* @returns Sempre retorna nulo, por ser requerido pelo contrato de visita.
|
|
702
1098
|
*/
|
|
703
1099
|
Interpretador.prototype.visitarExpressaoClasse = function (declaracao) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
1100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1101
|
+
var superClasse, variavelSuperClasse, metodos, definirMetodos, i, metodoAtual, eInicializador, funcao, deleguaClasse;
|
|
1102
|
+
return __generator(this, function (_a) {
|
|
1103
|
+
switch (_a.label) {
|
|
1104
|
+
case 0:
|
|
1105
|
+
superClasse = null;
|
|
1106
|
+
if (!(declaracao.superClasse !== null)) return [3 /*break*/, 2];
|
|
1107
|
+
return [4 /*yield*/, this.avaliar(declaracao.superClasse)];
|
|
1108
|
+
case 1:
|
|
1109
|
+
variavelSuperClasse = _a.sent();
|
|
1110
|
+
superClasse = variavelSuperClasse.valor;
|
|
1111
|
+
if (!(superClasse instanceof estruturas_1.DeleguaClasse)) {
|
|
1112
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
|
|
1113
|
+
}
|
|
1114
|
+
_a.label = 2;
|
|
1115
|
+
case 2:
|
|
1116
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
|
|
1117
|
+
if (declaracao.superClasse !== null) {
|
|
1118
|
+
this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
|
|
1119
|
+
}
|
|
1120
|
+
metodos = {};
|
|
1121
|
+
definirMetodos = declaracao.metodos;
|
|
1122
|
+
for (i = 0; i < declaracao.metodos.length; i++) {
|
|
1123
|
+
metodoAtual = definirMetodos[i];
|
|
1124
|
+
eInicializador = metodoAtual.simbolo.lexema === 'construtor';
|
|
1125
|
+
funcao = new estruturas_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
|
|
1126
|
+
metodos[metodoAtual.simbolo.lexema] = funcao;
|
|
1127
|
+
}
|
|
1128
|
+
deleguaClasse = new estruturas_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
|
|
1129
|
+
// TODO: Recolocar isso se for necessário.
|
|
1130
|
+
/* if (superClasse !== null) {
|
|
1131
|
+
this.ambiente = this.ambiente.enclosing;
|
|
1132
|
+
} */
|
|
1133
|
+
this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
|
|
1134
|
+
return [2 /*return*/, null];
|
|
1135
|
+
}
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
731
1138
|
};
|
|
732
1139
|
/**
|
|
733
1140
|
* Executa um acesso a método, normalmente de um objeto de classe.
|
|
@@ -735,49 +1142,95 @@ var Interpretador = /** @class */ (function () {
|
|
|
735
1142
|
* @returns O resultado da execução.
|
|
736
1143
|
*/
|
|
737
1144
|
Interpretador.prototype.visitarExpressaoAcessoMetodo = function (expressao) {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
1145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1146
|
+
var variavelObjeto, objeto, metodoDePrimitivaTexto, metodoDePrimitivaVetor;
|
|
1147
|
+
return __generator(this, function (_a) {
|
|
1148
|
+
switch (_a.label) {
|
|
1149
|
+
case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
|
|
1150
|
+
case 1:
|
|
1151
|
+
variavelObjeto = _a.sent();
|
|
1152
|
+
objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
|
|
1153
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
|
|
1154
|
+
return [2 /*return*/, objeto.get(expressao.simbolo) || null];
|
|
1155
|
+
}
|
|
1156
|
+
if (objeto.constructor === Object) {
|
|
1157
|
+
return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
|
|
1158
|
+
}
|
|
1159
|
+
if (objeto instanceof estruturas_1.DeleguaModulo) {
|
|
1160
|
+
return [2 /*return*/, objeto.componentes[expressao.simbolo.lexema] || null];
|
|
1161
|
+
}
|
|
1162
|
+
switch (variavelObjeto.tipo) {
|
|
1163
|
+
case 'texto':
|
|
1164
|
+
metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema];
|
|
1165
|
+
if (metodoDePrimitivaTexto) {
|
|
1166
|
+
return [2 /*return*/, new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaTexto)];
|
|
1167
|
+
}
|
|
1168
|
+
break;
|
|
1169
|
+
case 'vetor':
|
|
1170
|
+
metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.simbolo.lexema];
|
|
1171
|
+
if (metodoDePrimitivaVetor) {
|
|
1172
|
+
return [2 /*return*/, new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaVetor)];
|
|
1173
|
+
}
|
|
1174
|
+
break;
|
|
1175
|
+
}
|
|
1176
|
+
return [2 /*return*/, Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha))];
|
|
760
1177
|
}
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
|
|
1178
|
+
});
|
|
1179
|
+
});
|
|
764
1180
|
};
|
|
765
1181
|
Interpretador.prototype.visitarExpressaoIsto = function (expressao) {
|
|
766
1182
|
return this.procurarVariavel(expressao.palavraChave);
|
|
767
1183
|
};
|
|
768
1184
|
Interpretador.prototype.visitarExpressaoDicionario = function (expressao) {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1186
|
+
var dicionario, i, promises;
|
|
1187
|
+
return __generator(this, function (_a) {
|
|
1188
|
+
switch (_a.label) {
|
|
1189
|
+
case 0:
|
|
1190
|
+
dicionario = {};
|
|
1191
|
+
i = 0;
|
|
1192
|
+
_a.label = 1;
|
|
1193
|
+
case 1:
|
|
1194
|
+
if (!(i < expressao.chaves.length)) return [3 /*break*/, 4];
|
|
1195
|
+
return [4 /*yield*/, Promise.all([
|
|
1196
|
+
this.avaliar(expressao.chaves[i]),
|
|
1197
|
+
this.avaliar(expressao.valores[i])
|
|
1198
|
+
])];
|
|
1199
|
+
case 2:
|
|
1200
|
+
promises = _a.sent();
|
|
1201
|
+
dicionario[promises[0]] = promises[1];
|
|
1202
|
+
_a.label = 3;
|
|
1203
|
+
case 3:
|
|
1204
|
+
i++;
|
|
1205
|
+
return [3 /*break*/, 1];
|
|
1206
|
+
case 4: return [2 /*return*/, dicionario];
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
});
|
|
774
1210
|
};
|
|
775
1211
|
Interpretador.prototype.visitarExpressaoVetor = function (expressao) {
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
1212
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1213
|
+
var valores, i, _a, _b;
|
|
1214
|
+
return __generator(this, function (_c) {
|
|
1215
|
+
switch (_c.label) {
|
|
1216
|
+
case 0:
|
|
1217
|
+
valores = [];
|
|
1218
|
+
i = 0;
|
|
1219
|
+
_c.label = 1;
|
|
1220
|
+
case 1:
|
|
1221
|
+
if (!(i < expressao.valores.length)) return [3 /*break*/, 4];
|
|
1222
|
+
_b = (_a = valores).push;
|
|
1223
|
+
return [4 /*yield*/, this.avaliar(expressao.valores[i])];
|
|
1224
|
+
case 2:
|
|
1225
|
+
_b.apply(_a, [_c.sent()]);
|
|
1226
|
+
_c.label = 3;
|
|
1227
|
+
case 3:
|
|
1228
|
+
i++;
|
|
1229
|
+
return [3 /*break*/, 1];
|
|
1230
|
+
case 4: return [2 /*return*/, valores];
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
});
|
|
781
1234
|
};
|
|
782
1235
|
// TODO: Após remoção do Resolvedor, simular casos que usem 'super' e 'isto'.
|
|
783
1236
|
Interpretador.prototype.visitarExpressaoSuper = function (expressao) {
|
|
@@ -818,14 +1271,23 @@ var Interpretador = /** @class */ (function () {
|
|
|
818
1271
|
*/
|
|
819
1272
|
Interpretador.prototype.executar = function (declaracao, mostrarResultado) {
|
|
820
1273
|
if (mostrarResultado === void 0) { mostrarResultado = false; }
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
1274
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1275
|
+
var resultado;
|
|
1276
|
+
return __generator(this, function (_a) {
|
|
1277
|
+
switch (_a.label) {
|
|
1278
|
+
case 0: return [4 /*yield*/, declaracao.aceitar(this)];
|
|
1279
|
+
case 1:
|
|
1280
|
+
resultado = _a.sent();
|
|
1281
|
+
if (mostrarResultado) {
|
|
1282
|
+
this.funcaoDeRetorno(this.paraTexto(resultado));
|
|
1283
|
+
}
|
|
1284
|
+
if (resultado || typeof resultado === 'boolean') {
|
|
1285
|
+
this.resultadoInterpretador.push(this.paraTexto(resultado));
|
|
1286
|
+
}
|
|
1287
|
+
return [2 /*return*/, resultado];
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
});
|
|
829
1291
|
};
|
|
830
1292
|
/**
|
|
831
1293
|
* Executa o último escopo empilhado no topo na pilha de escopos do interpretador.
|
|
@@ -839,25 +1301,42 @@ var Interpretador = /** @class */ (function () {
|
|
|
839
1301
|
*/
|
|
840
1302
|
Interpretador.prototype.executarUltimoEscopo = function (manterAmbiente) {
|
|
841
1303
|
if (manterAmbiente === void 0) { manterAmbiente = false; }
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
1304
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1305
|
+
var ultimoEscopo, retornoExecucao, erro_10, escopoAnterior;
|
|
1306
|
+
return __generator(this, function (_a) {
|
|
1307
|
+
switch (_a.label) {
|
|
1308
|
+
case 0:
|
|
1309
|
+
ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
|
|
1310
|
+
_a.label = 1;
|
|
1311
|
+
case 1:
|
|
1312
|
+
_a.trys.push([1, 6, 7, 8]);
|
|
1313
|
+
retornoExecucao = void 0;
|
|
1314
|
+
_a.label = 2;
|
|
1315
|
+
case 2:
|
|
1316
|
+
if (!(!(retornoExecucao instanceof quebras_1.Quebra) &&
|
|
1317
|
+
ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length)) return [3 /*break*/, 5];
|
|
1318
|
+
return [4 /*yield*/, this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual])];
|
|
1319
|
+
case 3:
|
|
1320
|
+
retornoExecucao = _a.sent();
|
|
1321
|
+
_a.label = 4;
|
|
1322
|
+
case 4:
|
|
1323
|
+
ultimoEscopo.declaracaoAtual++;
|
|
1324
|
+
return [3 /*break*/, 2];
|
|
1325
|
+
case 5: return [2 /*return*/, retornoExecucao];
|
|
1326
|
+
case 6:
|
|
1327
|
+
erro_10 = _a.sent();
|
|
1328
|
+
return [2 /*return*/, Promise.reject(erro_10)];
|
|
1329
|
+
case 7:
|
|
1330
|
+
this.pilhaEscoposExecucao.removerUltimo();
|
|
1331
|
+
if (manterAmbiente) {
|
|
1332
|
+
escopoAnterior = this.pilhaEscoposExecucao.topoDaPilha();
|
|
1333
|
+
escopoAnterior.ambiente.valores = Object.assign(escopoAnterior.ambiente.valores, ultimoEscopo.ambiente.valores);
|
|
1334
|
+
}
|
|
1335
|
+
return [7 /*endfinally*/];
|
|
1336
|
+
case 8: return [2 /*return*/];
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1339
|
+
});
|
|
861
1340
|
};
|
|
862
1341
|
/**
|
|
863
1342
|
* Interpretação sem depurador, com medição de performance.
|
|
@@ -869,29 +1348,48 @@ var Interpretador = /** @class */ (function () {
|
|
|
869
1348
|
*/
|
|
870
1349
|
Interpretador.prototype.interpretar = function (declaracoes, manterAmbiente) {
|
|
871
1350
|
if (manterAmbiente === void 0) { manterAmbiente = false; }
|
|
872
|
-
this
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1351
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1352
|
+
var escopoExecucao, inicioInterpretacao, retornoOuErro, erro_11, deltaInterpretacao, retorno;
|
|
1353
|
+
return __generator(this, function (_a) {
|
|
1354
|
+
switch (_a.label) {
|
|
1355
|
+
case 0:
|
|
1356
|
+
this.erros = [];
|
|
1357
|
+
escopoExecucao = {
|
|
1358
|
+
declaracoes: declaracoes,
|
|
1359
|
+
declaracaoAtual: 0,
|
|
1360
|
+
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
1361
|
+
};
|
|
1362
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
1363
|
+
inicioInterpretacao = (0, browser_process_hrtime_1.default)();
|
|
1364
|
+
_a.label = 1;
|
|
1365
|
+
case 1:
|
|
1366
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
1367
|
+
return [4 /*yield*/, this.executarUltimoEscopo(manterAmbiente)];
|
|
1368
|
+
case 2:
|
|
1369
|
+
retornoOuErro = _a.sent();
|
|
1370
|
+
if (retornoOuErro instanceof excecoes_1.ErroEmTempoDeExecucao) {
|
|
1371
|
+
this.erros.push(retornoOuErro);
|
|
1372
|
+
}
|
|
1373
|
+
return [3 /*break*/, 5];
|
|
1374
|
+
case 3:
|
|
1375
|
+
erro_11 = _a.sent();
|
|
1376
|
+
this.erros.push(erro_11);
|
|
1377
|
+
return [3 /*break*/, 5];
|
|
1378
|
+
case 4:
|
|
1379
|
+
if (this.performance) {
|
|
1380
|
+
deltaInterpretacao = (0, browser_process_hrtime_1.default)(inicioInterpretacao);
|
|
1381
|
+
console.log("[Interpretador] Tempo para interpreta\u00E7ao: ".concat(deltaInterpretacao[0] * 1e9 + deltaInterpretacao[1], "ns"));
|
|
1382
|
+
}
|
|
1383
|
+
retorno = {
|
|
1384
|
+
erros: this.erros,
|
|
1385
|
+
resultado: this.resultadoInterpretador,
|
|
1386
|
+
};
|
|
1387
|
+
this.resultadoInterpretador = [];
|
|
1388
|
+
return [2 /*return*/, retorno];
|
|
1389
|
+
case 5: return [2 /*return*/];
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
});
|
|
895
1393
|
};
|
|
896
1394
|
return Interpretador;
|
|
897
1395
|
}());
|