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