@designliquido/delegua 0.35.2 → 0.35.3
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/analisador-semantico/analisador-semantico-base.d.ts +3 -0
- package/analisador-semantico/analisador-semantico-base.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico-base.js +10 -0
- package/analisador-semantico/analisador-semantico-base.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts +3 -3
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +236 -231
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/atribuir.d.ts +3 -1
- package/construtos/atribuir.d.ts.map +1 -1
- package/construtos/atribuir.js +7 -1
- package/construtos/atribuir.js.map +1 -1
- package/estruturas/delegua-funcao.js +1 -1
- package/estruturas/delegua-funcao.js.map +1 -1
- package/interfaces/pilha-escopos-execucao-interface.d.ts +1 -1
- package/interfaces/pilha-escopos-execucao-interface.d.ts.map +1 -1
- package/interpretador/interpretador-base.d.ts +1 -0
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +16 -10
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts.map +1 -1
- package/interpretador/pilha-escopos-execucao.js +16 -6
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/package.json +1 -1
- package/umd/delegua.js +276 -249
package/umd/delegua.js
CHANGED
|
@@ -230,14 +230,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
230
230
|
};
|
|
231
231
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
232
232
|
exports.AvaliadorSintatico = void 0;
|
|
233
|
-
const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
234
|
-
const delegua_2 = __importDefault(require("../tipos-de-dados/delegua"));
|
|
235
233
|
const browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime"));
|
|
234
|
+
const delegua_1 = __importDefault(require("../tipos-de-dados/delegua"));
|
|
235
|
+
const delegua_2 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
236
236
|
const construtos_1 = require("../construtos");
|
|
237
237
|
const erro_avaliador_sintatico_1 = require("./erro-avaliador-sintatico");
|
|
238
|
+
const tuplas_1 = require("../construtos/tuplas");
|
|
238
239
|
const declaracoes_1 = require("../declaracoes");
|
|
239
240
|
const lexador_1 = require("../lexador");
|
|
240
|
-
const tuplas_1 = require("../construtos/tuplas");
|
|
241
241
|
/**
|
|
242
242
|
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
243
243
|
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
@@ -273,13 +273,13 @@ class AvaliadorSintatico {
|
|
|
273
273
|
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
274
274
|
}
|
|
275
275
|
verificarDefinicaoTipoAtual() {
|
|
276
|
-
const tipos = [...Object.values(
|
|
276
|
+
const tipos = [...Object.values(delegua_1.default)];
|
|
277
277
|
const lexema = this.simboloAtual().lexema.toLowerCase();
|
|
278
278
|
const contemTipo = tipos.find((tipo) => tipo === lexema);
|
|
279
|
-
if (contemTipo && this.verificarTipoProximoSimbolo(
|
|
279
|
+
if (contemTipo && this.verificarTipoProximoSimbolo(delegua_2.default.COLCHETE_ESQUERDO)) {
|
|
280
280
|
const tiposVetores = ['inteiro[]', 'numero[]', 'número[]', 'qualquer[]', 'real[]', 'texto[]'];
|
|
281
281
|
this.avancarEDevolverAnterior();
|
|
282
|
-
if (!this.verificarTipoProximoSimbolo(
|
|
282
|
+
if (!this.verificarTipoProximoSimbolo(delegua_2.default.COLCHETE_DIREITO)) {
|
|
283
283
|
throw this.erro(this.simbolos[this.atual], "Esperado símbolo de fechamento do vetor ']'.");
|
|
284
284
|
}
|
|
285
285
|
const contemTipoVetor = tiposVetores.find((tipo) => tipo === `${lexema}[]`);
|
|
@@ -316,124 +316,124 @@ class AvaliadorSintatico {
|
|
|
316
316
|
const simboloAtual = this.simbolos[this.atual];
|
|
317
317
|
let valores = [];
|
|
318
318
|
switch (simboloAtual.tipo) {
|
|
319
|
-
case
|
|
319
|
+
case delegua_2.default.CHAVE_ESQUERDA:
|
|
320
320
|
this.avancarEDevolverAnterior();
|
|
321
321
|
const chaves = [];
|
|
322
322
|
valores = [];
|
|
323
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
323
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_DIREITA)) {
|
|
324
324
|
return new construtos_1.Dicionario(this.hashArquivo, Number(simboloAtual.linha), [], []);
|
|
325
325
|
}
|
|
326
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
326
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_DIREITA)) {
|
|
327
327
|
const chave = this.atribuir();
|
|
328
|
-
this.consumir(
|
|
328
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' entre chave e valor.");
|
|
329
329
|
const valor = this.atribuir();
|
|
330
330
|
chaves.push(chave);
|
|
331
331
|
valores.push(valor);
|
|
332
|
-
if (this.simbolos[this.atual].tipo !==
|
|
333
|
-
this.consumir(
|
|
332
|
+
if (this.simbolos[this.atual].tipo !== delegua_2.default.CHAVE_DIREITA) {
|
|
333
|
+
this.consumir(delegua_2.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
return new construtos_1.Dicionario(this.hashArquivo, Number(simboloAtual.linha), chaves, valores);
|
|
337
|
-
case
|
|
337
|
+
case delegua_2.default.COLCHETE_ESQUERDO:
|
|
338
338
|
this.avancarEDevolverAnterior();
|
|
339
339
|
valores = [];
|
|
340
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
340
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.COLCHETE_DIREITO)) {
|
|
341
341
|
return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), []);
|
|
342
342
|
}
|
|
343
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
343
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.COLCHETE_DIREITO)) {
|
|
344
344
|
let valor = null;
|
|
345
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
345
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO)) {
|
|
346
346
|
const expressao = this.expressao();
|
|
347
347
|
const argumentos = [expressao];
|
|
348
|
-
while (this.simbolos[this.atual].tipo ===
|
|
348
|
+
while (this.simbolos[this.atual].tipo === delegua_2.default.VIRGULA) {
|
|
349
349
|
this.avancarEDevolverAnterior();
|
|
350
350
|
argumentos.push(this.expressao());
|
|
351
351
|
}
|
|
352
|
-
this.consumir(
|
|
353
|
-
this.consumir(
|
|
352
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
353
|
+
this.consumir(delegua_2.default.COLCHETE_DIREITO, "Esperado ']' após a expressão.");
|
|
354
354
|
return new tuplas_1.SeletorTuplas(...argumentos);
|
|
355
355
|
}
|
|
356
356
|
valor = this.atribuir();
|
|
357
357
|
valores.push(valor);
|
|
358
|
-
if (this.simbolos[this.atual].tipo !==
|
|
359
|
-
this.consumir(
|
|
358
|
+
if (this.simbolos[this.atual].tipo !== delegua_2.default.COLCHETE_DIREITO) {
|
|
359
|
+
this.consumir(delegua_2.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), valores);
|
|
363
|
-
case
|
|
363
|
+
case delegua_2.default.FALSO:
|
|
364
364
|
this.avancarEDevolverAnterior();
|
|
365
365
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), false);
|
|
366
|
-
case
|
|
367
|
-
case
|
|
366
|
+
case delegua_2.default.FUNCAO:
|
|
367
|
+
case delegua_2.default.FUNÇÃO:
|
|
368
368
|
const simboloFuncao = this.avancarEDevolverAnterior();
|
|
369
369
|
return this.corpoDaFuncao(simboloFuncao.lexema);
|
|
370
|
-
case
|
|
370
|
+
case delegua_2.default.IDENTIFICADOR:
|
|
371
371
|
const simboloIdentificador = this.avancarEDevolverAnterior();
|
|
372
372
|
// Se o próximo símbolo é um incremento ou um decremento,
|
|
373
373
|
// aqui deve retornar um unário correspondente.
|
|
374
374
|
// Caso contrário, apenas retornar um construto de variável.
|
|
375
375
|
if (this.simbolos[this.atual] &&
|
|
376
|
-
[
|
|
376
|
+
[delegua_2.default.INCREMENTAR, delegua_2.default.DECREMENTAR].includes(this.simbolos[this.atual].tipo)) {
|
|
377
377
|
const simboloIncrementoDecremento = this.avancarEDevolverAnterior();
|
|
378
378
|
return new construtos_1.Unario(this.hashArquivo, simboloIncrementoDecremento, new construtos_1.Variavel(this.hashArquivo, simboloIdentificador), 'DEPOIS');
|
|
379
379
|
}
|
|
380
380
|
return new construtos_1.Variavel(this.hashArquivo, simboloIdentificador);
|
|
381
|
-
case
|
|
381
|
+
case delegua_2.default.IMPORTAR:
|
|
382
382
|
this.avancarEDevolverAnterior();
|
|
383
383
|
return this.declaracaoImportar();
|
|
384
|
-
case
|
|
384
|
+
case delegua_2.default.ISTO:
|
|
385
385
|
this.avancarEDevolverAnterior();
|
|
386
386
|
return new construtos_1.Isto(this.hashArquivo, Number(simboloAtual.linha), simboloAtual);
|
|
387
|
-
case
|
|
387
|
+
case delegua_2.default.NULO:
|
|
388
388
|
this.avancarEDevolverAnterior();
|
|
389
389
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), null);
|
|
390
|
-
case
|
|
391
|
-
case
|
|
390
|
+
case delegua_2.default.NUMERO:
|
|
391
|
+
case delegua_2.default.TEXTO:
|
|
392
392
|
const simboloNumeroTexto = this.avancarEDevolverAnterior();
|
|
393
393
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloNumeroTexto.linha), simboloNumeroTexto.literal);
|
|
394
|
-
case
|
|
394
|
+
case delegua_2.default.PARENTESE_ESQUERDO:
|
|
395
395
|
this.avancarEDevolverAnterior();
|
|
396
396
|
const expressao = this.expressao();
|
|
397
|
-
this.consumir(
|
|
397
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
398
398
|
return new construtos_1.Agrupamento(this.hashArquivo, Number(simboloAtual.linha), expressao);
|
|
399
|
-
case
|
|
399
|
+
case delegua_2.default.SUPER:
|
|
400
400
|
const simboloSuper = this.avancarEDevolverAnterior();
|
|
401
401
|
// Se o próximo símbolo for uma abertura de parênteses, significa que
|
|
402
402
|
// é uma chamada ao construtor da classe ancestral (superclasse).
|
|
403
403
|
// Se o próximo símbolo for um ponto, significa que é uma chamada
|
|
404
404
|
// a um método da superclasse.
|
|
405
405
|
switch (this.simbolos[this.atual].tipo) {
|
|
406
|
-
case
|
|
407
|
-
return new construtos_1.Super(this.hashArquivo, simboloSuper, new lexador_1.Simbolo(
|
|
406
|
+
case delegua_2.default.PARENTESE_ESQUERDO:
|
|
407
|
+
return new construtos_1.Super(this.hashArquivo, simboloSuper, new lexador_1.Simbolo(delegua_2.default.IDENTIFICADOR, 'construtor', null, simboloSuper.linha, this.hashArquivo));
|
|
408
408
|
default:
|
|
409
|
-
this.consumir(
|
|
410
|
-
const metodoSuperclasse = this.consumir(
|
|
409
|
+
this.consumir(delegua_2.default.PONTO, "Esperado '.' após 'super'.");
|
|
410
|
+
const metodoSuperclasse = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome do método da Superclasse.');
|
|
411
411
|
return new construtos_1.Super(this.hashArquivo, simboloSuper, metodoSuperclasse);
|
|
412
412
|
}
|
|
413
|
-
case
|
|
413
|
+
case delegua_2.default.VERDADEIRO:
|
|
414
414
|
this.avancarEDevolverAnterior();
|
|
415
415
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), true);
|
|
416
|
-
case
|
|
416
|
+
case delegua_2.default.TIPO:
|
|
417
417
|
this.avancarEDevolverAnterior();
|
|
418
|
-
this.consumir(
|
|
418
|
+
this.consumir(delegua_2.default.DE, "Esperado 'de' após 'tipo'.");
|
|
419
419
|
let _expressao;
|
|
420
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
420
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.ESCREVA, delegua_2.default.LEIA, delegua_2.default.FUNCAO, delegua_2.default.FUNÇÃO, delegua_2.default.SE, delegua_2.default.ENQUANTO, delegua_2.default.PARA, delegua_2.default.RETORNA, delegua_1.default.INTEIRO, delegua_1.default.TEXTO, delegua_1.default.VETOR, delegua_1.default.LOGICO, delegua_1.default.LÓGICO, delegua_1.default.VAZIO)) {
|
|
421
421
|
_expressao = this.simboloAnterior();
|
|
422
422
|
}
|
|
423
423
|
else {
|
|
424
424
|
_expressao = this.expressao();
|
|
425
425
|
}
|
|
426
426
|
return new construtos_1.TipoDe(this.hashArquivo, simboloAtual, _expressao instanceof construtos_1.Literal ? _expressao.valor : _expressao);
|
|
427
|
-
case
|
|
427
|
+
case delegua_2.default.EXPRESSAO_REGULAR:
|
|
428
428
|
let valor = '';
|
|
429
429
|
let linhaAtual = this.simbolos[this.atual].linha;
|
|
430
|
-
let eParExpressaoRegular = this.simbolos.filter((l) => l.linha === linhaAtual && l.tipo ===
|
|
430
|
+
let eParExpressaoRegular = this.simbolos.filter((l) => l.linha === linhaAtual && l.tipo === delegua_2.default.EXPRESSAO_REGULAR)
|
|
431
431
|
.length %
|
|
432
432
|
2 ===
|
|
433
433
|
0;
|
|
434
434
|
if (eParExpressaoRegular) {
|
|
435
435
|
this.avancarEDevolverAnterior();
|
|
436
|
-
while (!this.verificarTipoSimboloAtual(
|
|
436
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.EXPRESSAO_REGULAR)) {
|
|
437
437
|
valor += this.simboloAtual().lexema || '';
|
|
438
438
|
this.avancarEDevolverAnterior();
|
|
439
439
|
}
|
|
@@ -445,30 +445,30 @@ class AvaliadorSintatico {
|
|
|
445
445
|
}
|
|
446
446
|
finalizarChamada(entidadeChamada) {
|
|
447
447
|
const argumentos = [];
|
|
448
|
-
if (!this.verificarTipoSimboloAtual(
|
|
448
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
449
449
|
do {
|
|
450
450
|
if (argumentos.length >= 255) {
|
|
451
451
|
throw this.erro(this.simbolos[this.atual], 'Não pode haver mais de 255 argumentos.');
|
|
452
452
|
}
|
|
453
453
|
argumentos.push(this.expressao());
|
|
454
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
454
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
455
455
|
}
|
|
456
|
-
const parenteseDireito = this.consumir(
|
|
456
|
+
const parenteseDireito = this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos.");
|
|
457
457
|
return new construtos_1.Chamada(this.hashArquivo, entidadeChamada, parenteseDireito, argumentos);
|
|
458
458
|
}
|
|
459
459
|
chamar() {
|
|
460
460
|
let expressao = this.primario();
|
|
461
461
|
while (true) {
|
|
462
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
462
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO)) {
|
|
463
463
|
expressao = this.finalizarChamada(expressao);
|
|
464
464
|
}
|
|
465
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
466
|
-
const nome = this.consumir(
|
|
465
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO)) {
|
|
466
|
+
const nome = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado nome de método ou propriedade após '.'.");
|
|
467
467
|
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
468
468
|
}
|
|
469
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
469
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.COLCHETE_ESQUERDO)) {
|
|
470
470
|
const indice = this.expressao();
|
|
471
|
-
const simboloFechamento = this.consumir(
|
|
471
|
+
const simboloFechamento = this.consumir(delegua_2.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
472
472
|
expressao = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, expressao, indice, simboloFechamento);
|
|
473
473
|
}
|
|
474
474
|
else {
|
|
@@ -478,7 +478,7 @@ class AvaliadorSintatico {
|
|
|
478
478
|
return expressao;
|
|
479
479
|
}
|
|
480
480
|
unario() {
|
|
481
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
481
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.NEGACAO, delegua_2.default.SUBTRACAO, delegua_2.default.BIT_NOT, delegua_2.default.INCREMENTAR, delegua_2.default.DECREMENTAR)) {
|
|
482
482
|
const operador = this.simbolos[this.atual - 1];
|
|
483
483
|
const direito = this.unario();
|
|
484
484
|
return new construtos_1.Unario(this.hashArquivo, operador, direito, 'ANTES');
|
|
@@ -487,7 +487,7 @@ class AvaliadorSintatico {
|
|
|
487
487
|
}
|
|
488
488
|
exponenciacao() {
|
|
489
489
|
let expressao = this.unario();
|
|
490
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
490
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.EXPONENCIACAO)) {
|
|
491
491
|
const operador = this.simbolos[this.atual - 1];
|
|
492
492
|
const direito = this.unario();
|
|
493
493
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -496,7 +496,7 @@ class AvaliadorSintatico {
|
|
|
496
496
|
}
|
|
497
497
|
multiplicar() {
|
|
498
498
|
let expressao = this.exponenciacao();
|
|
499
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
499
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DIVISAO, delegua_2.default.DIVISAO_IGUAL, delegua_2.default.DIVISAO_INTEIRA, delegua_2.default.DIVISAO_INTEIRA_IGUAL, delegua_2.default.MODULO, delegua_2.default.MODULO_IGUAL, delegua_2.default.MULTIPLICACAO, delegua_2.default.MULTIPLICACAO_IGUAL)) {
|
|
500
500
|
const operador = this.simbolos[this.atual - 1];
|
|
501
501
|
const direito = this.exponenciacao();
|
|
502
502
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -510,7 +510,7 @@ class AvaliadorSintatico {
|
|
|
510
510
|
*/
|
|
511
511
|
adicaoOuSubtracao() {
|
|
512
512
|
let expressao = this.multiplicar();
|
|
513
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
513
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SUBTRACAO, delegua_2.default.ADICAO, delegua_2.default.MAIS_IGUAL, delegua_2.default.MENOS_IGUAL)) {
|
|
514
514
|
const operador = this.simbolos[this.atual - 1];
|
|
515
515
|
const direito = this.multiplicar();
|
|
516
516
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -519,7 +519,7 @@ class AvaliadorSintatico {
|
|
|
519
519
|
}
|
|
520
520
|
bitShift() {
|
|
521
521
|
let expressao = this.adicaoOuSubtracao();
|
|
522
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
522
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.MENOR_MENOR, delegua_2.default.MAIOR_MAIOR)) {
|
|
523
523
|
const operador = this.simbolos[this.atual - 1];
|
|
524
524
|
const direito = this.adicaoOuSubtracao();
|
|
525
525
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -528,7 +528,7 @@ class AvaliadorSintatico {
|
|
|
528
528
|
}
|
|
529
529
|
bitE() {
|
|
530
530
|
let expressao = this.bitShift();
|
|
531
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
531
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.BIT_AND)) {
|
|
532
532
|
const operador = this.simbolos[this.atual - 1];
|
|
533
533
|
const direito = this.bitShift();
|
|
534
534
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -537,7 +537,7 @@ class AvaliadorSintatico {
|
|
|
537
537
|
}
|
|
538
538
|
bitOu() {
|
|
539
539
|
let expressao = this.bitE();
|
|
540
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
540
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.BIT_OR, delegua_2.default.BIT_XOR)) {
|
|
541
541
|
const operador = this.simbolos[this.atual - 1];
|
|
542
542
|
const direito = this.bitE();
|
|
543
543
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -546,7 +546,7 @@ class AvaliadorSintatico {
|
|
|
546
546
|
}
|
|
547
547
|
comparar() {
|
|
548
548
|
let expressao = this.bitOu();
|
|
549
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
549
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.MAIOR, delegua_2.default.MAIOR_IGUAL, delegua_2.default.MENOR, delegua_2.default.MENOR_IGUAL)) {
|
|
550
550
|
const operador = this.simbolos[this.atual - 1];
|
|
551
551
|
const direito = this.bitOu();
|
|
552
552
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -555,7 +555,7 @@ class AvaliadorSintatico {
|
|
|
555
555
|
}
|
|
556
556
|
comparacaoIgualdade() {
|
|
557
557
|
let expressao = this.comparar();
|
|
558
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
558
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DIFERENTE, delegua_2.default.IGUAL_IGUAL)) {
|
|
559
559
|
const operador = this.simbolos[this.atual - 1];
|
|
560
560
|
const direito = this.comparar();
|
|
561
561
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -564,7 +564,7 @@ class AvaliadorSintatico {
|
|
|
564
564
|
}
|
|
565
565
|
em() {
|
|
566
566
|
let expressao = this.comparacaoIgualdade();
|
|
567
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
567
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.EM)) {
|
|
568
568
|
const operador = this.simbolos[this.atual - 1];
|
|
569
569
|
const direito = this.comparacaoIgualdade();
|
|
570
570
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
@@ -573,7 +573,7 @@ class AvaliadorSintatico {
|
|
|
573
573
|
}
|
|
574
574
|
e() {
|
|
575
575
|
let expressao = this.em();
|
|
576
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
576
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.E)) {
|
|
577
577
|
const operador = this.simbolos[this.atual - 1];
|
|
578
578
|
const direito = this.em();
|
|
579
579
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
@@ -582,7 +582,7 @@ class AvaliadorSintatico {
|
|
|
582
582
|
}
|
|
583
583
|
ou() {
|
|
584
584
|
let expressao = this.e();
|
|
585
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
585
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.OU)) {
|
|
586
586
|
const operador = this.simbolos[this.atual - 1];
|
|
587
587
|
const direito = this.e();
|
|
588
588
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
@@ -597,16 +597,21 @@ class AvaliadorSintatico {
|
|
|
597
597
|
const expressao = this.ou();
|
|
598
598
|
if (expressao instanceof construtos_1.Binario &&
|
|
599
599
|
[
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
600
|
+
delegua_2.default.MAIS_IGUAL,
|
|
601
|
+
delegua_2.default.MENOS_IGUAL,
|
|
602
|
+
delegua_2.default.MULTIPLICACAO_IGUAL,
|
|
603
|
+
delegua_2.default.DIVISAO_IGUAL,
|
|
604
|
+
delegua_2.default.DIVISAO_INTEIRA_IGUAL,
|
|
605
|
+
delegua_2.default.MODULO_IGUAL,
|
|
606
606
|
].includes(expressao.operador.tipo)) {
|
|
607
|
-
|
|
607
|
+
let simbolo = expressao.esquerda.simbolo;
|
|
608
|
+
if (expressao.esquerda instanceof construtos_1.AcessoIndiceVariavel) {
|
|
609
|
+
simbolo = expressao.esquerda.entidadeChamada.simbolo;
|
|
610
|
+
return new construtos_1.Atribuir(this.hashArquivo, simbolo, expressao, expressao.esquerda.indice);
|
|
611
|
+
}
|
|
612
|
+
return new construtos_1.Atribuir(this.hashArquivo, simbolo, expressao);
|
|
608
613
|
}
|
|
609
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
614
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL)) {
|
|
610
615
|
const igual = this.simbolos[this.atual - 1];
|
|
611
616
|
const valor = this.expressao();
|
|
612
617
|
if (expressao instanceof construtos_1.Variavel) {
|
|
@@ -625,13 +630,13 @@ class AvaliadorSintatico {
|
|
|
625
630
|
return expressao;
|
|
626
631
|
}
|
|
627
632
|
expressao() {
|
|
628
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
633
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.LEIA))
|
|
629
634
|
return this.declaracaoLeia();
|
|
630
635
|
return this.atribuir();
|
|
631
636
|
}
|
|
632
637
|
blocoEscopo() {
|
|
633
638
|
let declaracoes = [];
|
|
634
|
-
while (!this.verificarTipoSimboloAtual(
|
|
639
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) && !this.estaNoFinal()) {
|
|
635
640
|
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
636
641
|
if (Array.isArray(retornoDeclaracao)) {
|
|
637
642
|
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
@@ -640,8 +645,8 @@ class AvaliadorSintatico {
|
|
|
640
645
|
declaracoes.push(retornoDeclaracao);
|
|
641
646
|
}
|
|
642
647
|
}
|
|
643
|
-
this.consumir(
|
|
644
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
648
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' após o bloco.");
|
|
649
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
645
650
|
return declaracoes;
|
|
646
651
|
}
|
|
647
652
|
declaracaoEnquanto() {
|
|
@@ -657,22 +662,22 @@ class AvaliadorSintatico {
|
|
|
657
662
|
}
|
|
658
663
|
declaracaoEscreva() {
|
|
659
664
|
const simboloAtual = this.simbolos[this.atual];
|
|
660
|
-
this.consumir(
|
|
665
|
+
this.consumir(delegua_2.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em escreva.");
|
|
661
666
|
const argumentos = [];
|
|
662
|
-
if (!this.verificarTipoSimboloAtual(
|
|
667
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
663
668
|
do {
|
|
664
669
|
argumentos.push(this.expressao());
|
|
665
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
670
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
666
671
|
}
|
|
667
|
-
this.consumir(
|
|
672
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após os valores em escreva.");
|
|
668
673
|
// Ponto-e-vírgula é opcional aqui.
|
|
669
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
674
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
670
675
|
return new declaracoes_1.Escreva(Number(simboloAtual.linha), simboloAtual.hashArquivo, argumentos);
|
|
671
676
|
}
|
|
672
677
|
declaracaoExpressao() {
|
|
673
678
|
const expressao = this.expressao();
|
|
674
679
|
// Ponto-e-vírgula é opcional aqui.
|
|
675
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
680
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
676
681
|
return new declaracoes_1.Expressao(expressao);
|
|
677
682
|
}
|
|
678
683
|
declaracaoComentarioMultilinha() {
|
|
@@ -681,7 +686,7 @@ class AvaliadorSintatico {
|
|
|
681
686
|
do {
|
|
682
687
|
simboloComentario = this.avancarEDevolverAnterior();
|
|
683
688
|
conteudos.push(simboloComentario.literal);
|
|
684
|
-
} while (simboloComentario.tipo ===
|
|
689
|
+
} while (simboloComentario.tipo === delegua_2.default.LINHA_COMENTARIO);
|
|
685
690
|
return new construtos_1.Comentario(simboloComentario.hashArquivo, simboloComentario.linha, conteudos, true);
|
|
686
691
|
}
|
|
687
692
|
declaracaoComentarioUmaLinha() {
|
|
@@ -693,24 +698,24 @@ class AvaliadorSintatico {
|
|
|
693
698
|
this.erro(this.simbolos[this.atual - 1], "'continua' precisa estar em um laço de repetição.");
|
|
694
699
|
}
|
|
695
700
|
// Ponto-e-vírgula é opcional aqui.
|
|
696
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
701
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
697
702
|
return new declaracoes_1.Continua(this.simbolos[this.atual - 1]);
|
|
698
703
|
}
|
|
699
704
|
declaracaoEscolha() {
|
|
700
705
|
try {
|
|
701
706
|
this.blocos += 1;
|
|
702
707
|
const condicao = this.expressao();
|
|
703
|
-
this.consumir(
|
|
708
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo do 'escolha'.");
|
|
704
709
|
const caminhos = [];
|
|
705
710
|
let caminhoPadrao = null;
|
|
706
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
707
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
711
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_DIREITA) && !this.estaNoFinal()) {
|
|
712
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CASO)) {
|
|
708
713
|
const caminhoCondicoes = [this.expressao()];
|
|
709
|
-
this.consumir(
|
|
710
|
-
while (this.verificarTipoSimboloAtual(
|
|
711
|
-
this.consumir(
|
|
714
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' após o 'caso'.");
|
|
715
|
+
while (this.verificarTipoSimboloAtual(delegua_2.default.CASO)) {
|
|
716
|
+
this.consumir(delegua_2.default.CASO, null);
|
|
712
717
|
caminhoCondicoes.push(this.expressao());
|
|
713
|
-
this.consumir(
|
|
718
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' após declaração do 'caso'.");
|
|
714
719
|
}
|
|
715
720
|
let declaracoes = [];
|
|
716
721
|
do {
|
|
@@ -721,27 +726,27 @@ class AvaliadorSintatico {
|
|
|
721
726
|
else {
|
|
722
727
|
declaracoes.push(retornoDeclaracao);
|
|
723
728
|
}
|
|
724
|
-
} while (!this.verificarTipoSimboloAtual(
|
|
725
|
-
!this.verificarTipoSimboloAtual(
|
|
726
|
-
!this.verificarTipoSimboloAtual(
|
|
729
|
+
} while (!this.verificarTipoSimboloAtual(delegua_2.default.CASO) &&
|
|
730
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.PADRAO) &&
|
|
731
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA));
|
|
727
732
|
caminhos.push({
|
|
728
733
|
condicoes: caminhoCondicoes,
|
|
729
734
|
declaracoes,
|
|
730
735
|
});
|
|
731
736
|
}
|
|
732
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
737
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PADRAO)) {
|
|
733
738
|
if (caminhoPadrao !== null) {
|
|
734
739
|
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.simbolos[this.atual], "Você só pode ter um 'padrao' em cada declaração de 'escolha'.");
|
|
735
740
|
this.erros.push(excecao);
|
|
736
741
|
throw excecao;
|
|
737
742
|
}
|
|
738
|
-
this.consumir(
|
|
743
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' após declaração do 'padrao'.");
|
|
739
744
|
const declaracoes = [];
|
|
740
745
|
do {
|
|
741
746
|
declaracoes.push(this.resolverDeclaracao());
|
|
742
|
-
} while (!this.verificarTipoSimboloAtual(
|
|
743
|
-
!this.verificarTipoSimboloAtual(
|
|
744
|
-
!this.verificarTipoSimboloAtual(
|
|
747
|
+
} while (!this.verificarTipoSimboloAtual(delegua_2.default.CASO) &&
|
|
748
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.PADRAO) &&
|
|
749
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA));
|
|
745
750
|
caminhoPadrao = {
|
|
746
751
|
declaracoes,
|
|
747
752
|
};
|
|
@@ -762,7 +767,7 @@ class AvaliadorSintatico {
|
|
|
762
767
|
try {
|
|
763
768
|
this.blocos += 1;
|
|
764
769
|
const caminhoFazer = this.resolverDeclaracao();
|
|
765
|
-
this.consumir(
|
|
770
|
+
this.consumir(delegua_2.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo do 'fazer'.");
|
|
766
771
|
const condicaoEnquanto = this.expressao();
|
|
767
772
|
return new declaracoes_1.Fazer(simboloFazer.hashArquivo, Number(simboloFazer.linha), caminhoFazer, condicaoEnquanto);
|
|
768
773
|
}
|
|
@@ -771,9 +776,9 @@ class AvaliadorSintatico {
|
|
|
771
776
|
}
|
|
772
777
|
}
|
|
773
778
|
declaracaoImportar() {
|
|
774
|
-
this.consumir(
|
|
779
|
+
this.consumir(delegua_2.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
|
|
775
780
|
const caminho = this.expressao();
|
|
776
|
-
const simboloFechamento = this.consumir(
|
|
781
|
+
const simboloFechamento = this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
777
782
|
return new declaracoes_1.Importar(caminho, simboloFechamento);
|
|
778
783
|
}
|
|
779
784
|
/**
|
|
@@ -782,21 +787,21 @@ class AvaliadorSintatico {
|
|
|
782
787
|
*/
|
|
783
788
|
declaracaoLeia() {
|
|
784
789
|
const simboloLeia = this.simbolos[this.atual];
|
|
785
|
-
this.consumir(
|
|
790
|
+
this.consumir(delegua_2.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos argumentos em instrução `leia`.");
|
|
786
791
|
const argumentos = [];
|
|
787
|
-
if (this.simbolos[this.atual].tipo !==
|
|
792
|
+
if (this.simbolos[this.atual].tipo !== delegua_2.default.PARENTESE_DIREITO) {
|
|
788
793
|
do {
|
|
789
794
|
argumentos.push(this.expressao());
|
|
790
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
795
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
791
796
|
}
|
|
792
|
-
this.consumir(
|
|
797
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos em instrução `leia`.");
|
|
793
798
|
return new declaracoes_1.Leia(simboloLeia, argumentos);
|
|
794
799
|
}
|
|
795
800
|
declaracaoPara() {
|
|
796
801
|
try {
|
|
797
802
|
const simboloPara = this.simbolos[this.atual - 1];
|
|
798
803
|
this.blocos += 1;
|
|
799
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
804
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CADA)) {
|
|
800
805
|
return this.declaracaoParaCada(simboloPara);
|
|
801
806
|
}
|
|
802
807
|
return this.declaracaoParaTradicional(simboloPara);
|
|
@@ -806,8 +811,8 @@ class AvaliadorSintatico {
|
|
|
806
811
|
}
|
|
807
812
|
}
|
|
808
813
|
declaracaoParaCada(simboloPara) {
|
|
809
|
-
const nomeVariavelIteracao = this.consumir(
|
|
810
|
-
if (!this.verificarSeSimboloAtualEIgualA(
|
|
814
|
+
const nomeVariavelIteracao = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado identificador de variável de iteração para instrução 'para cada'.");
|
|
815
|
+
if (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.DE, delegua_2.default.EM)) {
|
|
811
816
|
throw this.erro(this.simbolos[this.atual], "Esperado palavras reservadas 'em' ou 'de' após variável de iteração em instrução 'para cada'.");
|
|
812
817
|
}
|
|
813
818
|
const vetor = this.expressao();
|
|
@@ -815,33 +820,33 @@ class AvaliadorSintatico {
|
|
|
815
820
|
return new declaracoes_1.ParaCada(this.hashArquivo, Number(simboloPara.linha), nomeVariavelIteracao.lexema, vetor, corpo);
|
|
816
821
|
}
|
|
817
822
|
declaracaoParaTradicional(simboloPara) {
|
|
818
|
-
const comParenteses = this.verificarSeSimboloAtualEIgualA(
|
|
823
|
+
const comParenteses = this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO);
|
|
819
824
|
let inicializador;
|
|
820
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
825
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA)) {
|
|
821
826
|
inicializador = null;
|
|
822
827
|
}
|
|
823
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
828
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VARIAVEL)) {
|
|
824
829
|
inicializador = this.declaracaoDeVariaveis();
|
|
825
830
|
}
|
|
826
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
831
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CONSTANTE)) {
|
|
827
832
|
inicializador = this.declaracaoDeConstantes();
|
|
828
833
|
}
|
|
829
834
|
else {
|
|
830
835
|
inicializador = this.declaracaoExpressao();
|
|
831
836
|
}
|
|
832
837
|
let condicao = null;
|
|
833
|
-
if (!this.verificarTipoSimboloAtual(
|
|
838
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PONTO_E_VIRGULA)) {
|
|
834
839
|
condicao = this.expressao();
|
|
835
840
|
}
|
|
836
841
|
// Ponto-e-vírgula é opcional aqui.
|
|
837
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
842
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
838
843
|
let incrementar = null;
|
|
839
|
-
if (!this.verificarTipoSimboloAtual(
|
|
844
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
840
845
|
incrementar = this.expressao();
|
|
841
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
846
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.INCREMENTAR, delegua_2.default.DECREMENTAR);
|
|
842
847
|
}
|
|
843
848
|
if (comParenteses) {
|
|
844
|
-
this.consumir(
|
|
849
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após cláusulas de inicialização, condição e incremento.");
|
|
845
850
|
}
|
|
846
851
|
const corpo = this.resolverDeclaracao();
|
|
847
852
|
return new declaracoes_1.Para(this.hashArquivo, Number(simboloPara.linha), inicializador, condicao, incrementar, corpo);
|
|
@@ -850,30 +855,30 @@ class AvaliadorSintatico {
|
|
|
850
855
|
const simboloChave = this.simbolos[this.atual - 1];
|
|
851
856
|
let valor = null;
|
|
852
857
|
if ([
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
858
|
+
delegua_2.default.CHAVE_ESQUERDA,
|
|
859
|
+
delegua_2.default.COLCHETE_ESQUERDO,
|
|
860
|
+
delegua_2.default.FALSO,
|
|
861
|
+
delegua_2.default.IDENTIFICADOR,
|
|
862
|
+
delegua_2.default.ISTO,
|
|
863
|
+
delegua_2.default.NEGACAO,
|
|
864
|
+
delegua_2.default.NUMERO,
|
|
865
|
+
delegua_2.default.NULO,
|
|
866
|
+
delegua_2.default.PARENTESE_ESQUERDO,
|
|
867
|
+
delegua_2.default.SUPER,
|
|
868
|
+
delegua_2.default.TEXTO,
|
|
869
|
+
delegua_2.default.VERDADEIRO,
|
|
865
870
|
].includes(this.simbolos[this.atual].tipo)) {
|
|
866
871
|
valor = this.expressao();
|
|
867
872
|
}
|
|
868
873
|
// Ponto-e-vírgula é opcional aqui.
|
|
869
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
874
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
870
875
|
return new declaracoes_1.Retorna(simboloChave, valor);
|
|
871
876
|
}
|
|
872
877
|
declaracaoSe() {
|
|
873
878
|
const condicao = this.expressao();
|
|
874
879
|
const caminhoEntao = this.resolverDeclaracao();
|
|
875
880
|
let caminhoSenao = null;
|
|
876
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
881
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SENAO, delegua_2.default.SENÃO)) {
|
|
877
882
|
caminhoSenao = this.resolverDeclaracao();
|
|
878
883
|
}
|
|
879
884
|
return new declaracoes_1.Se(condicao, caminhoEntao, [], caminhoSenao);
|
|
@@ -883,16 +888,16 @@ class AvaliadorSintatico {
|
|
|
883
888
|
this.erro(this.simbolos[this.atual - 1], "'sustar' ou 'pausa' deve estar dentro de um laço de repetição.");
|
|
884
889
|
}
|
|
885
890
|
// Ponto-e-vírgula é opcional aqui.
|
|
886
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
891
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
887
892
|
return new declaracoes_1.Sustar(this.simbolos[this.atual - 1]);
|
|
888
893
|
}
|
|
889
894
|
declaracaoTente() {
|
|
890
895
|
const simboloTente = this.simbolos[this.atual - 1];
|
|
891
|
-
this.consumir(
|
|
896
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'tente'.");
|
|
892
897
|
const blocoTente = this.blocoEscopo();
|
|
893
898
|
let blocoPegue = null;
|
|
894
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
895
|
-
if (this.verificarTipoSimboloAtual(
|
|
899
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PEGUE)) {
|
|
900
|
+
if (this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_ESQUERDO)) {
|
|
896
901
|
// Caso 1: com parâmetro de erro.
|
|
897
902
|
// `pegue` recebe um `FuncaoConstruto`.
|
|
898
903
|
blocoPegue = this.corpoDaFuncao('bloco `pegue`');
|
|
@@ -900,25 +905,25 @@ class AvaliadorSintatico {
|
|
|
900
905
|
else {
|
|
901
906
|
// Caso 2: sem parâmetro de erro.
|
|
902
907
|
// `pegue` recebe um bloco.
|
|
903
|
-
this.consumir(
|
|
908
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
|
|
904
909
|
blocoPegue = this.blocoEscopo();
|
|
905
910
|
}
|
|
906
911
|
}
|
|
907
912
|
let blocoSenao = null;
|
|
908
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
909
|
-
this.consumir(
|
|
913
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SENAO, delegua_2.default.SENÃO)) {
|
|
914
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'senão'.");
|
|
910
915
|
blocoSenao = this.blocoEscopo();
|
|
911
916
|
}
|
|
912
917
|
let blocoFinalmente = null;
|
|
913
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
914
|
-
this.consumir(
|
|
918
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.FINALMENTE)) {
|
|
919
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'finalmente'.");
|
|
915
920
|
blocoFinalmente = this.blocoEscopo();
|
|
916
921
|
}
|
|
917
922
|
return new declaracoes_1.Tente(simboloTente.hashArquivo, Number(simboloTente.linha), blocoTente, blocoPegue, blocoSenao, blocoFinalmente);
|
|
918
923
|
}
|
|
919
924
|
resolverDecorador() {
|
|
920
925
|
this.pilhaDecoradores = [];
|
|
921
|
-
while (this.verificarTipoSimboloAtual(
|
|
926
|
+
while (this.verificarTipoSimboloAtual(delegua_2.default.ARROBA)) {
|
|
922
927
|
let nomeDecorador = '';
|
|
923
928
|
let linha;
|
|
924
929
|
let parametros = [];
|
|
@@ -926,12 +931,12 @@ class AvaliadorSintatico {
|
|
|
926
931
|
linha = this.simbolos[this.atual].linha;
|
|
927
932
|
let simbolosLinhaAtual = this.simbolos.filter((l) => l.linha === linha);
|
|
928
933
|
for (let simbolo of simbolosLinhaAtual) {
|
|
929
|
-
parenteseEsquerdo = this.verificarSeSimboloAtualEIgualA(
|
|
934
|
+
parenteseEsquerdo = this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO);
|
|
930
935
|
if (parenteseEsquerdo) {
|
|
931
|
-
if (!this.verificarTipoSimboloAtual(
|
|
936
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
932
937
|
parametros = this.logicaComumParametros();
|
|
933
938
|
}
|
|
934
|
-
this.consumir(
|
|
939
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
935
940
|
break;
|
|
936
941
|
}
|
|
937
942
|
this.avancarEDevolverAnterior();
|
|
@@ -950,65 +955,65 @@ class AvaliadorSintatico {
|
|
|
950
955
|
*/
|
|
951
956
|
resolverDeclaracao() {
|
|
952
957
|
switch (this.simbolos[this.atual].tipo) {
|
|
953
|
-
case
|
|
958
|
+
case delegua_2.default.CHAVE_ESQUERDA:
|
|
954
959
|
const simboloInicioBloco = this.avancarEDevolverAnterior();
|
|
955
960
|
return new declaracoes_1.Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
956
|
-
case
|
|
961
|
+
case delegua_2.default.COMENTARIO:
|
|
957
962
|
return this.declaracaoComentarioUmaLinha();
|
|
958
|
-
case
|
|
963
|
+
case delegua_2.default.CONSTANTE:
|
|
959
964
|
this.avancarEDevolverAnterior();
|
|
960
965
|
return this.declaracaoDeConstantes();
|
|
961
|
-
case
|
|
966
|
+
case delegua_2.default.CONTINUA:
|
|
962
967
|
this.avancarEDevolverAnterior();
|
|
963
968
|
return this.declaracaoContinua();
|
|
964
|
-
case
|
|
969
|
+
case delegua_2.default.ENQUANTO:
|
|
965
970
|
this.avancarEDevolverAnterior();
|
|
966
971
|
return this.declaracaoEnquanto();
|
|
967
|
-
case
|
|
972
|
+
case delegua_2.default.ESCOLHA:
|
|
968
973
|
this.avancarEDevolverAnterior();
|
|
969
974
|
return this.declaracaoEscolha();
|
|
970
|
-
case
|
|
975
|
+
case delegua_2.default.ESCREVA:
|
|
971
976
|
this.avancarEDevolverAnterior();
|
|
972
977
|
return this.declaracaoEscreva();
|
|
973
|
-
case
|
|
978
|
+
case delegua_2.default.FALHAR:
|
|
974
979
|
this.avancarEDevolverAnterior();
|
|
975
980
|
return this.declaracaoFalhar();
|
|
976
|
-
case
|
|
981
|
+
case delegua_2.default.FAZER:
|
|
977
982
|
this.avancarEDevolverAnterior();
|
|
978
983
|
return this.declaracaoFazer();
|
|
979
|
-
case
|
|
984
|
+
case delegua_2.default.LINHA_COMENTARIO:
|
|
980
985
|
return this.declaracaoComentarioMultilinha();
|
|
981
|
-
case
|
|
986
|
+
case delegua_2.default.PARA:
|
|
982
987
|
this.avancarEDevolverAnterior();
|
|
983
988
|
return this.declaracaoPara();
|
|
984
|
-
case
|
|
985
|
-
case
|
|
989
|
+
case delegua_2.default.PAUSA:
|
|
990
|
+
case delegua_2.default.SUSTAR:
|
|
986
991
|
this.avancarEDevolverAnterior();
|
|
987
992
|
return this.declaracaoSustar();
|
|
988
|
-
case
|
|
993
|
+
case delegua_2.default.SE:
|
|
989
994
|
this.avancarEDevolverAnterior();
|
|
990
995
|
return this.declaracaoSe();
|
|
991
|
-
case
|
|
996
|
+
case delegua_2.default.RETORNA:
|
|
992
997
|
this.avancarEDevolverAnterior();
|
|
993
998
|
return this.declaracaoRetorna();
|
|
994
|
-
case
|
|
999
|
+
case delegua_2.default.TENDO:
|
|
995
1000
|
this.avancarEDevolverAnterior();
|
|
996
1001
|
return this.declaracaoTendoComo();
|
|
997
|
-
case
|
|
1002
|
+
case delegua_2.default.TENTE:
|
|
998
1003
|
this.avancarEDevolverAnterior();
|
|
999
1004
|
return this.declaracaoTente();
|
|
1000
|
-
case
|
|
1005
|
+
case delegua_2.default.VARIAVEL:
|
|
1001
1006
|
this.avancarEDevolverAnterior();
|
|
1002
1007
|
return this.declaracaoDeVariaveis();
|
|
1003
1008
|
}
|
|
1004
1009
|
const simboloAtual = this.simbolos[this.atual];
|
|
1005
|
-
if (simboloAtual.tipo ===
|
|
1010
|
+
if (simboloAtual.tipo === delegua_2.default.IDENTIFICADOR) {
|
|
1006
1011
|
// Pela gramática, a seguinte situação não pode ocorrer:
|
|
1007
1012
|
// 1. O símbolo anterior ser um identificador; e
|
|
1008
1013
|
// 2. O símbolo anterior estar na mesma linha do identificador atual.
|
|
1009
1014
|
const simboloAnterior = this.simbolos[this.atual - 1];
|
|
1010
1015
|
if (!!simboloAnterior &&
|
|
1011
|
-
simboloAnterior.tipo ===
|
|
1016
|
+
simboloAnterior.tipo === delegua_2.default.IDENTIFICADOR &&
|
|
1012
1017
|
simboloAnterior.linha === simboloAtual.linha) {
|
|
1013
1018
|
this.erro(this.simbolos[this.atual], 'Não é permitido ter dois identificadores seguidos na mesma linha.');
|
|
1014
1019
|
}
|
|
@@ -1018,19 +1023,19 @@ class AvaliadorSintatico {
|
|
|
1018
1023
|
declaracaoTendoComo() {
|
|
1019
1024
|
const simboloTendo = this.simbolos[this.atual - 1];
|
|
1020
1025
|
const expressaoInicializacao = this.expressao();
|
|
1021
|
-
this.consumir(
|
|
1022
|
-
const simboloNomeVariavel = this.consumir(
|
|
1023
|
-
this.consumir(
|
|
1026
|
+
this.consumir(delegua_2.default.COMO, "Esperado palavra reservada 'como' após expressão de inicialização de variável, em declaração 'tendo'.");
|
|
1027
|
+
const simboloNomeVariavel = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado nome do identificador em declaração 'tendo'.");
|
|
1028
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado chave esquerda para abertura de bloco em declaração 'tendo'.");
|
|
1024
1029
|
const blocoCorpo = this.blocoEscopo();
|
|
1025
1030
|
return new declaracoes_1.TendoComo(simboloTendo.linha, simboloTendo.hashArquivo, simboloNomeVariavel, expressaoInicializacao, new declaracoes_1.Bloco(simboloTendo.linha, simboloTendo.hashArquivo, blocoCorpo));
|
|
1026
1031
|
}
|
|
1027
1032
|
declaracaoDesestruturacaoVariavel() {
|
|
1028
1033
|
const identificadores = [];
|
|
1029
1034
|
do {
|
|
1030
|
-
identificadores.push(this.consumir(
|
|
1031
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
1032
|
-
this.consumir(
|
|
1033
|
-
this.consumir(
|
|
1035
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
1036
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
1037
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, 'Esperado chave direita para concluir relação de variáveis a serem desestruturadas.');
|
|
1038
|
+
this.consumir(delegua_2.default.IGUAL, 'Esperado igual após relação de propriedades da desestruturação.');
|
|
1034
1039
|
const inicializador = this.expressao();
|
|
1035
1040
|
// TODO: Para cada variável dos identificadores, emitir um `AcessoMetodoOuPropriedade` usando
|
|
1036
1041
|
// como prefixo o nome do inicializador, e o sufixo o nome de cada propriedade.
|
|
@@ -1048,45 +1053,45 @@ class AvaliadorSintatico {
|
|
|
1048
1053
|
const identificadores = [];
|
|
1049
1054
|
let retorno = [];
|
|
1050
1055
|
let tipo = null;
|
|
1051
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1056
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_ESQUERDA)) {
|
|
1052
1057
|
return this.declaracaoDesestruturacaoVariavel();
|
|
1053
1058
|
}
|
|
1054
1059
|
do {
|
|
1055
|
-
identificadores.push(this.consumir(
|
|
1056
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
1057
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1060
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
1061
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
1062
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
1058
1063
|
tipo = this.verificarDefinicaoTipoAtual();
|
|
1059
1064
|
this.avancarEDevolverAnterior();
|
|
1060
1065
|
}
|
|
1061
|
-
if (!this.verificarSeSimboloAtualEIgualA(
|
|
1066
|
+
if (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL)) {
|
|
1062
1067
|
// Inicialização de variáveis sem valor.
|
|
1063
1068
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
1064
1069
|
retorno.push(new declaracoes_1.Var(identificador, null, tipo));
|
|
1065
1070
|
}
|
|
1066
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
1071
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
1067
1072
|
return retorno;
|
|
1068
1073
|
}
|
|
1069
1074
|
const inicializadores = [];
|
|
1070
1075
|
do {
|
|
1071
1076
|
inicializadores.push(this.expressao());
|
|
1072
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
1077
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
1073
1078
|
if (identificadores.length !== inicializadores.length) {
|
|
1074
1079
|
throw this.erro(this.simboloAtual(), 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
1075
1080
|
}
|
|
1076
1081
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
1077
|
-
tipo = inicializadores[indice] instanceof tuplas_1.Tupla ?
|
|
1082
|
+
tipo = inicializadores[indice] instanceof tuplas_1.Tupla ? delegua_1.default.TUPLA : tipo;
|
|
1078
1083
|
retorno.push(new declaracoes_1.Var(identificador, inicializadores[indice], tipo));
|
|
1079
1084
|
}
|
|
1080
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
1085
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
1081
1086
|
return retorno;
|
|
1082
1087
|
}
|
|
1083
1088
|
declaracaoDesestruturacaoConstante() {
|
|
1084
1089
|
const identificadores = [];
|
|
1085
1090
|
do {
|
|
1086
|
-
identificadores.push(this.consumir(
|
|
1087
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
1088
|
-
this.consumir(
|
|
1089
|
-
this.consumir(
|
|
1091
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
1092
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
1093
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, 'Esperado chave direita para concluir relação de variáveis a serem desestruturadas.');
|
|
1094
|
+
this.consumir(delegua_2.default.IGUAL, 'Esperado igual após relação de propriedades da desestruturação.');
|
|
1090
1095
|
const inicializador = this.expressao();
|
|
1091
1096
|
// TODO: Para cada variável dos identificadores, emitir um `AcessoMetodoOuPropriedade` usando
|
|
1092
1097
|
// como prefixo o nome do inicializador, e o sufixo o nome de cada propriedade.
|
|
@@ -1103,21 +1108,21 @@ class AvaliadorSintatico {
|
|
|
1103
1108
|
declaracaoDeConstantes() {
|
|
1104
1109
|
const identificadores = [];
|
|
1105
1110
|
let tipo = null;
|
|
1106
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1111
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_ESQUERDA)) {
|
|
1107
1112
|
return this.declaracaoDesestruturacaoConstante();
|
|
1108
1113
|
}
|
|
1109
1114
|
do {
|
|
1110
|
-
identificadores.push(this.consumir(
|
|
1111
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
1112
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1115
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da constante.'));
|
|
1116
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
1117
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
1113
1118
|
tipo = this.verificarDefinicaoTipoAtual();
|
|
1114
1119
|
this.avancarEDevolverAnterior();
|
|
1115
1120
|
}
|
|
1116
|
-
this.consumir(
|
|
1121
|
+
this.consumir(delegua_2.default.IGUAL, "Esperado '=' após identificador em instrução 'constante'.");
|
|
1117
1122
|
const inicializadores = [];
|
|
1118
1123
|
do {
|
|
1119
1124
|
inicializadores.push(this.expressao());
|
|
1120
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
1125
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
1121
1126
|
if (identificadores.length !== inicializadores.length) {
|
|
1122
1127
|
throw this.erro(this.simboloAtual(), 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
1123
1128
|
}
|
|
@@ -1125,18 +1130,18 @@ class AvaliadorSintatico {
|
|
|
1125
1130
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
1126
1131
|
retorno.push(new declaracoes_1.Const(identificador, inicializadores[indice], tipo));
|
|
1127
1132
|
}
|
|
1128
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
1133
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
1129
1134
|
return retorno;
|
|
1130
1135
|
}
|
|
1131
1136
|
funcao(tipo) {
|
|
1132
1137
|
let simbolo;
|
|
1133
1138
|
switch (this.simbolos[this.atual].tipo) {
|
|
1134
|
-
case
|
|
1139
|
+
case delegua_2.default.CONSTRUTOR:
|
|
1135
1140
|
simbolo = this.avancarEDevolverAnterior();
|
|
1136
1141
|
this.pilhaDecoradores = [];
|
|
1137
1142
|
break;
|
|
1138
1143
|
default:
|
|
1139
|
-
simbolo = this.consumir(
|
|
1144
|
+
simbolo = this.consumir(delegua_2.default.IDENTIFICADOR, `Esperado nome de ${tipo}.`);
|
|
1140
1145
|
break;
|
|
1141
1146
|
}
|
|
1142
1147
|
return new declaracoes_1.FuncaoDeclaracao(simbolo, this.corpoDaFuncao(tipo), null, this.pilhaDecoradores);
|
|
@@ -1145,18 +1150,18 @@ class AvaliadorSintatico {
|
|
|
1145
1150
|
const parametros = [];
|
|
1146
1151
|
do {
|
|
1147
1152
|
const parametro = {};
|
|
1148
|
-
if (this.simbolos[this.atual].tipo ===
|
|
1149
|
-
this.consumir(
|
|
1153
|
+
if (this.simbolos[this.atual].tipo === delegua_2.default.MULTIPLICACAO) {
|
|
1154
|
+
this.consumir(delegua_2.default.MULTIPLICACAO, null);
|
|
1150
1155
|
parametro.abrangencia = 'multiplo';
|
|
1151
1156
|
}
|
|
1152
1157
|
else {
|
|
1153
1158
|
parametro.abrangencia = 'padrao';
|
|
1154
1159
|
}
|
|
1155
|
-
parametro.nome = this.consumir(
|
|
1156
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1160
|
+
parametro.nome = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome do parâmetro.');
|
|
1161
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL)) {
|
|
1157
1162
|
parametro.valorPadrao = this.primario();
|
|
1158
1163
|
}
|
|
1159
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1164
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
1160
1165
|
let tipoDadoParametro = this.verificarDefinicaoTipoAtual();
|
|
1161
1166
|
parametro.tipoDado = {
|
|
1162
1167
|
nome: this.simbolos[this.atual - 2].lexema,
|
|
@@ -1168,43 +1173,43 @@ class AvaliadorSintatico {
|
|
|
1168
1173
|
parametros.push(parametro);
|
|
1169
1174
|
if (parametro.abrangencia === 'multiplo')
|
|
1170
1175
|
break;
|
|
1171
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
1176
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
1172
1177
|
return parametros;
|
|
1173
1178
|
}
|
|
1174
1179
|
corpoDaFuncao(tipo) {
|
|
1175
1180
|
// O parêntese esquerdo é considerado o símbolo inicial para
|
|
1176
1181
|
// fins de pragma.
|
|
1177
|
-
const parenteseEsquerdo = this.consumir(
|
|
1182
|
+
const parenteseEsquerdo = this.consumir(delegua_2.default.PARENTESE_ESQUERDO, `Esperado '(' após o nome ${tipo}.`);
|
|
1178
1183
|
let parametros = [];
|
|
1179
|
-
if (!this.verificarTipoSimboloAtual(
|
|
1184
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
1180
1185
|
parametros = this.logicaComumParametros();
|
|
1181
1186
|
}
|
|
1182
|
-
this.consumir(
|
|
1187
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
1183
1188
|
let tipoRetorno = null;
|
|
1184
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1189
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
1185
1190
|
tipoRetorno = this.verificarDefinicaoTipoAtual();
|
|
1186
1191
|
this.avancarEDevolverAnterior();
|
|
1187
1192
|
}
|
|
1188
|
-
this.consumir(
|
|
1193
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, `Esperado '{' antes do escopo do ${tipo}.`);
|
|
1189
1194
|
const corpo = this.blocoEscopo();
|
|
1190
1195
|
return new construtos_1.FuncaoConstruto(this.hashArquivo, Number(parenteseEsquerdo.linha), parametros, corpo, tipoRetorno);
|
|
1191
1196
|
}
|
|
1192
1197
|
declaracaoDeClasse() {
|
|
1193
|
-
const simbolo = this.consumir(
|
|
1198
|
+
const simbolo = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
1194
1199
|
const pilhaDecoradoresClasse = this.pilhaDecoradores;
|
|
1195
1200
|
let superClasse = null;
|
|
1196
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1197
|
-
this.consumir(
|
|
1201
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.HERDA)) {
|
|
1202
|
+
this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da Superclasse.');
|
|
1198
1203
|
superClasse = new construtos_1.Variavel(this.hashArquivo, this.simbolos[this.atual - 1]);
|
|
1199
1204
|
}
|
|
1200
|
-
this.consumir(
|
|
1205
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo da classe.");
|
|
1201
1206
|
this.pilhaDecoradores = [];
|
|
1202
1207
|
const metodos = [];
|
|
1203
1208
|
const propriedades = [];
|
|
1204
|
-
while (!this.verificarTipoSimboloAtual(
|
|
1209
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) && !this.estaNoFinal()) {
|
|
1205
1210
|
// Se o símbolo atual é arroba, é um decorador.
|
|
1206
1211
|
// Caso contrário, verificamos o próximo símbolo.
|
|
1207
|
-
if (this.simbolos[this.atual].tipo ===
|
|
1212
|
+
if (this.simbolos[this.atual].tipo === delegua_2.default.ARROBA) {
|
|
1208
1213
|
this.resolverDecorador();
|
|
1209
1214
|
continue;
|
|
1210
1215
|
}
|
|
@@ -1212,15 +1217,15 @@ class AvaliadorSintatico {
|
|
|
1212
1217
|
// Caso contrário, é uma propriedade.
|
|
1213
1218
|
const proximoSimbolo = this.simbolos[this.atual + 1];
|
|
1214
1219
|
switch (proximoSimbolo.tipo) {
|
|
1215
|
-
case
|
|
1220
|
+
case delegua_2.default.PARENTESE_ESQUERDO:
|
|
1216
1221
|
metodos.push(this.funcao('método'));
|
|
1217
1222
|
this.pilhaDecoradores = [];
|
|
1218
1223
|
break;
|
|
1219
|
-
case
|
|
1220
|
-
const nomePropriedade = this.consumir(
|
|
1221
|
-
this.consumir(
|
|
1224
|
+
case delegua_2.default.DOIS_PONTOS:
|
|
1225
|
+
const nomePropriedade = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado identificador para nome de propriedade.');
|
|
1226
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, 'Esperado dois-pontos após nome de propriedade.');
|
|
1222
1227
|
const tipoPropriedade = this.avancarEDevolverAnterior();
|
|
1223
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
1228
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
1224
1229
|
propriedades.push(new declaracoes_1.PropriedadeClasse(nomePropriedade, tipoPropriedade.lexema, this.pilhaDecoradores));
|
|
1225
1230
|
this.pilhaDecoradores = [];
|
|
1226
1231
|
break;
|
|
@@ -1228,7 +1233,7 @@ class AvaliadorSintatico {
|
|
|
1228
1233
|
throw this.erro(this.simbolos[this.atual], 'Esperado definição de método ou propriedade.');
|
|
1229
1234
|
}
|
|
1230
1235
|
}
|
|
1231
|
-
this.consumir(
|
|
1236
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' após o escopo da classe.");
|
|
1232
1237
|
return new declaracoes_1.Classe(simbolo, superClasse, metodos, propriedades, pilhaDecoradoresClasse);
|
|
1233
1238
|
}
|
|
1234
1239
|
/**
|
|
@@ -1241,13 +1246,13 @@ class AvaliadorSintatico {
|
|
|
1241
1246
|
*/
|
|
1242
1247
|
resolverDeclaracaoForaDeBloco() {
|
|
1243
1248
|
try {
|
|
1244
|
-
if ((this.verificarTipoSimboloAtual(
|
|
1245
|
-
this.verificarTipoSimboloAtual(
|
|
1246
|
-
this.verificarTipoProximoSimbolo(
|
|
1249
|
+
if ((this.verificarTipoSimboloAtual(delegua_2.default.FUNCAO) ||
|
|
1250
|
+
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO)) &&
|
|
1251
|
+
this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
1247
1252
|
this.avancarEDevolverAnterior();
|
|
1248
1253
|
return this.funcao('funcao');
|
|
1249
1254
|
}
|
|
1250
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1255
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CLASSE)) {
|
|
1251
1256
|
return this.declaracaoDeClasse();
|
|
1252
1257
|
}
|
|
1253
1258
|
return this.resolverDeclaracao();
|
|
@@ -1268,15 +1273,15 @@ class AvaliadorSintatico {
|
|
|
1268
1273
|
while (!this.estaNoFinal()) {
|
|
1269
1274
|
const tipoSimboloAtual = this.simbolos[this.atual - 1].tipo;
|
|
1270
1275
|
switch (tipoSimboloAtual) {
|
|
1271
|
-
case
|
|
1272
|
-
case
|
|
1273
|
-
case
|
|
1274
|
-
case
|
|
1275
|
-
case
|
|
1276
|
-
case
|
|
1277
|
-
case
|
|
1278
|
-
case
|
|
1279
|
-
case
|
|
1276
|
+
case delegua_2.default.CLASSE:
|
|
1277
|
+
case delegua_2.default.FUNCAO:
|
|
1278
|
+
case delegua_2.default.FUNÇÃO:
|
|
1279
|
+
case delegua_2.default.VARIAVEL:
|
|
1280
|
+
case delegua_2.default.PARA:
|
|
1281
|
+
case delegua_2.default.SE:
|
|
1282
|
+
case delegua_2.default.ENQUANTO:
|
|
1283
|
+
case delegua_2.default.ESCREVA:
|
|
1284
|
+
case delegua_2.default.RETORNA:
|
|
1280
1285
|
return;
|
|
1281
1286
|
}
|
|
1282
1287
|
this.avancarEDevolverAnterior();
|
|
@@ -4171,11 +4176,17 @@ exports.Atribuir = void 0;
|
|
|
4171
4176
|
* Construto de atribuição de um valor a um símbolo.
|
|
4172
4177
|
*/
|
|
4173
4178
|
class Atribuir {
|
|
4174
|
-
constructor(hashArquivo, simbolo, valor
|
|
4179
|
+
constructor(hashArquivo, simbolo, valor,
|
|
4180
|
+
// indice so é usado para variaveis de vetores
|
|
4181
|
+
// TODO: criar alguma validaçao para garantir que indice so seja passado para variaveis de vetores
|
|
4182
|
+
indice) {
|
|
4175
4183
|
this.linha = Number(simbolo.linha);
|
|
4176
4184
|
this.hashArquivo = hashArquivo;
|
|
4177
4185
|
this.simbolo = simbolo;
|
|
4178
4186
|
this.valor = valor;
|
|
4187
|
+
if (indice !== undefined) {
|
|
4188
|
+
this.indice = indice;
|
|
4189
|
+
}
|
|
4179
4190
|
}
|
|
4180
4191
|
async aceitar(visitante) {
|
|
4181
4192
|
return await visitante.visitarExpressaoDeAtribuicao(this);
|
|
@@ -5796,7 +5807,7 @@ class DeleguaFuncao extends chamavel_1.Chamavel {
|
|
|
5796
5807
|
}
|
|
5797
5808
|
resolverParametrosEspalhados(argumentos, indiceArgumentoAtual) {
|
|
5798
5809
|
const argumentosResolvidos = [];
|
|
5799
|
-
for (let i = indiceArgumentoAtual; i < argumentos.length;
|
|
5810
|
+
for (let i = indiceArgumentoAtual; i < argumentos.length; i++) {
|
|
5800
5811
|
const argumentoAtual = argumentos[i];
|
|
5801
5812
|
argumentosResolvidos.push(argumentoAtual && argumentoAtual.hasOwnProperty('valor') ? argumentoAtual.valor : argumentoAtual);
|
|
5802
5813
|
}
|
|
@@ -7753,7 +7764,7 @@ class InterpretadorBase {
|
|
|
7753
7764
|
});
|
|
7754
7765
|
}
|
|
7755
7766
|
}
|
|
7756
|
-
// Por algum motivo misterioso, `entidadeChamada instanceof Chamavel` dá `false` em Liquido,
|
|
7767
|
+
// Por algum motivo misterioso, `entidadeChamada instanceof Chamavel` dá `false` em Liquido,
|
|
7757
7768
|
// mesmo que esteja tudo certo com `DeleguaFuncao`,
|
|
7758
7769
|
// então precisamos testar o nome do construtor também.
|
|
7759
7770
|
if (entidadeChamada instanceof estruturas_1.Chamavel || entidadeChamada.constructor.name === 'DeleguaFuncao') {
|
|
@@ -7788,7 +7799,11 @@ class InterpretadorBase {
|
|
|
7788
7799
|
async visitarExpressaoDeAtribuicao(expressao) {
|
|
7789
7800
|
const valor = await this.avaliar(expressao.valor);
|
|
7790
7801
|
const valorResolvido = valor !== undefined && valor.hasOwnProperty('valor') ? valor.valor : valor;
|
|
7791
|
-
|
|
7802
|
+
let indice = null;
|
|
7803
|
+
if (expressao.indice) {
|
|
7804
|
+
indice = await this.avaliar(expressao.indice);
|
|
7805
|
+
}
|
|
7806
|
+
this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valorResolvido, indice);
|
|
7792
7807
|
return valorResolvido;
|
|
7793
7808
|
}
|
|
7794
7809
|
procurarVariavel(simbolo) {
|
|
@@ -8218,14 +8233,17 @@ class InterpretadorBase {
|
|
|
8218
8233
|
}
|
|
8219
8234
|
return objeto[valorIndice];
|
|
8220
8235
|
}
|
|
8221
|
-
|
|
8236
|
+
if (objeto instanceof construtos_1.Vetor) {
|
|
8237
|
+
return objeto.valores[valorIndice];
|
|
8238
|
+
}
|
|
8239
|
+
if (objeto.constructor === Object ||
|
|
8222
8240
|
objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
8223
8241
|
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
8224
8242
|
objeto instanceof estruturas_1.DeleguaClasse ||
|
|
8225
8243
|
objeto instanceof estruturas_1.DeleguaModulo) {
|
|
8226
8244
|
return objeto[valorIndice] || null;
|
|
8227
8245
|
}
|
|
8228
|
-
|
|
8246
|
+
if (typeof objeto === primitivos_1.default.TEXTO) {
|
|
8229
8247
|
if (!Number.isInteger(valorIndice)) {
|
|
8230
8248
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha));
|
|
8231
8249
|
}
|
|
@@ -8239,9 +8257,7 @@ class InterpretadorBase {
|
|
|
8239
8257
|
}
|
|
8240
8258
|
return objeto.charAt(valorIndice);
|
|
8241
8259
|
}
|
|
8242
|
-
|
|
8243
|
-
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ter seus valores indexados.', expressao.linha));
|
|
8244
|
-
}
|
|
8260
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ter seus valores indexados.', expressao.linha));
|
|
8245
8261
|
}
|
|
8246
8262
|
async visitarExpressaoDefinirValor(expressao) {
|
|
8247
8263
|
const variavelObjeto = await this.avaliar(expressao.objeto);
|
|
@@ -8264,6 +8280,7 @@ class InterpretadorBase {
|
|
|
8264
8280
|
}
|
|
8265
8281
|
/**
|
|
8266
8282
|
* Executa uma declaração de classe.
|
|
8283
|
+
* Uma variável do tipo `DeleguaClasse` é adicionada à pilha de escopos de execução.
|
|
8267
8284
|
* @param declaracao A declaração de classe.
|
|
8268
8285
|
* @returns Sempre retorna nulo, por ser requerido pelo contrato de visita.
|
|
8269
8286
|
*/
|
|
@@ -8307,15 +8324,15 @@ class InterpretadorBase {
|
|
|
8307
8324
|
*/
|
|
8308
8325
|
async visitarExpressaoAcessoMetodo(expressao) {
|
|
8309
8326
|
let variavelObjeto = await this.avaliar(expressao.objeto);
|
|
8310
|
-
// Este caso acontece quando há encadeamento de métodos.
|
|
8327
|
+
// Este caso acontece quando há encadeamento de métodos.
|
|
8311
8328
|
// Por exemplo, `objeto1.metodo1().metodo2()`.
|
|
8312
|
-
// Como `RetornoQuebra` também possui `valor`, precisamos extrair o
|
|
8329
|
+
// Como `RetornoQuebra` também possui `valor`, precisamos extrair o
|
|
8313
8330
|
// valor dele primeiro.
|
|
8314
8331
|
if (variavelObjeto.constructor.name === 'RetornoQuebra') {
|
|
8315
8332
|
variavelObjeto = variavelObjeto.valor;
|
|
8316
8333
|
}
|
|
8317
8334
|
const objeto = variavelObjeto.hasOwnProperty('valor') ? variavelObjeto.valor : variavelObjeto;
|
|
8318
|
-
// Outro caso que `instanceof` simplesmente não funciona para casos em Liquido,
|
|
8335
|
+
// Outro caso que `instanceof` simplesmente não funciona para casos em Liquido,
|
|
8319
8336
|
// então testamos também o nome do construtor.
|
|
8320
8337
|
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse || objeto.constructor.name === 'ObjetoDeleguaClasse') {
|
|
8321
8338
|
return objeto.obter(expressao.simbolo) || null;
|
|
@@ -9294,7 +9311,7 @@ class PilhaEscoposExecucao {
|
|
|
9294
9311
|
imutavel: false,
|
|
9295
9312
|
};
|
|
9296
9313
|
}
|
|
9297
|
-
atribuirVariavel(simbolo, valor) {
|
|
9314
|
+
atribuirVariavel(simbolo, valor, indice) {
|
|
9298
9315
|
for (let i = 1; i <= this.pilha.length; i++) {
|
|
9299
9316
|
const ambiente = this.pilha[this.pilha.length - i].ambiente;
|
|
9300
9317
|
if (ambiente.valores[simbolo.lexema] !== undefined) {
|
|
@@ -9304,11 +9321,21 @@ class PilhaEscoposExecucao {
|
|
|
9304
9321
|
}
|
|
9305
9322
|
const tipo = (variavel && variavel.hasOwnProperty('tipo') ? variavel.tipo : (0, inferenciador_1.inferirTipoVariavel)(valor)).toLowerCase();
|
|
9306
9323
|
const valorResolvido = this.converterValor(tipo, valor);
|
|
9307
|
-
|
|
9308
|
-
valor
|
|
9309
|
-
|
|
9310
|
-
|
|
9311
|
-
|
|
9324
|
+
if (indice !== undefined && indice !== null) {
|
|
9325
|
+
if (variavel.valor instanceof Array) {
|
|
9326
|
+
variavel.valor[indice] = valorResolvido;
|
|
9327
|
+
}
|
|
9328
|
+
else {
|
|
9329
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(simbolo, "Variável não é um vetor.");
|
|
9330
|
+
}
|
|
9331
|
+
}
|
|
9332
|
+
else {
|
|
9333
|
+
ambiente.valores[simbolo.lexema] = {
|
|
9334
|
+
valor: valorResolvido,
|
|
9335
|
+
tipo,
|
|
9336
|
+
imutavel: false,
|
|
9337
|
+
};
|
|
9338
|
+
}
|
|
9312
9339
|
return;
|
|
9313
9340
|
}
|
|
9314
9341
|
}
|