@designliquido/delegua 0.26.3 → 0.28.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/analisador-semantico/analisador-semantico.d.ts +8 -5
- package/fontes/analisador-semantico/analisador-semantico.js +55 -12
- package/fontes/analisador-semantico/analisador-semantico.js.map +1 -1
- package/fontes/analisador-semantico/dialetos/analisador-semantico-birl.d.ts +2 -2
- package/fontes/analisador-semantico/dialetos/analisador-semantico-birl.js +12 -7
- package/fontes/analisador-semantico/dialetos/analisador-semantico-birl.js.map +1 -1
- package/fontes/avaliador-sintatico/avaliador-sintatico.d.ts +2 -0
- package/fontes/avaliador-sintatico/avaliador-sintatico.js +60 -10
- package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +2 -2
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +2 -2
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/potigol/avaliador-sintatico-potigol.js +5 -16
- package/fontes/avaliador-sintatico/dialetos/potigol/avaliador-sintatico-potigol.js.map +1 -1
- package/fontes/avaliador-sintatico/micro-avaliador-sintatico.js +1 -1
- package/fontes/avaliador-sintatico/micro-avaliador-sintatico.js.map +1 -1
- package/fontes/construtos/{acesso-metodo.d.ts → acesso-metodo-ou-propriedade.d.ts} +1 -1
- package/fontes/construtos/{acesso-metodo.js → acesso-metodo-ou-propriedade.js} +4 -4
- package/fontes/construtos/acesso-metodo-ou-propriedade.js.map +1 -0
- 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/declaracoes/leia-multiplo.d.ts +2 -4
- package/fontes/declaracoes/leia-multiplo.js +2 -3
- package/fontes/declaracoes/leia-multiplo.js.map +1 -1
- package/fontes/declaracoes/var.d.ts +1 -0
- package/fontes/declaracoes/var.js +1 -0
- package/fontes/declaracoes/var.js.map +1 -1
- package/fontes/interfaces/erros/diagnostico-analisador-semantico.d.ts +14 -0
- package/fontes/interfaces/erros/diagnostico-analisador-semantico.js +11 -0
- package/fontes/interfaces/erros/diagnostico-analisador-semantico.js.map +1 -0
- package/fontes/interfaces/erros/index.d.ts +1 -1
- package/fontes/interfaces/erros/index.js +1 -1
- package/fontes/interfaces/erros/index.js.map +1 -1
- package/fontes/interfaces/retornos/retorno-analisador-semantico.d.ts +2 -2
- package/fontes/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts +2 -2
- package/fontes/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js.map +1 -1
- package/fontes/interpretador/dialetos/potigol/comum.d.ts +2 -2
- package/fontes/interpretador/dialetos/potigol/comum.js.map +1 -1
- package/fontes/interpretador/dialetos/potigol/interpretador-potigol-com-depuracao.d.ts +2 -2
- package/fontes/interpretador/dialetos/potigol/interpretador-potigol-com-depuracao.js.map +1 -1
- package/fontes/interpretador/dialetos/potigol/interpretador-potigol.d.ts +3 -2
- package/fontes/interpretador/dialetos/potigol/interpretador-potigol.js +13 -0
- package/fontes/interpretador/dialetos/potigol/interpretador-potigol.js.map +1 -1
- package/fontes/interpretador/interpretador-base.d.ts +1 -0
- package/fontes/interpretador/interpretador-base.js +142 -135
- package/fontes/interpretador/interpretador-base.js.map +1 -1
- package/fontes/tipos-de-dados/delegua.d.ts +8 -0
- package/fontes/tipos-de-dados/delegua.js +10 -0
- package/fontes/tipos-de-dados/delegua.js.map +1 -0
- package/fontes/tipos-de-dados/listas-delegua.d.ts +6 -0
- package/fontes/tipos-de-dados/listas-delegua.js +8 -0
- package/fontes/tipos-de-dados/listas-delegua.js.map +1 -0
- package/fontes/tipos-de-dados/listas-primitivos.d.ts +5 -0
- package/fontes/tipos-de-dados/listas-primitivos.js +7 -0
- package/fontes/tipos-de-dados/listas-primitivos.js.map +1 -0
- package/fontes/tipos-de-dados/primitivos.d.ts +16 -0
- package/fontes/tipos-de-dados/primitivos.js +18 -0
- package/fontes/tipos-de-dados/primitivos.js.map +1 -0
- package/fontes/tradutores/tradutor-assembly-x64.js +1 -1
- package/fontes/tradutores/tradutor-assembly-x64.js.map +1 -1
- package/fontes/tradutores/tradutor-assemblyscript.d.ts +3 -3
- package/fontes/tradutores/tradutor-assemblyscript.js +1 -1
- package/fontes/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/fontes/tradutores/tradutor-javascript.d.ts +3 -3
- package/fontes/tradutores/tradutor-javascript.js +1 -1
- package/fontes/tradutores/tradutor-javascript.js.map +1 -1
- package/fontes/tradutores/tradutor-python.d.ts +3 -3
- package/fontes/tradutores/tradutor-python.js +1 -1
- package/fontes/tradutores/tradutor-python.js.map +1 -1
- package/package.json +1 -1
- package/fontes/construtos/acesso-metodo.js.map +0 -1
- package/fontes/interfaces/erros/erro-analisador-semantico.d.ts +0 -7
- package/fontes/interfaces/erros/erro-analisador-semantico.js +0 -3
- package/fontes/interfaces/erros/erro-analisador-semantico.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpretador-potigol.js","sourceRoot":"","sources":["../../../../../fontes/interpretador/dialetos/potigol/interpretador-potigol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAA6D;AAE7D,+FAA2G;AAC3G,
|
|
1
|
+
{"version":3,"file":"interpretador-potigol.js","sourceRoot":"","sources":["../../../../../fontes/interpretador/dialetos/potigol/interpretador-potigol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAA6D;AAE7D,+FAA2G;AAC3G,oDAA8I;AAE9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AC,UAAuB;QAC5D,IAAI,YAAY,GAAW,EAAE,CAAC;QAE9B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAChC,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACzD,IAAI,KAAK,GAAG,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,cAAc,CAAC,OAAO,CAAC,EAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACxG,YAAY,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;SAC/C;QAED,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAEzC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,YAAY,GAAG,IAAI,YAAY,GAAG,CAAC;SACtC;QAED,OAAO,YAAY,CAAC;IACxB,CAAC;CAEJ;AAvFD,oDAuFC"}
|
|
@@ -27,6 +27,7 @@ export declare class InterpretadorBase implements InterpretadorInterface {
|
|
|
27
27
|
funcaoDeRetornoMesmaLinha: Function;
|
|
28
28
|
interfaceDeEntrada: any;
|
|
29
29
|
interfaceEntradaSaida: any;
|
|
30
|
+
emDeclaracaoTente: boolean;
|
|
30
31
|
pilhaEscoposExecucao: PilhaEscoposExecucaoInterface;
|
|
31
32
|
microLexador: MicroLexador;
|
|
32
33
|
microAvaliadorSintatico: MicroAvaliadorSintatico;
|
|
@@ -19,6 +19,8 @@ const metodo_primitiva_1 = require("../estruturas/metodo-primitiva");
|
|
|
19
19
|
const primitivas_texto_1 = __importDefault(require("../bibliotecas/primitivas-texto"));
|
|
20
20
|
const primitivas_vetor_1 = __importDefault(require("../bibliotecas/primitivas-vetor"));
|
|
21
21
|
const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
22
|
+
const primitivos_1 = __importDefault(require("../tipos-de-dados/primitivos"));
|
|
23
|
+
const delegua_2 = __importDefault(require("../tipos-de-dados/delegua"));
|
|
22
24
|
/**
|
|
23
25
|
* O Interpretador visita todos os elementos complexos gerados pelo avaliador sintático (_parser_),
|
|
24
26
|
* e de fato executa a lógica de programação descrita no código.
|
|
@@ -33,6 +35,7 @@ class InterpretadorBase {
|
|
|
33
35
|
this.funcaoDeRetornoMesmaLinha = null;
|
|
34
36
|
this.interfaceDeEntrada = null; // Originalmente é `readline.Interface`
|
|
35
37
|
this.interfaceEntradaSaida = null;
|
|
38
|
+
this.emDeclaracaoTente = false;
|
|
36
39
|
this.microLexador = new micro_lexador_1.MicroLexador();
|
|
37
40
|
this.microAvaliadorSintatico = new micro_avaliador_sintatico_1.MicroAvaliadorSintatico();
|
|
38
41
|
this.regexInterpolacao = /\${(.*?)}/g;
|
|
@@ -61,8 +64,8 @@ class InterpretadorBase {
|
|
|
61
64
|
//https://stackoverflow.com/a/66751666/9043143
|
|
62
65
|
textoParaRegex(texto) {
|
|
63
66
|
const match = texto.match(/^([\/~@;%#'])(.*?)\1([gimsuy]*)$/);
|
|
64
|
-
return match
|
|
65
|
-
new RegExp(match[2], match[3]
|
|
67
|
+
return match
|
|
68
|
+
? new RegExp(match[2], match[3]
|
|
66
69
|
.split('')
|
|
67
70
|
.filter((char, pos, flagArr) => flagArr.indexOf(char) === pos)
|
|
68
71
|
.join(''))
|
|
@@ -122,12 +125,25 @@ class InterpretadorBase {
|
|
|
122
125
|
* @returns Promise com o resultado da leitura.
|
|
123
126
|
*/
|
|
124
127
|
async visitarExpressaoLeiaMultiplo(expressao) {
|
|
125
|
-
const mensagem =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
const mensagem = '> ';
|
|
129
|
+
if (expressao.argumento instanceof construtos_1.Literal) {
|
|
130
|
+
let valor = expressao.argumento.valor;
|
|
131
|
+
if (typeof valor === primitivos_1.default.TEXTO) {
|
|
132
|
+
return new Promise((resolucao) => this.interfaceEntradaSaida.question(mensagem, (resposta) => {
|
|
133
|
+
resolucao(String(resposta)
|
|
134
|
+
.split(valor)
|
|
135
|
+
.filter((r) => !/(\s+)/.test(r)));
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
let respostas = [];
|
|
139
|
+
for (let i = 0; i < valor; i++) {
|
|
140
|
+
this.interfaceEntradaSaida.question(mensagem, (resposta) => {
|
|
141
|
+
respostas.push(resposta);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return Promise.resolve(respostas);
|
|
145
|
+
}
|
|
146
|
+
return Promise.resolve();
|
|
131
147
|
}
|
|
132
148
|
/**
|
|
133
149
|
* Retira a interpolação de um texto.
|
|
@@ -139,7 +155,7 @@ class InterpretadorBase {
|
|
|
139
155
|
let textoFinal = texto;
|
|
140
156
|
variaveis.forEach((elemento) => {
|
|
141
157
|
var _a, _b, _c;
|
|
142
|
-
if (((_a = elemento === null || elemento === void 0 ? void 0 : elemento.valor) === null || _a === void 0 ? void 0 : _a.tipo) ===
|
|
158
|
+
if (((_a = elemento === null || elemento === void 0 ? void 0 : elemento.valor) === null || _a === void 0 ? void 0 : _a.tipo) === delegua_2.default.LOGICO) {
|
|
143
159
|
textoFinal = textoFinal.replace('${' + elemento.variavel + '}', this.paraTexto((_b = elemento === null || elemento === void 0 ? void 0 : elemento.valor) === null || _b === void 0 ? void 0 : _b.valor));
|
|
144
160
|
}
|
|
145
161
|
else {
|
|
@@ -186,7 +202,7 @@ class InterpretadorBase {
|
|
|
186
202
|
eVerdadeiro(objeto) {
|
|
187
203
|
if (objeto === null)
|
|
188
204
|
return false;
|
|
189
|
-
if (typeof objeto ===
|
|
205
|
+
if (typeof objeto === primitivos_1.default.BOOLEANO)
|
|
190
206
|
return Boolean(objeto);
|
|
191
207
|
if (objeto.hasOwnProperty('valor')) {
|
|
192
208
|
return Boolean(objeto.valor);
|
|
@@ -194,7 +210,7 @@ class InterpretadorBase {
|
|
|
194
210
|
return true;
|
|
195
211
|
}
|
|
196
212
|
verificarOperandoNumero(operador, operando) {
|
|
197
|
-
if (typeof operando ===
|
|
213
|
+
if (typeof operando === primitivos_1.default.NUMERO || operando.tipo === delegua_2.default.NUMERO)
|
|
198
214
|
return;
|
|
199
215
|
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operando precisa ser um número.', Number(operador.linha));
|
|
200
216
|
}
|
|
@@ -244,7 +260,7 @@ class InterpretadorBase {
|
|
|
244
260
|
const valorConteudo = (conteudo === null || conteudo === void 0 ? void 0 : conteudo.hasOwnProperty('valor')) ? conteudo.valor : conteudo;
|
|
245
261
|
const tipoConteudo = conteudo.hasOwnProperty('tipo') ? conteudo.tipo : typeof conteudo;
|
|
246
262
|
resultado = valorConteudo;
|
|
247
|
-
if ([
|
|
263
|
+
if ([delegua_2.default.NUMERO, primitivos_1.default.NUMERO].includes(tipoConteudo) && declaracao.casasDecimais > 0) {
|
|
248
264
|
resultado = valorConteudo.toLocaleString('pt', { maximumFractionDigits: declaracao.casasDecimais });
|
|
249
265
|
}
|
|
250
266
|
if (declaracao.espacos > 0) {
|
|
@@ -268,117 +284,105 @@ class InterpretadorBase {
|
|
|
268
284
|
* @returns Se ambos os operandos são números ou não.
|
|
269
285
|
*/
|
|
270
286
|
verificarOperandosNumeros(operador, direita, esquerda) {
|
|
271
|
-
const tipoDireita = direita.tipo ? direita.tipo : typeof direita ===
|
|
287
|
+
const tipoDireita = direita.tipo ? direita.tipo : typeof direita === primitivos_1.default.NUMERO ? delegua_2.default.NUMERO : String(NaN);
|
|
272
288
|
const tipoEsquerda = esquerda.tipo
|
|
273
289
|
? esquerda.tipo
|
|
274
|
-
: typeof esquerda ===
|
|
275
|
-
?
|
|
290
|
+
: typeof esquerda === primitivos_1.default.NUMERO
|
|
291
|
+
? delegua_2.default.NUMERO
|
|
276
292
|
: String(NaN);
|
|
277
|
-
if (tipoDireita ===
|
|
293
|
+
if (tipoDireita === delegua_2.default.NUMERO && tipoEsquerda === delegua_2.default.NUMERO)
|
|
278
294
|
return;
|
|
279
295
|
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
|
|
280
296
|
}
|
|
281
297
|
async visitarExpressaoBinaria(expressao) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return Number(valorEsquerdo)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
298
|
+
const esquerda = await this.avaliar(expressao.esquerda);
|
|
299
|
+
const direita = await this.avaliar(expressao.direita);
|
|
300
|
+
const valorEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('valor')) ? esquerda.valor : esquerda;
|
|
301
|
+
const valorDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('valor')) ? direita.valor : direita;
|
|
302
|
+
const tipoEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('tipo')) ? esquerda.tipo : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
|
|
303
|
+
const tipoDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('tipo')) ? direita.tipo : (0, inferenciador_1.inferirTipoVariavel)(direita);
|
|
304
|
+
switch (expressao.operador.tipo) {
|
|
305
|
+
case delegua_1.default.EXPONENCIACAO:
|
|
306
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
307
|
+
return Math.pow(valorEsquerdo, valorDireito);
|
|
308
|
+
case delegua_1.default.MAIOR:
|
|
309
|
+
if (tipoEsquerdo === delegua_2.default.NUMERO && tipoDireito === delegua_2.default.NUMERO) {
|
|
310
|
+
return Number(valorEsquerdo) > Number(valorDireito);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
return String(valorEsquerdo) > String(valorDireito);
|
|
314
|
+
}
|
|
315
|
+
case delegua_1.default.MAIOR_IGUAL:
|
|
316
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
317
|
+
return Number(valorEsquerdo) >= Number(valorDireito);
|
|
318
|
+
case delegua_1.default.MENOR:
|
|
319
|
+
if (tipoEsquerdo === delegua_2.default.NUMERO && tipoDireito === delegua_2.default.NUMERO) {
|
|
320
|
+
return Number(valorEsquerdo) < Number(valorDireito);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
return String(valorEsquerdo) < String(valorDireito);
|
|
324
|
+
}
|
|
325
|
+
case delegua_1.default.MENOR_IGUAL:
|
|
326
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
327
|
+
return Number(valorEsquerdo) <= Number(valorDireito);
|
|
328
|
+
case delegua_1.default.SUBTRACAO:
|
|
329
|
+
case delegua_1.default.MENOS_IGUAL:
|
|
330
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
331
|
+
return Number(valorEsquerdo) - Number(valorDireito);
|
|
332
|
+
case delegua_1.default.ADICAO:
|
|
333
|
+
case delegua_1.default.MAIS_IGUAL:
|
|
334
|
+
if ([delegua_2.default.NUMERO, delegua_2.default.INTEIRO].includes(tipoEsquerdo) && [delegua_2.default.NUMERO, delegua_2.default.INTEIRO].includes(tipoDireito)) {
|
|
335
|
+
return Number(valorEsquerdo) + Number(valorDireito);
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
return String(valorEsquerdo) + String(valorDireito);
|
|
339
|
+
}
|
|
340
|
+
case delegua_1.default.DIVISAO:
|
|
341
|
+
case delegua_1.default.DIVISAO_IGUAL:
|
|
342
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
343
|
+
return Number(valorEsquerdo) / Number(valorDireito);
|
|
344
|
+
case delegua_1.default.DIVISAO_INTEIRA:
|
|
345
|
+
case delegua_1.default.DIVISAO_INTEIRA_IGUAL:
|
|
346
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
347
|
+
return Math.floor(Number(valorEsquerdo) / Number(valorDireito));
|
|
348
|
+
case delegua_1.default.MULTIPLICACAO:
|
|
349
|
+
case delegua_1.default.MULTIPLICACAO_IGUAL:
|
|
350
|
+
if (tipoEsquerdo === delegua_2.default.TEXTO || tipoDireito === delegua_2.default.TEXTO) {
|
|
351
|
+
// Sem ambos os valores resolvem como texto, multiplica normal.
|
|
352
|
+
// Se apenas um resolve como texto, o outro repete o
|
|
353
|
+
// texto n vezes, sendo n o valor do outro.
|
|
354
|
+
if (tipoEsquerdo === delegua_2.default.TEXTO && tipoDireito === delegua_2.default.TEXTO) {
|
|
355
|
+
return Number(valorEsquerdo) * Number(valorDireito);
|
|
326
356
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
330
|
-
return Number(valorEsquerdo) / Number(valorDireito);
|
|
331
|
-
case delegua_1.default.DIVISAO_INTEIRA:
|
|
332
|
-
case delegua_1.default.DIVISAO_INTEIRA_IGUAL:
|
|
333
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
334
|
-
return Math.floor(Number(valorEsquerdo) / Number(valorDireito));
|
|
335
|
-
case delegua_1.default.MULTIPLICACAO:
|
|
336
|
-
case delegua_1.default.MULTIPLICACAO_IGUAL:
|
|
337
|
-
if (tipoEsquerdo === 'texto' || tipoDireito === 'texto') {
|
|
338
|
-
// Sem ambos os valores resolvem como texto, multiplica normal.
|
|
339
|
-
// Se apenas um resolve como texto, o outro repete o
|
|
340
|
-
// texto n vezes, sendo n o valor do outro.
|
|
341
|
-
if (tipoEsquerdo === 'texto' && tipoDireito === 'texto') {
|
|
342
|
-
return Number(valorEsquerdo) * Number(valorDireito);
|
|
343
|
-
}
|
|
344
|
-
if (tipoEsquerdo === 'texto') {
|
|
345
|
-
return valorEsquerdo.repeat(Number(valorDireito));
|
|
346
|
-
}
|
|
347
|
-
return valorDireito.repeat(Number(valorEsquerdo));
|
|
357
|
+
if (tipoEsquerdo === delegua_2.default.TEXTO) {
|
|
358
|
+
return valorEsquerdo.repeat(Number(valorDireito));
|
|
348
359
|
}
|
|
349
|
-
return Number(valorEsquerdo)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
catch (erro) {
|
|
376
|
-
this.erros.push({
|
|
377
|
-
erroInterno: erro,
|
|
378
|
-
linha: expressao.linha,
|
|
379
|
-
hashArquivo: expressao.hashArquivo,
|
|
380
|
-
});
|
|
381
|
-
return Promise.reject(erro);
|
|
360
|
+
return valorDireito.repeat(Number(valorEsquerdo));
|
|
361
|
+
}
|
|
362
|
+
return Number(valorEsquerdo) * Number(valorDireito);
|
|
363
|
+
case delegua_1.default.MODULO:
|
|
364
|
+
case delegua_1.default.MODULO_IGUAL:
|
|
365
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
366
|
+
return Number(valorEsquerdo) % Number(valorDireito);
|
|
367
|
+
case delegua_1.default.BIT_AND:
|
|
368
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
369
|
+
return Number(valorEsquerdo) & Number(valorDireito);
|
|
370
|
+
case delegua_1.default.BIT_XOR:
|
|
371
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
372
|
+
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
373
|
+
case delegua_1.default.BIT_OR:
|
|
374
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
375
|
+
return Number(valorEsquerdo) | Number(valorDireito);
|
|
376
|
+
case delegua_1.default.MENOR_MENOR:
|
|
377
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
378
|
+
return Number(valorEsquerdo) << Number(valorDireito);
|
|
379
|
+
case delegua_1.default.MAIOR_MAIOR:
|
|
380
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
381
|
+
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
382
|
+
case delegua_1.default.DIFERENTE:
|
|
383
|
+
return !this.eIgual(valorEsquerdo, valorDireito);
|
|
384
|
+
case delegua_1.default.IGUAL_IGUAL:
|
|
385
|
+
return this.eIgual(valorEsquerdo, valorDireito);
|
|
382
386
|
}
|
|
383
387
|
}
|
|
384
388
|
/**
|
|
@@ -456,7 +460,6 @@ class InterpretadorBase {
|
|
|
456
460
|
linha: expressao.linha,
|
|
457
461
|
hashArquivo: expressao.hashArquivo,
|
|
458
462
|
});
|
|
459
|
-
this.erros.push(erro);
|
|
460
463
|
}
|
|
461
464
|
}
|
|
462
465
|
if (entidadeChamada instanceof estruturas_1.Chamavel) {
|
|
@@ -465,7 +468,7 @@ class InterpretadorBase {
|
|
|
465
468
|
}
|
|
466
469
|
// A função chamada pode ser de uma biblioteca JavaScript.
|
|
467
470
|
// Neste caso apenas testamos se o tipo é uma função.
|
|
468
|
-
if (typeof entidadeChamada ===
|
|
471
|
+
if (typeof entidadeChamada === primitivos_1.default.FUNCAO) {
|
|
469
472
|
let objeto = null;
|
|
470
473
|
if (expressao.entidadeChamada.objeto) {
|
|
471
474
|
objeto = await this.avaliar(expressao.entidadeChamada.objeto);
|
|
@@ -475,13 +478,11 @@ class InterpretadorBase {
|
|
|
475
478
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha));
|
|
476
479
|
}
|
|
477
480
|
catch (erro) {
|
|
478
|
-
console.log(erro);
|
|
479
481
|
this.erros.push({
|
|
480
482
|
erroInterno: erro,
|
|
481
483
|
linha: expressao.linha,
|
|
482
484
|
hashArquivo: expressao.hashArquivo,
|
|
483
485
|
});
|
|
484
|
-
this.erros.push(erro);
|
|
485
486
|
}
|
|
486
487
|
}
|
|
487
488
|
/**
|
|
@@ -491,7 +492,7 @@ class InterpretadorBase {
|
|
|
491
492
|
*/
|
|
492
493
|
async visitarDeclaracaoDeAtribuicao(expressao) {
|
|
493
494
|
const valor = await this.avaliar(expressao.valor);
|
|
494
|
-
const valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor;
|
|
495
|
+
const valorResolvido = valor !== undefined && valor.hasOwnProperty('valor') ? valor.valor : valor;
|
|
495
496
|
this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valorResolvido);
|
|
496
497
|
return valorResolvido;
|
|
497
498
|
}
|
|
@@ -508,7 +509,7 @@ class InterpretadorBase {
|
|
|
508
509
|
const esquerda = await this.avaliar(expressao.esquerda);
|
|
509
510
|
if (expressao.operador.tipo === delegua_1.default.EM) {
|
|
510
511
|
const direita = await this.avaliar(expressao.direita);
|
|
511
|
-
if (Array.isArray(direita) || typeof direita ===
|
|
512
|
+
if (Array.isArray(direita) || typeof direita === primitivos_1.default.TEXTO) {
|
|
512
513
|
return direita.includes(esquerda);
|
|
513
514
|
}
|
|
514
515
|
else if (direita.constructor === Object) {
|
|
@@ -709,12 +710,11 @@ class InterpretadorBase {
|
|
|
709
710
|
async visitarDeclaracaoTente(declaracao) {
|
|
710
711
|
let valorRetorno;
|
|
711
712
|
try {
|
|
712
|
-
|
|
713
|
+
this.emDeclaracaoTente = true;
|
|
713
714
|
try {
|
|
714
715
|
valorRetorno = await this.executarBloco(declaracao.caminhoTente);
|
|
715
716
|
}
|
|
716
717
|
catch (erro) {
|
|
717
|
-
sucesso = false;
|
|
718
718
|
if (declaracao.caminhoPegue !== null) {
|
|
719
719
|
// `caminhoPegue` aqui pode ser um construto de função (se `pegue` tem parâmetros)
|
|
720
720
|
// ou um vetor de `Declaracao` (`pegue` sem parâmetros).
|
|
@@ -733,6 +733,7 @@ class InterpretadorBase {
|
|
|
733
733
|
finally {
|
|
734
734
|
if (declaracao.caminhoFinalmente !== null)
|
|
735
735
|
valorRetorno = await this.executarBloco(declaracao.caminhoFinalmente);
|
|
736
|
+
this.emDeclaracaoTente = false;
|
|
736
737
|
}
|
|
737
738
|
return valorRetorno;
|
|
738
739
|
}
|
|
@@ -934,7 +935,7 @@ class InterpretadorBase {
|
|
|
934
935
|
objeto instanceof estruturas_1.DeleguaModulo) {
|
|
935
936
|
return objeto[valorIndice] || null;
|
|
936
937
|
}
|
|
937
|
-
else if (typeof objeto ===
|
|
938
|
+
else if (typeof objeto === primitivos_1.default.TEXTO) {
|
|
938
939
|
if (!Number.isInteger(valorIndice)) {
|
|
939
940
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha));
|
|
940
941
|
}
|
|
@@ -1026,12 +1027,12 @@ class InterpretadorBase {
|
|
|
1026
1027
|
}
|
|
1027
1028
|
// Função tradicional do JavaScript.
|
|
1028
1029
|
// Normalmente executa quando uma biblioteca é importada.
|
|
1029
|
-
if (typeof objeto[expressao.simbolo.lexema] ===
|
|
1030
|
+
if (typeof objeto[expressao.simbolo.lexema] === primitivos_1.default.FUNCAO) {
|
|
1030
1031
|
return objeto[expressao.simbolo.lexema];
|
|
1031
1032
|
}
|
|
1032
1033
|
// Objeto tradicional do JavaScript.
|
|
1033
1034
|
// Normalmente executa quando uma biblioteca é importada.
|
|
1034
|
-
if (typeof objeto[expressao.simbolo.lexema] ===
|
|
1035
|
+
if (typeof objeto[expressao.simbolo.lexema] === primitivos_1.default.OBJETO) {
|
|
1035
1036
|
return objeto[expressao.simbolo.lexema];
|
|
1036
1037
|
}
|
|
1037
1038
|
if (objeto instanceof estruturas_1.DeleguaModulo) {
|
|
@@ -1042,7 +1043,7 @@ class InterpretadorBase {
|
|
|
1042
1043
|
tipoObjeto = (0, inferenciador_1.inferirTipoVariavel)(variavelObjeto);
|
|
1043
1044
|
}
|
|
1044
1045
|
switch (tipoObjeto) {
|
|
1045
|
-
case
|
|
1046
|
+
case delegua_2.default.TEXTO:
|
|
1046
1047
|
const metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema];
|
|
1047
1048
|
if (metodoDePrimitivaTexto) {
|
|
1048
1049
|
return new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaTexto);
|
|
@@ -1117,8 +1118,8 @@ class InterpretadorBase {
|
|
|
1117
1118
|
}
|
|
1118
1119
|
paraTexto(objeto) {
|
|
1119
1120
|
if (objeto === null || objeto === undefined)
|
|
1120
|
-
return
|
|
1121
|
-
if (typeof objeto ===
|
|
1121
|
+
return delegua_2.default.NULO;
|
|
1122
|
+
if (typeof objeto === primitivos_1.default.BOOLEANO) {
|
|
1122
1123
|
return objeto ? 'verdadeiro' : 'falso';
|
|
1123
1124
|
}
|
|
1124
1125
|
if (objeto instanceof Date) {
|
|
@@ -1132,7 +1133,10 @@ class InterpretadorBase {
|
|
|
1132
1133
|
return objeto;
|
|
1133
1134
|
if (objeto.valor instanceof estruturas_1.ObjetoPadrao)
|
|
1134
1135
|
return objeto.valor.paraTexto();
|
|
1135
|
-
|
|
1136
|
+
// TODO: Idealmente isso deveria devolver um texto estruturado representando o objeto.
|
|
1137
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse)
|
|
1138
|
+
return objeto.toString();
|
|
1139
|
+
if (typeof objeto === primitivos_1.default.OBJETO)
|
|
1136
1140
|
return JSON.stringify(objeto);
|
|
1137
1141
|
return objeto.toString();
|
|
1138
1142
|
}
|
|
@@ -1147,7 +1151,7 @@ class InterpretadorBase {
|
|
|
1147
1151
|
if (mostrarResultado) {
|
|
1148
1152
|
this.funcaoDeRetorno(this.paraTexto(resultado));
|
|
1149
1153
|
}
|
|
1150
|
-
if (resultado || typeof resultado ===
|
|
1154
|
+
if (resultado || typeof resultado === primitivos_1.default.BOOLEANO) {
|
|
1151
1155
|
this.resultadoInterpretador.push(this.paraTexto(resultado));
|
|
1152
1156
|
}
|
|
1153
1157
|
return resultado;
|
|
@@ -1173,11 +1177,13 @@ class InterpretadorBase {
|
|
|
1173
1177
|
}
|
|
1174
1178
|
catch (erro) {
|
|
1175
1179
|
const declaracaoAtual = ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual];
|
|
1176
|
-
this.
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1180
|
+
if (!this.emDeclaracaoTente) {
|
|
1181
|
+
this.erros.push({
|
|
1182
|
+
erroInterno: erro,
|
|
1183
|
+
linha: declaracaoAtual.linha,
|
|
1184
|
+
hashArquivo: declaracaoAtual.hashArquivo,
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1181
1187
|
return Promise.reject(erro);
|
|
1182
1188
|
}
|
|
1183
1189
|
finally {
|
|
@@ -1198,6 +1204,7 @@ class InterpretadorBase {
|
|
|
1198
1204
|
*/
|
|
1199
1205
|
async interpretar(declaracoes, manterAmbiente = false) {
|
|
1200
1206
|
this.erros = [];
|
|
1207
|
+
this.emDeclaracaoTente = false;
|
|
1201
1208
|
const escopoExecucao = {
|
|
1202
1209
|
declaracoes: declaracoes,
|
|
1203
1210
|
declaracaoAtual: 0,
|