@designliquido/delegua 0.9.3 → 0.9.4
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/delegua +1 -1
- package/bin/delegua.cmd +1 -1
- package/bin/package.json +3 -3
- package/coverage/lcov-report/sorter.js +4 -4
- package/coverage/lcov-report/sorter.js.map +1 -1
- package/execucao.d.ts +1 -0
- package/execucao.js +29 -0
- package/execucao.js.map +1 -0
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js +108 -105
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico.js +226 -232
- package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js +35 -55
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +211 -216
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +231 -237
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.d.ts +3 -0
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js +188 -121
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js.map +1 -1
- package/fontes/avaliador-sintatico/erro-avaliador-sintatico.js +6 -24
- package/fontes/avaliador-sintatico/erro-avaliador-sintatico.js.map +1 -1
- package/fontes/bibliotecas/biblioteca-global.js +206 -367
- package/fontes/bibliotecas/biblioteca-global.js.map +1 -1
- package/fontes/bibliotecas/importar-biblioteca.js +28 -29
- package/fontes/bibliotecas/importar-biblioteca.js.map +1 -1
- package/fontes/bibliotecas/primitivas-texto.js +9 -22
- package/fontes/bibliotecas/primitivas-texto.js.map +1 -1
- package/fontes/bibliotecas/primitivas-vetor.js +12 -14
- package/fontes/bibliotecas/primitivas-vetor.js.map +1 -1
- package/fontes/construtos/acesso-indice-variavel.js +6 -50
- package/fontes/construtos/acesso-indice-variavel.js.map +1 -1
- package/fontes/construtos/acesso-metodo.js +6 -50
- package/fontes/construtos/acesso-metodo.js.map +1 -1
- package/fontes/construtos/agrupamento.js +6 -50
- package/fontes/construtos/agrupamento.js.map +1 -1
- package/fontes/construtos/atribuicao-sobrescrita.js +6 -50
- package/fontes/construtos/atribuicao-sobrescrita.js.map +1 -1
- package/fontes/construtos/atribuir.js +6 -50
- package/fontes/construtos/atribuir.js.map +1 -1
- package/fontes/construtos/binario.js +6 -50
- package/fontes/construtos/binario.js.map +1 -1
- package/fontes/construtos/chamada.js +6 -50
- package/fontes/construtos/chamada.js.map +1 -1
- package/fontes/construtos/definir-valor.js +6 -50
- package/fontes/construtos/definir-valor.js.map +1 -1
- package/fontes/construtos/dicionario.js +6 -50
- package/fontes/construtos/dicionario.js.map +1 -1
- package/fontes/construtos/funcao.d.ts +2 -2
- package/fontes/construtos/funcao.js +6 -47
- package/fontes/construtos/funcao.js.map +1 -1
- package/fontes/construtos/isto.js +6 -47
- package/fontes/construtos/isto.js.map +1 -1
- package/fontes/construtos/literal.js +6 -47
- package/fontes/construtos/literal.js.map +1 -1
- package/fontes/construtos/logico.js +6 -50
- package/fontes/construtos/logico.js.map +1 -1
- package/fontes/construtos/super.js +6 -47
- package/fontes/construtos/super.js.map +1 -1
- package/fontes/construtos/unario.js +6 -50
- package/fontes/construtos/unario.js.map +1 -1
- package/fontes/construtos/variavel.js +6 -47
- package/fontes/construtos/variavel.js.map +1 -1
- package/fontes/construtos/vetor.js +6 -50
- package/fontes/construtos/vetor.js.map +1 -1
- package/fontes/declaracoes/bloco.js +9 -70
- package/fontes/declaracoes/bloco.js.map +1 -1
- package/fontes/declaracoes/classe.js +11 -72
- package/fontes/declaracoes/classe.js.map +1 -1
- package/fontes/declaracoes/continua.js +8 -65
- package/fontes/declaracoes/continua.js.map +1 -1
- package/fontes/declaracoes/declaracao.js +6 -47
- package/fontes/declaracoes/declaracao.js.map +1 -1
- package/fontes/declaracoes/enquanto.js +10 -71
- package/fontes/declaracoes/enquanto.js.map +1 -1
- package/fontes/declaracoes/escolha.js +11 -72
- package/fontes/declaracoes/escolha.js.map +1 -1
- package/fontes/declaracoes/escreva.js +9 -70
- package/fontes/declaracoes/escreva.js.map +1 -1
- package/fontes/declaracoes/expressao.js +9 -70
- package/fontes/declaracoes/expressao.js.map +1 -1
- package/fontes/declaracoes/fazer.js +10 -71
- package/fontes/declaracoes/fazer.js.map +1 -1
- package/fontes/declaracoes/funcao.js +10 -68
- package/fontes/declaracoes/funcao.js.map +1 -1
- package/fontes/declaracoes/importar.js +10 -71
- package/fontes/declaracoes/importar.js.map +1 -1
- package/fontes/declaracoes/leia.js +9 -70
- package/fontes/declaracoes/leia.js.map +1 -1
- package/fontes/declaracoes/para.js +12 -73
- package/fontes/declaracoes/para.js.map +1 -1
- package/fontes/declaracoes/retorna.js +10 -71
- package/fontes/declaracoes/retorna.js.map +1 -1
- package/fontes/declaracoes/se.js +12 -73
- package/fontes/declaracoes/se.js.map +1 -1
- package/fontes/declaracoes/sustar.js +8 -65
- package/fontes/declaracoes/sustar.js.map +1 -1
- package/fontes/declaracoes/tente.js +12 -73
- package/fontes/declaracoes/tente.js.map +1 -1
- package/fontes/declaracoes/var.js +10 -71
- package/fontes/declaracoes/var.js.map +1 -1
- package/fontes/delegua.js +116 -199
- package/fontes/delegua.js.map +1 -1
- package/fontes/depuracao/cyrb53.js +3 -4
- package/fontes/depuracao/cyrb53.js.map +1 -1
- package/fontes/depuracao/servidor-depuracao.js +125 -209
- package/fontes/depuracao/servidor-depuracao.js.map +1 -1
- package/fontes/espaco-variaveis.js +3 -4
- package/fontes/espaco-variaveis.js.map +1 -1
- package/fontes/estruturas/chamavel.js +6 -9
- package/fontes/estruturas/chamavel.js.map +1 -1
- package/fontes/estruturas/classe-padrao.js +17 -35
- package/fontes/estruturas/classe-padrao.js.map +1 -1
- package/fontes/estruturas/delegua-classe.d.ts +2 -2
- package/fontes/estruturas/delegua-classe.js +21 -39
- package/fontes/estruturas/delegua-classe.js.map +1 -1
- package/fontes/estruturas/delegua-funcao.js +48 -114
- package/fontes/estruturas/delegua-funcao.js.map +1 -1
- package/fontes/estruturas/funcao-padrao.js +13 -75
- package/fontes/estruturas/funcao-padrao.js.map +1 -1
- package/fontes/estruturas/metodo-primitiva.js +11 -39
- package/fontes/estruturas/metodo-primitiva.js.map +1 -1
- package/fontes/estruturas/modulo.js +6 -7
- package/fontes/estruturas/modulo.js.map +1 -1
- package/fontes/estruturas/objeto-delegua-classe.d.ts +3 -3
- package/fontes/estruturas/objeto-delegua-classe.js +12 -13
- package/fontes/estruturas/objeto-delegua-classe.js.map +1 -1
- package/fontes/estruturas/objeto-padrao.js +9 -11
- package/fontes/estruturas/objeto-padrao.js.map +1 -1
- package/fontes/excecoes/erro-em-tempo-de-execucao.js +8 -26
- package/fontes/excecoes/erro-em-tempo-de-execucao.js.map +1 -1
- package/fontes/importador/importador.js +21 -22
- package/fontes/importador/importador.js.map +1 -1
- package/fontes/interfaces/parametro-interface.d.ts +1 -1
- package/fontes/interpretador/dialetos/egua-classico.js +592 -1019
- package/fontes/interpretador/dialetos/egua-classico.js.map +1 -1
- package/fontes/interpretador/inferenciador.js +1 -1
- package/fontes/interpretador/inferenciador.js.map +1 -1
- package/fontes/interpretador/interpretador-com-depuracao.js +186 -336
- package/fontes/interpretador/interpretador-com-depuracao.js.map +1 -1
- package/fontes/interpretador/interpretador.js +706 -1175
- package/fontes/interpretador/interpretador.js.map +1 -1
- package/fontes/interpretador/pilha-escopos-execucao.js +52 -57
- package/fontes/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/fontes/lexador/dialetos/lexador-birl.d.ts +1 -0
- package/fontes/lexador/dialetos/lexador-birl.js +55 -64
- package/fontes/lexador/dialetos/lexador-birl.js.map +1 -1
- package/fontes/lexador/dialetos/lexador-egua-classico.js +43 -46
- package/fontes/lexador/dialetos/lexador-egua-classico.js.map +1 -1
- package/fontes/lexador/dialetos/lexador-eguap.js +59 -63
- package/fontes/lexador/dialetos/lexador-eguap.js.map +1 -1
- package/fontes/lexador/dialetos/lexador-visualg.js +45 -54
- package/fontes/lexador/dialetos/lexador-visualg.js.map +1 -1
- package/fontes/lexador/dialetos/palavras-reservadas/birl.js +1 -1
- package/fontes/lexador/dialetos/palavras-reservadas/birl.js.map +1 -1
- package/fontes/lexador/dialetos/palavras-reservadas/egua-classico.js +1 -1
- package/fontes/lexador/dialetos/palavras-reservadas/egua-classico.js.map +1 -1
- package/fontes/lexador/dialetos/palavras-reservadas/visualg.d.ts +24 -0
- package/fontes/lexador/dialetos/palavras-reservadas/visualg.js +25 -1
- package/fontes/lexador/dialetos/palavras-reservadas/visualg.js.map +1 -1
- package/fontes/lexador/lexador-base-linha-unica.js +28 -29
- package/fontes/lexador/lexador-base-linha-unica.js.map +1 -1
- package/fontes/lexador/lexador.js +53 -57
- package/fontes/lexador/lexador.js.map +1 -1
- package/fontes/lexador/palavras-reservadas.js +1 -1
- package/fontes/lexador/palavras-reservadas.js.map +1 -1
- package/fontes/lexador/simbolo.js +5 -6
- package/fontes/lexador/simbolo.js.map +1 -1
- package/fontes/quebras/index.js +11 -42
- package/fontes/quebras/index.js.map +1 -1
- package/fontes/resolvedor/dialetos/egua-classico.js +143 -144
- package/fontes/resolvedor/dialetos/egua-classico.js.map +1 -1
- package/fontes/resolvedor/erro-resolvedor.js +6 -24
- package/fontes/resolvedor/erro-resolvedor.js.map +1 -1
- package/fontes/resolvedor/pilha-escopos.js +11 -12
- package/fontes/resolvedor/pilha-escopos.js.map +1 -1
- package/fontes/tipos-de-simbolos/birl.d.ts +1 -0
- package/fontes/tipos-de-simbolos/birl.js +1 -0
- package/fontes/tipos-de-simbolos/birl.js.map +1 -1
- package/fontes/tipos-de-simbolos/comum.d.ts +2 -0
- package/fontes/tipos-de-simbolos/comum.js +2 -0
- package/fontes/tipos-de-simbolos/comum.js.map +1 -1
- package/fontes/tipos-de-simbolos/visualg.d.ts +9 -0
- package/fontes/tipos-de-simbolos/visualg.js +9 -0
- package/fontes/tipos-de-simbolos/visualg.js.map +1 -1
- package/index.d.ts +4 -0
- package/index.js +4 -26
- package/index.js.map +1 -1
- package/jest.config.js +9 -47
- package/jest.config.js.map +1 -1
- package/package.json +3 -3
- package/testes/__mocks__/estatistica.js +1 -1
- package/testes/__mocks__/estatistica.js.map +1 -1
- package/testes/__mocks__/fisica.js +1 -1
- package/testes/__mocks__/fisica.js.map +1 -1
- package/testes/__mocks__/matematica.js +1 -1
- package/testes/__mocks__/matematica.js.map +1 -1
- package/testes/avaliador-sintatico.test.js +27 -27
- package/testes/avaliador-sintatico.test.js.map +1 -1
- package/testes/biblioteca-global.test.js +197 -440
- package/testes/biblioteca-global.test.js.map +1 -1
- package/testes/birl/avaliador-sintatico.test.js +8 -8
- package/testes/birl/avaliador-sintatico.test.js.map +1 -1
- package/testes/birl/lexador.test.js +10 -10
- package/testes/birl/lexador.test.js.map +1 -1
- package/testes/delegua.test.js +7 -7
- package/testes/delegua.test.js.map +1 -1
- package/testes/egua-classico/avaliador-sintatico.test.js +14 -14
- package/testes/egua-classico/avaliador-sintatico.test.js.map +1 -1
- package/testes/egua-classico/delegua.test.js +5 -5
- package/testes/egua-classico/delegua.test.js.map +1 -1
- package/testes/egua-classico/interpretador.test.js +180 -396
- package/testes/egua-classico/interpretador.test.js.map +1 -1
- package/testes/egua-classico/lexador.test.js +23 -23
- package/testes/egua-classico/lexador.test.js.map +1 -1
- package/testes/egua-classico/resolvedor.test.js +12 -12
- package/testes/egua-classico/resolvedor.test.js.map +1 -1
- package/testes/eguap/avaliador-sintatico.test.js +11 -11
- package/testes/eguap/avaliador-sintatico.test.js.map +1 -1
- package/testes/eguap/interpretador.test.js +189 -405
- package/testes/eguap/interpretador.test.js.map +1 -1
- package/testes/eguap/lexador.test.js +18 -18
- package/testes/eguap/lexador.test.js.map +1 -1
- package/testes/interpretador.test.js +431 -908
- package/testes/interpretador.test.js.map +1 -1
- package/testes/lexador.test.js +42 -42
- package/testes/lexador.test.js.map +1 -1
- package/testes/visualg/avaliador-sintatico.test.js +23 -23
- package/testes/visualg/avaliador-sintatico.test.js.map +1 -1
- package/testes/visualg/interpretador.test.js +16 -61
- package/testes/visualg/interpretador.test.js.map +1 -1
- package/testes/visualg/lexador.test.js +15 -15
- package/testes/visualg/lexador.test.js.map +1 -1
|
@@ -22,70 +22,34 @@ 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
|
-
};
|
|
61
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
27
|
};
|
|
64
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
29
|
exports.InterpretadorEguaClassico = void 0;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
30
|
+
const caminho = __importStar(require("path"));
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const espaco_variaveis_1 = require("../../espaco-variaveis");
|
|
33
|
+
const delegua_1 = require("../../delegua");
|
|
34
|
+
const biblioteca_global_1 = __importDefault(require("../../bibliotecas/biblioteca-global"));
|
|
35
|
+
const importar_biblioteca_1 = __importDefault(require("../../bibliotecas/importar-biblioteca"));
|
|
36
|
+
const chamavel_1 = require("../../estruturas/chamavel");
|
|
37
|
+
const funcao_padrao_1 = require("../../estruturas/funcao-padrao");
|
|
38
|
+
const delegua_classe_1 = require("../../estruturas/delegua-classe");
|
|
39
|
+
const delegua_funcao_1 = require("../../estruturas/delegua-funcao");
|
|
40
|
+
const objeto_delegua_classe_1 = require("../../estruturas/objeto-delegua-classe");
|
|
41
|
+
const modulo_1 = require("../../estruturas/modulo");
|
|
42
|
+
const excecoes_1 = require("../../excecoes");
|
|
43
|
+
const pilha_escopos_execucao_1 = require("../pilha-escopos-execucao");
|
|
44
|
+
const quebras_1 = require("../../quebras");
|
|
45
|
+
const inferenciador_1 = require("../inferenciador");
|
|
46
|
+
const egua_classico_1 = __importDefault(require("../../tipos-de-simbolos/egua-classico"));
|
|
83
47
|
/**
|
|
84
48
|
* O Interpretador visita todos os elementos complexos gerados pelo analisador sintático (Parser)
|
|
85
49
|
* e de fato executa a lógica de programação descrita no código.
|
|
86
50
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
51
|
+
class InterpretadorEguaClassico {
|
|
52
|
+
constructor(Delegua, resolvedor, diretorioBase) {
|
|
89
53
|
this.interfaceEntradaSaida = null;
|
|
90
54
|
this.Delegua = Delegua;
|
|
91
55
|
this.resolvedor = resolvedor;
|
|
@@ -94,7 +58,7 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
94
58
|
this.locais = new Map();
|
|
95
59
|
this.erros = [];
|
|
96
60
|
this.pilhaEscoposExecucao = new pilha_escopos_execucao_1.PilhaEscoposExecucao();
|
|
97
|
-
|
|
61
|
+
const escopoExecucao = {
|
|
98
62
|
declaracoes: [],
|
|
99
63
|
declaracaoAtual: 0,
|
|
100
64
|
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
@@ -102,56 +66,47 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
102
66
|
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
103
67
|
(0, biblioteca_global_1.default)(this, this.pilhaEscoposExecucao);
|
|
104
68
|
}
|
|
105
|
-
|
|
69
|
+
visitarExpressaoLeia(expressao) {
|
|
106
70
|
throw new Error('Método não implementado.');
|
|
107
|
-
}
|
|
108
|
-
|
|
71
|
+
}
|
|
72
|
+
visitarExpressaoLiteral(expressao) {
|
|
109
73
|
return expressao.valor;
|
|
110
|
-
}
|
|
111
|
-
|
|
74
|
+
}
|
|
75
|
+
avaliar(expressao) {
|
|
112
76
|
return expressao.aceitar(this);
|
|
113
|
-
}
|
|
114
|
-
|
|
77
|
+
}
|
|
78
|
+
visitarExpressaoAgrupamento(expressao) {
|
|
115
79
|
return this.avaliar(expressao.expressao);
|
|
116
|
-
}
|
|
117
|
-
|
|
80
|
+
}
|
|
81
|
+
eVerdadeiro(objeto) {
|
|
118
82
|
if (objeto === null)
|
|
119
83
|
return false;
|
|
120
84
|
if (typeof objeto === 'boolean')
|
|
121
85
|
return Boolean(objeto);
|
|
122
86
|
return true;
|
|
123
|
-
}
|
|
124
|
-
|
|
87
|
+
}
|
|
88
|
+
verificarOperandoNumero(operador, operando) {
|
|
125
89
|
if (typeof operando === 'number' || operando.tipo === 'número')
|
|
126
90
|
return;
|
|
127
91
|
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operador precisa ser um número.', operador.linha);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
case egua_classico_1.default.BIT_NOT:
|
|
147
|
-
return [2 /*return*/, ~valor];
|
|
148
|
-
}
|
|
149
|
-
return [2 /*return*/, null];
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
InterpretadorEguaClassico.prototype.eIgual = function (esquerda, direita) {
|
|
92
|
+
}
|
|
93
|
+
async visitarExpressaoUnaria(expr) {
|
|
94
|
+
const direita = await this.avaliar(expr.direita);
|
|
95
|
+
const valor = direita.hasOwnProperty('valor') ?
|
|
96
|
+
direita.valor :
|
|
97
|
+
direita;
|
|
98
|
+
switch (expr.operador.tipo) {
|
|
99
|
+
case egua_classico_1.default.SUBTRACAO:
|
|
100
|
+
this.verificarOperandoNumero(expr.operador, valor);
|
|
101
|
+
return -valor;
|
|
102
|
+
case egua_classico_1.default.NEGACAO:
|
|
103
|
+
return !this.eVerdadeiro(valor);
|
|
104
|
+
case egua_classico_1.default.BIT_NOT:
|
|
105
|
+
return ~valor;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
eIgual(esquerda, direita) {
|
|
155
110
|
if (esquerda.tipo) {
|
|
156
111
|
if (esquerda.tipo === 'nulo' &&
|
|
157
112
|
direita.tipo &&
|
|
@@ -166,14 +121,14 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
166
121
|
if (esquerda === null)
|
|
167
122
|
return false;
|
|
168
123
|
return esquerda === direita;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
124
|
+
}
|
|
125
|
+
verificarOperandosNumeros(operador, direita, esquerda) {
|
|
126
|
+
const tipoDireita = direita.tipo
|
|
172
127
|
? direita.tipo
|
|
173
128
|
: typeof direita === 'number'
|
|
174
129
|
? 'número'
|
|
175
130
|
: String(NaN);
|
|
176
|
-
|
|
131
|
+
const tipoEsquerda = esquerda.tipo
|
|
177
132
|
? esquerda.tipo
|
|
178
133
|
: typeof esquerda === 'number'
|
|
179
134
|
? 'número'
|
|
@@ -181,537 +136,325 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
181
136
|
if (tipoDireita === 'número' && tipoEsquerda === 'número')
|
|
182
137
|
return;
|
|
183
138
|
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
// 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
|
-
});
|
|
338
|
-
};
|
|
339
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoDeAtribuicao = function (expressao) {
|
|
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
|
-
});
|
|
352
|
-
};
|
|
353
|
-
InterpretadorEguaClassico.prototype.procurarVariavel = function (simbolo, expressao) {
|
|
139
|
+
}
|
|
140
|
+
async visitarExpressaoBinaria(expressao) {
|
|
141
|
+
try {
|
|
142
|
+
const esquerda = await this.avaliar(expressao.esquerda);
|
|
143
|
+
const direita = await this.avaliar(expressao.direita);
|
|
144
|
+
const valorEsquerdo = esquerda.hasOwnProperty('valor')
|
|
145
|
+
? esquerda.valor
|
|
146
|
+
: esquerda;
|
|
147
|
+
const valorDireito = direita.hasOwnProperty('valor')
|
|
148
|
+
? direita.valor
|
|
149
|
+
: direita;
|
|
150
|
+
const tipoEsquerdo = esquerda.hasOwnProperty('tipo')
|
|
151
|
+
? esquerda.tipo
|
|
152
|
+
: (0, inferenciador_1.inferirTipoVariavel)(esquerda);
|
|
153
|
+
const tipoDireito = direita.hasOwnProperty('tipo')
|
|
154
|
+
? direita.tipo
|
|
155
|
+
: (0, inferenciador_1.inferirTipoVariavel)(direita);
|
|
156
|
+
switch (expressao.operador.tipo) {
|
|
157
|
+
case egua_classico_1.default.EXPONENCIACAO:
|
|
158
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
159
|
+
return Math.pow(valorEsquerdo, valorDireito);
|
|
160
|
+
case egua_classico_1.default.MAIOR:
|
|
161
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
162
|
+
return Number(valorEsquerdo) > Number(valorDireito);
|
|
163
|
+
case egua_classico_1.default.MAIOR_IGUAL:
|
|
164
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
165
|
+
return Number(valorEsquerdo) >= Number(valorDireito);
|
|
166
|
+
case egua_classico_1.default.MENOR:
|
|
167
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
168
|
+
return Number(valorEsquerdo) < Number(valorDireito);
|
|
169
|
+
case egua_classico_1.default.MENOR_IGUAL:
|
|
170
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
171
|
+
return Number(valorEsquerdo) <= Number(valorDireito);
|
|
172
|
+
case egua_classico_1.default.SUBTRACAO:
|
|
173
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
174
|
+
return Number(valorEsquerdo) - Number(valorDireito);
|
|
175
|
+
case egua_classico_1.default.ADICAO:
|
|
176
|
+
if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
|
|
177
|
+
return Number(esquerda) + Number(direita);
|
|
178
|
+
}
|
|
179
|
+
else if (tipoEsquerdo === 'texto' &&
|
|
180
|
+
tipoDireito === 'texto') {
|
|
181
|
+
return String(esquerda) + String(direita);
|
|
182
|
+
}
|
|
183
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
|
|
184
|
+
case egua_classico_1.default.DIVISAO:
|
|
185
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
186
|
+
return Number(valorEsquerdo) / Number(valorDireito);
|
|
187
|
+
case egua_classico_1.default.MULTIPLICACAO:
|
|
188
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
189
|
+
return Number(valorEsquerdo) * Number(valorDireito);
|
|
190
|
+
case egua_classico_1.default.MODULO:
|
|
191
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
192
|
+
return Number(valorEsquerdo) % Number(valorDireito);
|
|
193
|
+
case egua_classico_1.default.BIT_AND:
|
|
194
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
195
|
+
return Number(valorEsquerdo) & Number(valorDireito);
|
|
196
|
+
case egua_classico_1.default.BIT_XOR:
|
|
197
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
198
|
+
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
199
|
+
case egua_classico_1.default.BIT_OR:
|
|
200
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
201
|
+
return Number(valorEsquerdo) | Number(valorDireito);
|
|
202
|
+
case egua_classico_1.default.MENOR_MENOR:
|
|
203
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
204
|
+
return Number(valorEsquerdo) << Number(valorDireito);
|
|
205
|
+
case egua_classico_1.default.MAIOR_MAIOR:
|
|
206
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
207
|
+
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
208
|
+
case egua_classico_1.default.DIFERENTE:
|
|
209
|
+
return !this.eIgual(valorEsquerdo, valorDireito);
|
|
210
|
+
case egua_classico_1.default.IGUAL_IGUAL:
|
|
211
|
+
return this.eIgual(valorEsquerdo, valorDireito);
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
catch (erro) {
|
|
216
|
+
return Promise.reject(erro);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async visitarExpressaoDeChamada(expressao) {
|
|
220
|
+
const variavelEntidadeChamada = await this.avaliar(expressao.entidadeChamada);
|
|
221
|
+
const entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
|
|
222
|
+
? variavelEntidadeChamada.valor
|
|
223
|
+
: variavelEntidadeChamada;
|
|
224
|
+
let argumentos = [];
|
|
225
|
+
for (let i = 0; i < expressao.argumentos.length; i++) {
|
|
226
|
+
argumentos.push(await this.avaliar(expressao.argumentos[i]));
|
|
227
|
+
}
|
|
228
|
+
if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
|
|
229
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
|
|
230
|
+
}
|
|
231
|
+
let parametros;
|
|
232
|
+
if (entidadeChamada instanceof delegua_funcao_1.DeleguaFuncao) {
|
|
233
|
+
parametros = entidadeChamada.declaracao.parametros;
|
|
234
|
+
}
|
|
235
|
+
else if (entidadeChamada instanceof delegua_classe_1.DeleguaClasse) {
|
|
236
|
+
parametros = entidadeChamada.metodos.inicializacao
|
|
237
|
+
? entidadeChamada.metodos.inicializacao.declaracao.parametros
|
|
238
|
+
: [];
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
parametros = [];
|
|
242
|
+
}
|
|
243
|
+
// Isso aqui completa os parâmetros não preenchidos com nulos.
|
|
244
|
+
if (argumentos.length < entidadeChamada.aridade()) {
|
|
245
|
+
const diferenca = entidadeChamada.aridade() - argumentos.length;
|
|
246
|
+
for (let i = 0; i < diferenca; i++) {
|
|
247
|
+
argumentos.push(null);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
if (parametros &&
|
|
252
|
+
parametros.length > 0 &&
|
|
253
|
+
parametros[parametros.length - 1]['tipo'] === 'estrela') {
|
|
254
|
+
const novosArgumentos = argumentos.slice(0, parametros.length - 1);
|
|
255
|
+
novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
|
|
256
|
+
argumentos = novosArgumentos;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
|
|
260
|
+
return entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome);
|
|
261
|
+
}
|
|
262
|
+
return entidadeChamada.chamar(this, argumentos);
|
|
263
|
+
}
|
|
264
|
+
async visitarExpressaoDeAtribuicao(expressao) {
|
|
265
|
+
const valor = await this.avaliar(expressao.valor);
|
|
266
|
+
this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
|
|
267
|
+
return valor;
|
|
268
|
+
}
|
|
269
|
+
procurarVariavel(simbolo, expressao) {
|
|
354
270
|
return this.pilhaEscoposExecucao.obterVariavel(simbolo);
|
|
355
|
-
}
|
|
356
|
-
|
|
271
|
+
}
|
|
272
|
+
visitarExpressaoDeVariavel(expressao) {
|
|
357
273
|
return this.procurarVariavel(expressao.simbolo, expressao);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
return
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
});
|
|
443
|
-
};
|
|
444
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoPara = function (declaracao) {
|
|
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];
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
};
|
|
486
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoFazer = function (declaracao) {
|
|
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*/];
|
|
274
|
+
}
|
|
275
|
+
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
276
|
+
return await this.avaliar(declaracao.expressao);
|
|
277
|
+
}
|
|
278
|
+
async visitarExpressaoLogica(expressao) {
|
|
279
|
+
const esquerda = await this.avaliar(expressao.esquerda);
|
|
280
|
+
if (expressao.operador.tipo === egua_classico_1.default.EM) {
|
|
281
|
+
const direita = await this.avaliar(expressao.direita);
|
|
282
|
+
if (Array.isArray(direita) || typeof direita === 'string') {
|
|
283
|
+
return direita.includes(esquerda);
|
|
284
|
+
}
|
|
285
|
+
else if (direita.constructor === Object) {
|
|
286
|
+
return esquerda in direita;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// se um estado for verdadeiro, retorna verdadeiro
|
|
293
|
+
if (expressao.operador.tipo === egua_classico_1.default.OU) {
|
|
294
|
+
if (this.eVerdadeiro(esquerda))
|
|
295
|
+
return esquerda;
|
|
296
|
+
}
|
|
297
|
+
// se um estado for falso, retorna falso
|
|
298
|
+
if (expressao.operador.tipo === egua_classico_1.default.E) {
|
|
299
|
+
if (!this.eVerdadeiro(esquerda))
|
|
300
|
+
return esquerda;
|
|
301
|
+
}
|
|
302
|
+
return await this.avaliar(expressao.direita);
|
|
303
|
+
}
|
|
304
|
+
async visitarExpressaoSe(declaracao) {
|
|
305
|
+
if (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
306
|
+
return await this.executar(declaracao.caminhoEntao);
|
|
307
|
+
}
|
|
308
|
+
for (let i = 0; i < declaracao.caminhosSeSenao.length; i++) {
|
|
309
|
+
const atual = declaracao.caminhosSeSenao[i];
|
|
310
|
+
if (this.eVerdadeiro(await this.avaliar(atual.condicao))) {
|
|
311
|
+
return await this.executar(atual.caminho);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (declaracao.caminhoSenao !== null) {
|
|
315
|
+
return await this.executar(declaracao.caminhoSenao);
|
|
316
|
+
}
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
async visitarExpressaoPara(declaracao) {
|
|
320
|
+
if (declaracao.inicializador !== null) {
|
|
321
|
+
await this.avaliar(declaracao.inicializador);
|
|
322
|
+
}
|
|
323
|
+
while (true) {
|
|
324
|
+
if (declaracao.condicao !== null) {
|
|
325
|
+
if (!this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
326
|
+
break;
|
|
507
327
|
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
await this.executar(declaracao.corpo);
|
|
331
|
+
}
|
|
332
|
+
catch (erro) {
|
|
333
|
+
throw erro;
|
|
334
|
+
}
|
|
335
|
+
if (declaracao.incrementar !== null) {
|
|
336
|
+
await this.avaliar(declaracao.incrementar);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
async visitarExpressaoFazer(declaracao) {
|
|
342
|
+
do {
|
|
343
|
+
try {
|
|
344
|
+
await this.executar(declaracao.caminhoFazer);
|
|
345
|
+
}
|
|
346
|
+
catch (erro) {
|
|
347
|
+
throw erro;
|
|
348
|
+
}
|
|
349
|
+
} while (this.eVerdadeiro(await this.avaliar(declaracao.condicaoEnquanto)));
|
|
350
|
+
}
|
|
351
|
+
async visitarExpressaoEscolha(declaracao) {
|
|
352
|
+
const condicaoEscolha = await this.avaliar(declaracao.identificadorOuLiteral);
|
|
353
|
+
const caminhos = declaracao.caminhos;
|
|
354
|
+
const caminhoPadrao = declaracao.caminhoPadrao;
|
|
355
|
+
let encontrado = false;
|
|
356
|
+
try {
|
|
357
|
+
for (let i = 0; i < caminhos.length; i++) {
|
|
358
|
+
const caminho = caminhos[i];
|
|
359
|
+
for (let j = 0; j < caminho.condicoes.length; j++) {
|
|
360
|
+
if (await this.avaliar(caminho.condicoes[j]) === condicaoEscolha) {
|
|
537
361
|
encontrado = true;
|
|
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*/];
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
});
|
|
583
|
-
};
|
|
584
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoTente = function (declaracao) {
|
|
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*/];
|
|
626
|
-
}
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
};
|
|
630
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoEnquanto = function (declaracao) {
|
|
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
|
-
});
|
|
655
|
-
};
|
|
656
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoImportar = function (declaracao) {
|
|
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
362
|
try {
|
|
669
|
-
|
|
670
|
-
|
|
363
|
+
for (let k = 0; k < caminho.declaracoes.length; k++) {
|
|
364
|
+
await this.executar(caminho.declaracoes[k]);
|
|
671
365
|
}
|
|
672
366
|
}
|
|
673
367
|
catch (erro) {
|
|
674
|
-
throw
|
|
675
|
-
}
|
|
676
|
-
dados = fs.readFileSync(caminhoTotal).toString();
|
|
677
|
-
delegua = new delegua_1.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];
|
|
368
|
+
throw erro;
|
|
688
369
|
}
|
|
689
|
-
|
|
370
|
+
}
|
|
690
371
|
}
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
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*/];
|
|
372
|
+
}
|
|
373
|
+
if (caminhoPadrao !== null && encontrado === false) {
|
|
374
|
+
for (let i = 0; i < caminhoPadrao.declaracoes.length; i++) {
|
|
375
|
+
await this.executar(caminhoPadrao['declaracoes'][i]);
|
|
711
376
|
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
catch (erro) {
|
|
380
|
+
throw erro;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async visitarExpressaoTente(declaracao) {
|
|
384
|
+
try {
|
|
385
|
+
let sucesso = true;
|
|
386
|
+
try {
|
|
387
|
+
await this.executarBloco(declaracao.caminhoTente);
|
|
388
|
+
}
|
|
389
|
+
catch (erro) {
|
|
390
|
+
sucesso = false;
|
|
391
|
+
if (declaracao.caminhoPegue !== null) {
|
|
392
|
+
await this.executarBloco(declaracao.caminhoPegue);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
this.erros.push(erro);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (sucesso && declaracao.caminhoSenao !== null) {
|
|
399
|
+
await this.executarBloco(declaracao.caminhoSenao);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
finally {
|
|
403
|
+
if (declaracao.caminhoFinalmente !== null)
|
|
404
|
+
await this.executarBloco(declaracao.caminhoFinalmente);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async visitarExpressaoEnquanto(declaracao) {
|
|
408
|
+
while (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
409
|
+
try {
|
|
410
|
+
await this.executar(declaracao.corpo);
|
|
411
|
+
}
|
|
412
|
+
catch (erro) {
|
|
413
|
+
throw erro;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
async visitarExpressaoImportar(declaracao) {
|
|
419
|
+
const caminhoRelativo = await this.avaliar(declaracao.caminho);
|
|
420
|
+
const caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
|
|
421
|
+
// const nomeArquivo = caminho.basename(caminhoTotal);
|
|
422
|
+
let dados = (0, importar_biblioteca_1.default)(caminhoRelativo);
|
|
423
|
+
if (dados)
|
|
424
|
+
return dados;
|
|
425
|
+
try {
|
|
426
|
+
if (!fs.existsSync(caminhoTotal)) {
|
|
427
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível encontrar arquivo importado.', declaracao.linha);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
catch (erro) {
|
|
431
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível ler o arquivo.', declaracao.linha);
|
|
432
|
+
}
|
|
433
|
+
dados = fs.readFileSync(caminhoTotal).toString();
|
|
434
|
+
const delegua = new delegua_1.Delegua(this.Delegua.dialeto, false);
|
|
435
|
+
delegua.executar(dados);
|
|
436
|
+
const exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
|
|
437
|
+
const eDicionario = (objeto) => objeto.constructor === Object;
|
|
438
|
+
if (eDicionario(exportar)) {
|
|
439
|
+
const novoModulo = new modulo_1.DeleguaModulo();
|
|
440
|
+
const chaves = Object.keys(exportar);
|
|
441
|
+
for (let i = 0; i < chaves.length; i++) {
|
|
442
|
+
novoModulo[chaves[i]] = exportar[chaves[i]];
|
|
443
|
+
}
|
|
444
|
+
return novoModulo;
|
|
445
|
+
}
|
|
446
|
+
return exportar;
|
|
447
|
+
}
|
|
448
|
+
async visitarExpressaoEscreva(declaracao) {
|
|
449
|
+
try {
|
|
450
|
+
const valor = await this.avaliar(declaracao.argumentos[0]);
|
|
451
|
+
console.log(this.paraTexto(valor));
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
catch (erro) {
|
|
455
|
+
this.erros.push(erro);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
715
458
|
/**
|
|
716
459
|
* Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
|
|
717
460
|
* executa as declarações empilhadas.
|
|
@@ -722,355 +465,221 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
722
465
|
* @param declaracoes Um vetor de declaracoes a ser executado.
|
|
723
466
|
* @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
|
|
724
467
|
*/
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
throw retornoUltimoEscopo;
|
|
742
|
-
}
|
|
743
|
-
return [2 /*return*/, retornoUltimoEscopo];
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
|
-
};
|
|
748
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoBloco = function (declaracao) {
|
|
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
|
-
});
|
|
757
|
-
};
|
|
468
|
+
async executarBloco(declaracoes, ambiente) {
|
|
469
|
+
const escopoExecucao = {
|
|
470
|
+
declaracoes: declaracoes,
|
|
471
|
+
declaracaoAtual: 0,
|
|
472
|
+
ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
|
|
473
|
+
};
|
|
474
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
475
|
+
const retornoUltimoEscopo = await this.executarUltimoEscopo();
|
|
476
|
+
if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
|
|
477
|
+
throw retornoUltimoEscopo;
|
|
478
|
+
}
|
|
479
|
+
return retornoUltimoEscopo;
|
|
480
|
+
}
|
|
481
|
+
async visitarExpressaoBloco(declaracao) {
|
|
482
|
+
return await this.executarBloco(declaracao.declaracoes);
|
|
483
|
+
}
|
|
758
484
|
/**
|
|
759
485
|
* Executa expressão de definição de variável.
|
|
760
486
|
* @param declaracao A declaração Var
|
|
761
487
|
* @returns Sempre retorna nulo.
|
|
762
488
|
*/
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
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
|
-
});
|
|
783
|
-
};
|
|
784
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoContinua = function (declaracao) {
|
|
489
|
+
async visitarExpressaoVar(declaracao) {
|
|
490
|
+
let valorOuOutraVariavel = null;
|
|
491
|
+
if (declaracao.inicializador !== null) {
|
|
492
|
+
valorOuOutraVariavel = await this.avaliar(declaracao.inicializador);
|
|
493
|
+
}
|
|
494
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
|
|
495
|
+
? valorOuOutraVariavel.valor
|
|
496
|
+
: valorOuOutraVariavel);
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
visitarExpressaoContinua(declaracao) {
|
|
785
500
|
return new quebras_1.ContinuarQuebra();
|
|
786
|
-
}
|
|
787
|
-
|
|
501
|
+
}
|
|
502
|
+
visitarExpressaoSustar(declaracao) {
|
|
788
503
|
return new quebras_1.SustarQuebra();
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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
|
-
});
|
|
806
|
-
};
|
|
807
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoDeleguaFuncao = function (expressao) {
|
|
504
|
+
}
|
|
505
|
+
async visitarExpressaoRetornar(declaracao) {
|
|
506
|
+
let valor = null;
|
|
507
|
+
if (declaracao.valor != null)
|
|
508
|
+
valor = await this.avaliar(declaracao.valor);
|
|
509
|
+
return new quebras_1.RetornoQuebra(valor);
|
|
510
|
+
}
|
|
511
|
+
visitarExpressaoDeleguaFuncao(expressao) {
|
|
808
512
|
return new delegua_funcao_1.DeleguaFuncao(null, expressao);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
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
|
+
}
|
|
514
|
+
async visitarExpressaoAtribuicaoSobrescrita(expressao) {
|
|
515
|
+
const objeto = await this.avaliar(expressao.objeto);
|
|
516
|
+
let indice = await this.avaliar(expressao.indice);
|
|
517
|
+
const valor = await this.avaliar(expressao.valor);
|
|
518
|
+
if (Array.isArray(objeto)) {
|
|
519
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
520
|
+
while (indice < 0) {
|
|
521
|
+
indice += objeto.length;
|
|
846
522
|
}
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
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*/];
|
|
523
|
+
}
|
|
524
|
+
while (objeto.length < indice) {
|
|
525
|
+
objeto.push(null);
|
|
526
|
+
}
|
|
527
|
+
objeto[indice] = valor;
|
|
528
|
+
}
|
|
529
|
+
else if (objeto.constructor === Object ||
|
|
530
|
+
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
531
|
+
objeto instanceof delegua_funcao_1.DeleguaFuncao ||
|
|
532
|
+
objeto instanceof delegua_classe_1.DeleguaClasse ||
|
|
533
|
+
objeto instanceof modulo_1.DeleguaModulo) {
|
|
534
|
+
objeto[indice] = valor;
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async visitarExpressaoAcessoIndiceVariavel(expressao) {
|
|
541
|
+
const variavelObjeto = await this.avaliar(expressao.entidadeChamada);
|
|
542
|
+
const objeto = variavelObjeto.hasOwnProperty('valor')
|
|
543
|
+
? variavelObjeto.valor
|
|
544
|
+
: variavelObjeto;
|
|
545
|
+
let indice = await this.avaliar(expressao.indice);
|
|
546
|
+
const valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
|
|
547
|
+
if (Array.isArray(objeto)) {
|
|
548
|
+
if (!Number.isInteger(valorIndice)) {
|
|
549
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
550
|
+
}
|
|
551
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
552
|
+
while (indice < 0) {
|
|
553
|
+
indice += objeto.length;
|
|
904
554
|
}
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
return [2 /*return*/, valor];
|
|
926
|
-
}
|
|
927
|
-
else if (objeto.constructor === Object) {
|
|
928
|
-
objeto[expressao.simbolo.lexema] = valor;
|
|
929
|
-
}
|
|
930
|
-
return [2 /*return*/];
|
|
555
|
+
}
|
|
556
|
+
if (indice >= objeto.length) {
|
|
557
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
|
|
558
|
+
}
|
|
559
|
+
return objeto[indice];
|
|
560
|
+
}
|
|
561
|
+
else if (objeto.constructor === Object ||
|
|
562
|
+
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
563
|
+
objeto instanceof delegua_funcao_1.DeleguaFuncao ||
|
|
564
|
+
objeto instanceof delegua_classe_1.DeleguaClasse ||
|
|
565
|
+
objeto instanceof modulo_1.DeleguaModulo) {
|
|
566
|
+
return objeto[indice] || null;
|
|
567
|
+
}
|
|
568
|
+
else if (typeof objeto === 'string') {
|
|
569
|
+
if (!Number.isInteger(indice)) {
|
|
570
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
571
|
+
}
|
|
572
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
573
|
+
while (indice < 0) {
|
|
574
|
+
indice += objeto.length;
|
|
931
575
|
}
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
576
|
+
}
|
|
577
|
+
if (indice >= objeto.length) {
|
|
578
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
|
|
579
|
+
}
|
|
580
|
+
return objeto.charAt(indice);
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
async visitarExpressaoDefinirValor(expressao) {
|
|
587
|
+
const objeto = await this.avaliar(expressao.objeto);
|
|
588
|
+
if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) &&
|
|
589
|
+
objeto.constructor !== Object) {
|
|
590
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
|
|
591
|
+
}
|
|
592
|
+
const valor = await this.avaliar(expressao.valor);
|
|
593
|
+
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
594
|
+
objeto.definir(expressao.nome, valor);
|
|
595
|
+
return valor;
|
|
596
|
+
}
|
|
597
|
+
else if (objeto.constructor === Object) {
|
|
598
|
+
objeto[expressao.simbolo.lexema] = valor;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
visitarExpressaoFuncao(declaracao) {
|
|
602
|
+
const funcao = new delegua_funcao_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
937
603
|
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
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
|
-
});
|
|
1001
|
-
};
|
|
1002
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoIsto = function (expressao) {
|
|
604
|
+
}
|
|
605
|
+
async visitarExpressaoClasse(declaracao) {
|
|
606
|
+
let superClasse = null;
|
|
607
|
+
if (declaracao.superClasse !== null) {
|
|
608
|
+
const variavelSuperClasse = await this.avaliar(declaracao.superClasse);
|
|
609
|
+
superClasse = variavelSuperClasse.valor;
|
|
610
|
+
if (!(superClasse instanceof delegua_classe_1.DeleguaClasse)) {
|
|
611
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
|
|
615
|
+
if (declaracao.superClasse !== null) {
|
|
616
|
+
this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
|
|
617
|
+
}
|
|
618
|
+
const metodos = {};
|
|
619
|
+
const definirMetodos = declaracao.metodos;
|
|
620
|
+
for (let i = 0; i < declaracao.metodos.length; i++) {
|
|
621
|
+
const metodoAtual = definirMetodos[i];
|
|
622
|
+
const eInicializador = metodoAtual.simbolo.lexema === 'construtor';
|
|
623
|
+
const funcao = new delegua_funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
|
|
624
|
+
metodos[metodoAtual.simbolo.lexema] = funcao;
|
|
625
|
+
}
|
|
626
|
+
const deleguaClasse = new delegua_classe_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
|
|
627
|
+
// TODO: Recolocar isso se for necessário.
|
|
628
|
+
/* if (superClasse !== null) {
|
|
629
|
+
this.ambiente = this.ambiente.enclosing;
|
|
630
|
+
} */
|
|
631
|
+
this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
async visitarExpressaoAcessoMetodo(expressao) {
|
|
635
|
+
const variavelObjeto = await this.avaliar(expressao.objeto);
|
|
636
|
+
const objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
|
|
637
|
+
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
638
|
+
return objeto.obter(expressao.simbolo) || null;
|
|
639
|
+
}
|
|
640
|
+
else if (objeto.constructor === Object) {
|
|
641
|
+
return objeto[expressao.simbolo.lexema] || null;
|
|
642
|
+
}
|
|
643
|
+
else if (objeto instanceof modulo_1.DeleguaModulo) {
|
|
644
|
+
return objeto[expressao.simbolo.lexema] || null;
|
|
645
|
+
}
|
|
646
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
|
|
647
|
+
}
|
|
648
|
+
visitarExpressaoIsto(expressao) {
|
|
1003
649
|
return this.procurarVariavel(expressao.palavraChave, expressao);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
case 4:
|
|
1025
|
-
i++;
|
|
1026
|
-
return [3 /*break*/, 1];
|
|
1027
|
-
case 5: return [2 /*return*/, dicionario];
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
1030
|
-
});
|
|
1031
|
-
};
|
|
1032
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoVetor = function (expressao) {
|
|
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
|
-
});
|
|
1055
|
-
};
|
|
1056
|
-
InterpretadorEguaClassico.prototype.visitarExpressaoSuper = function (expressao) {
|
|
1057
|
-
var distancia = this.locais.get(expressao);
|
|
1058
|
-
var superClasse = this.pilhaEscoposExecucao.obterVariavelEm(distancia, 'super');
|
|
1059
|
-
var objeto = this.pilhaEscoposExecucao.obterVariavelEm(distancia - 1, 'isto');
|
|
1060
|
-
var metodo = superClasse.valor.encontrarMetodo(expressao.metodo.lexema);
|
|
650
|
+
}
|
|
651
|
+
async visitarExpressaoDicionario(expressao) {
|
|
652
|
+
const dicionario = {};
|
|
653
|
+
for (let i = 0; i < expressao.chaves.length; i++) {
|
|
654
|
+
dicionario[await this.avaliar(expressao.chaves[i])] = await this.avaliar(expressao.valores[i]);
|
|
655
|
+
}
|
|
656
|
+
return dicionario;
|
|
657
|
+
}
|
|
658
|
+
async visitarExpressaoVetor(expressao) {
|
|
659
|
+
const valores = [];
|
|
660
|
+
for (let i = 0; i < expressao.valores.length; i++) {
|
|
661
|
+
valores.push(await this.avaliar(expressao.valores[i]));
|
|
662
|
+
}
|
|
663
|
+
return valores;
|
|
664
|
+
}
|
|
665
|
+
visitarExpressaoSuper(expressao) {
|
|
666
|
+
const distancia = this.locais.get(expressao);
|
|
667
|
+
const superClasse = this.pilhaEscoposExecucao.obterVariavelEm(distancia, 'super');
|
|
668
|
+
const objeto = this.pilhaEscoposExecucao.obterVariavelEm(distancia - 1, 'isto');
|
|
669
|
+
const metodo = superClasse.valor.encontrarMetodo(expressao.metodo.lexema);
|
|
1061
670
|
if (metodo === undefined) {
|
|
1062
671
|
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.metodo, 'Método chamado indefinido.', expressao.linha);
|
|
1063
672
|
}
|
|
1064
673
|
return metodo.definirInstancia(objeto.valor);
|
|
1065
|
-
}
|
|
1066
|
-
|
|
674
|
+
}
|
|
675
|
+
paraTexto(objeto) {
|
|
1067
676
|
if (objeto === null)
|
|
1068
677
|
return 'nulo';
|
|
1069
678
|
if (typeof objeto === 'boolean') {
|
|
1070
679
|
return objeto ? 'verdadeiro' : 'falso';
|
|
1071
680
|
}
|
|
1072
681
|
if (objeto instanceof Date) {
|
|
1073
|
-
|
|
682
|
+
const formato = Intl.DateTimeFormat('pt', {
|
|
1074
683
|
dateStyle: 'full',
|
|
1075
684
|
timeStyle: 'full',
|
|
1076
685
|
});
|
|
@@ -1084,18 +693,10 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
1084
693
|
return 'nulo';
|
|
1085
694
|
}
|
|
1086
695
|
return objeto.toString();
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
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
|
-
});
|
|
1098
|
-
};
|
|
696
|
+
}
|
|
697
|
+
async executar(declaracao, mostrarResultado = false) {
|
|
698
|
+
return await declaracao.aceitar(this);
|
|
699
|
+
}
|
|
1099
700
|
/**
|
|
1100
701
|
* Executa o último escopo empilhado no topo na pilha de escopos do Interpretador.
|
|
1101
702
|
* Originalmente, Égua não trabalha com uma pilha de escopos.
|
|
@@ -1109,69 +710,41 @@ var InterpretadorEguaClassico = /** @class */ (function () {
|
|
|
1109
710
|
* Interpretador Égua: https://github.com/eguatech/egua/blob/master/src/interpreter.js
|
|
1110
711
|
* @returns O resultado da execução do escopo, se houver.
|
|
1111
712
|
*/
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
};
|
|
1146
|
-
InterpretadorEguaClassico.prototype.interpretar = function (declaracoes) {
|
|
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 () {
|
|
713
|
+
async executarUltimoEscopo() {
|
|
714
|
+
const ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
|
|
715
|
+
try {
|
|
716
|
+
let retornoExecucao;
|
|
717
|
+
for (; !(retornoExecucao instanceof quebras_1.Quebra) &&
|
|
718
|
+
ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length; ultimoEscopo.declaracaoAtual++) {
|
|
719
|
+
retornoExecucao = await this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual]);
|
|
720
|
+
}
|
|
721
|
+
return retornoExecucao;
|
|
722
|
+
}
|
|
723
|
+
catch (erro) {
|
|
724
|
+
return erro;
|
|
725
|
+
}
|
|
726
|
+
finally {
|
|
727
|
+
this.pilhaEscoposExecucao.removerUltimo();
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
async interpretar(declaracoes) {
|
|
731
|
+
this.erros = [];
|
|
732
|
+
const retornoResolvedor = this.resolvedor.resolver(declaracoes);
|
|
733
|
+
this.locais = retornoResolvedor.locais;
|
|
734
|
+
const escopoExecucao = {
|
|
735
|
+
declaracoes: declaracoes,
|
|
736
|
+
declaracaoAtual: 0,
|
|
737
|
+
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
738
|
+
};
|
|
739
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
740
|
+
await this.executarUltimoEscopo();
|
|
741
|
+
return {
|
|
742
|
+
erros: this.erros,
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
finalizacao() {
|
|
1172
746
|
this.funcaoDeRetorno();
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
}());
|
|
747
|
+
}
|
|
748
|
+
}
|
|
1176
749
|
exports.InterpretadorEguaClassico = InterpretadorEguaClassico;
|
|
1177
750
|
//# sourceMappingURL=egua-classico.js.map
|