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