@designliquido/delegua 1.14.0 → 1.15.1
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-documentario/index.d.ts +1 -1
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +12 -2
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts +1 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +18 -0
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +10 -0
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.d.ts +25 -5
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js +301 -25
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +15 -11
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts +10 -3
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js +279 -57
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.js +33 -2
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/biblioteca-global.js +3 -7
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/prisma/biblioteca-global.d.ts +10 -0
- package/bibliotecas/dialetos/prisma/biblioteca-global.d.ts.map +1 -0
- package/bibliotecas/dialetos/prisma/biblioteca-global.js +224 -0
- package/bibliotecas/dialetos/prisma/biblioteca-global.js.map +1 -0
- package/bibliotecas/dialetos/tenda/biblioteca-global.d.ts +3 -0
- package/bibliotecas/dialetos/tenda/biblioteca-global.d.ts.map +1 -0
- package/bibliotecas/dialetos/tenda/biblioteca-global.js +365 -0
- package/bibliotecas/dialetos/tenda/biblioteca-global.js.map +1 -0
- package/bin/package.json +1 -1
- package/construtos/vetor.d.ts.map +1 -1
- package/construtos/vetor.js.map +1 -1
- package/interfaces/documentario/documentario-analisado.d.ts +2 -2
- package/interfaces/documentario/index.d.ts +3 -3
- package/interpretador/depuracao/interpretador-com-depuracao.d.ts.map +1 -1
- package/interpretador/depuracao/interpretador-com-depuracao.js +8 -0
- package/interpretador/depuracao/interpretador-com-depuracao.js.map +1 -1
- package/interpretador/dialetos/calango/interpretador-calango.d.ts +2 -0
- package/interpretador/dialetos/calango/interpretador-calango.d.ts.map +1 -1
- package/interpretador/dialetos/calango/interpretador-calango.js +15 -0
- package/interpretador/dialetos/calango/interpretador-calango.js.map +1 -1
- package/interpretador/dialetos/index.d.ts +2 -0
- package/interpretador/dialetos/index.d.ts.map +1 -1
- package/interpretador/dialetos/index.js +2 -0
- package/interpretador/dialetos/index.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/dialetos/prisma/index.d.ts +2 -0
- package/interpretador/dialetos/prisma/index.d.ts.map +1 -0
- package/interpretador/dialetos/prisma/index.js +18 -0
- package/interpretador/dialetos/prisma/index.js.map +1 -0
- package/interpretador/dialetos/prisma/interpretador-prisma.d.ts +13 -0
- package/interpretador/dialetos/prisma/interpretador-prisma.d.ts.map +1 -0
- package/interpretador/dialetos/prisma/interpretador-prisma.js +49 -0
- package/interpretador/dialetos/prisma/interpretador-prisma.js.map +1 -0
- package/interpretador/dialetos/tenda/index.d.ts +2 -0
- package/interpretador/dialetos/tenda/index.d.ts.map +1 -0
- package/interpretador/dialetos/tenda/index.js +18 -0
- package/interpretador/dialetos/tenda/index.js.map +1 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.d.ts +13 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.d.ts.map +1 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.js +31 -0
- package/interpretador/dialetos/tenda/interpretador-tenda.js.map +1 -0
- package/interpretador/interpretador.d.ts +2 -1
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +24 -1
- package/interpretador/interpretador.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts.map +1 -1
- package/interpretador/pilha-escopos-execucao.js +3 -0
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/lexador/dialetos/lexador-calango.d.ts +1 -0
- package/lexador/dialetos/lexador-calango.d.ts.map +1 -1
- package/lexador/dialetos/lexador-calango.js +77 -0
- package/lexador/dialetos/lexador-calango.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts.map +1 -1
- package/lexador/dialetos/lexador-pitugues.js +2 -4
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/lexador/dialetos/lexador-prisma.d.ts.map +1 -1
- package/lexador/dialetos/lexador-prisma.js +24 -6
- package/lexador/dialetos/lexador-prisma.js.map +1 -1
- package/lexador/dialetos/palavras-reservadas/calango.d.ts +31 -4
- package/lexador/dialetos/palavras-reservadas/calango.d.ts.map +1 -1
- package/lexador/dialetos/palavras-reservadas/calango.js +31 -4
- package/lexador/dialetos/palavras-reservadas/calango.js.map +1 -1
- package/lexador/dialetos/palavras-reservadas/prisma.d.ts +3 -0
- package/lexador/dialetos/palavras-reservadas/prisma.d.ts.map +1 -1
- package/lexador/dialetos/palavras-reservadas/prisma.js +3 -0
- package/lexador/dialetos/palavras-reservadas/prisma.js.map +1 -1
- package/lexador/lexador.d.ts.map +1 -1
- package/lexador/lexador.js +55 -4
- package/lexador/lexador.js.map +1 -1
- package/package.json +1 -1
- package/tipos-de-simbolos/calango.d.ts +28 -0
- package/tipos-de-simbolos/calango.d.ts.map +1 -1
- package/tipos-de-simbolos/calango.js +28 -0
- package/tipos-de-simbolos/calango.js.map +1 -1
- package/tipos-de-simbolos/prisma.d.ts +4 -0
- package/tipos-de-simbolos/prisma.d.ts.map +1 -1
- package/tipos-de-simbolos/prisma.js +4 -0
- package/tipos-de-simbolos/prisma.js.map +1 -1
- package/tradutores/tradutor-assembly-risc-v.d.ts.map +1 -1
- package/tradutores/tradutor-assembly-risc-v.js +85 -85
- package/tradutores/tradutor-assembly-risc-v.js.map +1 -1
- package/tradutores/tradutor-assemblyscript.d.ts +2 -0
- package/tradutores/tradutor-assemblyscript.d.ts.map +1 -1
- package/tradutores/tradutor-assemblyscript.js +64 -1
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-webassembly.d.ts.map +1 -1
- package/tradutores/tradutor-webassembly.js +52 -46
- package/tradutores/tradutor-webassembly.js.map +1 -1
- package/umd/delegua.js +805 -231
package/umd/delegua.js
CHANGED
|
@@ -762,7 +762,10 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
762
762
|
switch (condicao.constructor) {
|
|
763
763
|
case construtos_1.Literal:
|
|
764
764
|
const condicaoLiteral = condicao;
|
|
765
|
-
|
|
765
|
+
const tiposNumericos = ['inteiro', 'número', 'real'];
|
|
766
|
+
const ambosSaoNumericos = tiposNumericos.includes(condicaoLiteral.tipo) &&
|
|
767
|
+
tiposNumericos.includes(tipo);
|
|
768
|
+
if (condicaoLiteral.tipo !== tipo && !ambosSaoNumericos) {
|
|
766
769
|
this.erro({
|
|
767
770
|
lexema: condicaoLiteral.valor,
|
|
768
771
|
tipo: condicaoLiteral.tipo,
|
|
@@ -881,7 +884,14 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
881
884
|
this.verificarOperadorBinario(binario.direita);
|
|
882
885
|
}
|
|
883
886
|
const operadoresMatematicos = ['ADICAO', 'SUBTRACAO', 'MULTIPLICACAO', 'DIVISAO', 'MODULO'];
|
|
884
|
-
const operadoresComparacao = [
|
|
887
|
+
const operadoresComparacao = [
|
|
888
|
+
'MAIOR',
|
|
889
|
+
'MAIOR_IGUAL',
|
|
890
|
+
'MENOR',
|
|
891
|
+
'MENOR_IGUAL',
|
|
892
|
+
'IGUAL',
|
|
893
|
+
'DIFERENTE',
|
|
894
|
+
];
|
|
885
895
|
if (operadoresMatematicos.includes(binario.operador.tipo)) {
|
|
886
896
|
this.verificarTiposOperandos(binario);
|
|
887
897
|
}
|
|
@@ -2679,6 +2689,16 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2679
2689
|
}
|
|
2680
2690
|
if (entidadeChamada.constructor === construtos_1.Variavel) {
|
|
2681
2691
|
const entidadeChamadaResolvidaVariavel = entidadeChamada;
|
|
2692
|
+
const informacoesFuncaoBibliotecaGlobal = this.pilhaEscopos.obterBibliotecaGlobal(entidadeChamadaResolvidaVariavel.simbolo.lexema);
|
|
2693
|
+
if (informacoesFuncaoBibliotecaGlobal &&
|
|
2694
|
+
Array.isArray(informacoesFuncaoBibliotecaGlobal.subElementos) &&
|
|
2695
|
+
informacoesFuncaoBibliotecaGlobal.subElementos.length > 0) {
|
|
2696
|
+
const erros = this.validarArgumentosEntidadeChamada(informacoesFuncaoBibliotecaGlobal.subElementos, argumentos);
|
|
2697
|
+
if (erros.length > 0) {
|
|
2698
|
+
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamadaResolvidaVariavel.simbolo, `Erros ao resolver argumentos de chamada a ${entidadeChamadaResolvidaVariavel.simbolo.lexema}: \n${erros.reduce((mensagem, erro) => (mensagem += `${erro}\n`), '')}`);
|
|
2699
|
+
}
|
|
2700
|
+
return entidadeChamadaResolvidaVariavel;
|
|
2701
|
+
}
|
|
2682
2702
|
if (tipoPrimitiva === 'qualquer') {
|
|
2683
2703
|
// Provavelmente uma chamada a alguma função da biblioteca global.
|
|
2684
2704
|
// Até então, é sempre do tipo `InformacaoElementoSintatico`.
|
|
@@ -6373,12 +6393,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
6373
6393
|
}
|
|
6374
6394
|
else {
|
|
6375
6395
|
// Bloco de múltiplas linhas baseado em indentação
|
|
6376
|
-
let espacosAtual = this
|
|
6377
|
-
|
|
6378
|
-
.espacosIndentacao;
|
|
6379
|
-
const espacosAnterior = this
|
|
6380
|
-
.localizacoes[simboloAnterior.linha]
|
|
6381
|
-
.espacosIndentacao;
|
|
6396
|
+
let espacosAtual = this.localizacoes[simboloAtual.linha].espacosIndentacao;
|
|
6397
|
+
const espacosAnterior = this.localizacoes[simboloAnterior.linha].espacosIndentacao;
|
|
6382
6398
|
if (espacosAtual <= espacosAnterior) {
|
|
6383
6399
|
throw this.erro(simboloAtual, `Indentação inconsistente na linha ${simboloAtual.linha}. ` +
|
|
6384
6400
|
`Esperado: >= ${espacosAnterior}. ` +
|
|
@@ -6392,9 +6408,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6392
6408
|
declaracoes = declaracoes.concat(retorno);
|
|
6393
6409
|
simboloAtual = this.simboloAtual();
|
|
6394
6410
|
if (simboloAtual) {
|
|
6395
|
-
espacosAtual = this
|
|
6396
|
-
.localizacoes[simboloAtual.linha]
|
|
6397
|
-
.espacosIndentacao;
|
|
6411
|
+
espacosAtual = this.localizacoes[simboloAtual.linha].espacosIndentacao;
|
|
6398
6412
|
}
|
|
6399
6413
|
}
|
|
6400
6414
|
}
|
|
@@ -6540,10 +6554,20 @@ class AvaliadorSintaticoPitugues {
|
|
|
6540
6554
|
}
|
|
6541
6555
|
async declaracaoSe() {
|
|
6542
6556
|
const condicao = await this.expressao();
|
|
6543
|
-
|
|
6557
|
+
this.consumir(pitugues_2.default.DOIS_PONTOS, "Esperado ':' após condição do 'se'.");
|
|
6558
|
+
const simboloColonEntao = this.simboloAnterior();
|
|
6559
|
+
const caminhoEntao = new declaracoes_1.Bloco(simboloColonEntao.hashArquivo, Number(simboloColonEntao.linha), await this.blocoEscopo());
|
|
6544
6560
|
let caminhoSenao = null;
|
|
6545
6561
|
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.SENAO, pitugues_2.default.SENÃO)) {
|
|
6546
|
-
|
|
6562
|
+
if (this.verificarTipoSimboloAtual(pitugues_2.default.SE)) {
|
|
6563
|
+
// 'senao se' - encadeamento de condicionais, sem dois-pontos
|
|
6564
|
+
caminhoSenao = await this.resolverDeclaracao();
|
|
6565
|
+
}
|
|
6566
|
+
else {
|
|
6567
|
+
this.consumir(pitugues_2.default.DOIS_PONTOS, "Esperado ':' após 'senao'.");
|
|
6568
|
+
const simboloColonSenao = this.simboloAnterior();
|
|
6569
|
+
caminhoSenao = new declaracoes_1.Bloco(simboloColonSenao.hashArquivo, Number(simboloColonSenao.linha), await this.blocoEscopo());
|
|
6570
|
+
}
|
|
6547
6571
|
}
|
|
6548
6572
|
return new declaracoes_1.Se(condicao, caminhoEntao, [], caminhoSenao);
|
|
6549
6573
|
}
|
|
@@ -7386,6 +7410,7 @@ const browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime
|
|
|
7386
7410
|
const construtos_1 = require("../../construtos");
|
|
7387
7411
|
const declaracoes_1 = require("../../declaracoes");
|
|
7388
7412
|
const avaliador_sintatico_base_1 = require("../avaliador-sintatico-base");
|
|
7413
|
+
const erro_avaliador_sintatico_1 = require("../erro-avaliador-sintatico");
|
|
7389
7414
|
const inferenciador_1 = require("../../inferenciador");
|
|
7390
7415
|
const pilha_escopos_1 = require("../pilha-escopos");
|
|
7391
7416
|
const informacao_escopo_1 = require("../informacao-escopo");
|
|
@@ -7470,6 +7495,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7470
7495
|
return false;
|
|
7471
7496
|
}
|
|
7472
7497
|
async primario() {
|
|
7498
|
+
var _a;
|
|
7473
7499
|
const simboloAtual = this.simbolos[this.atual];
|
|
7474
7500
|
let valores = [];
|
|
7475
7501
|
switch (simboloAtual.tipo) {
|
|
@@ -7491,10 +7517,16 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7491
7517
|
}
|
|
7492
7518
|
let indice = 1;
|
|
7493
7519
|
do {
|
|
7494
|
-
let chave
|
|
7495
|
-
if (this.
|
|
7496
|
-
|
|
7497
|
-
//
|
|
7520
|
+
let chave;
|
|
7521
|
+
if (this.verificarTipoSimboloAtual(prisma_1.default.IDENTIFICADOR) &&
|
|
7522
|
+
((_a = this.simbolos[this.atual + 1]) === null || _a === void 0 ? void 0 : _a.tipo) === prisma_1.default.IGUAL) {
|
|
7523
|
+
// Chave nomeada: {nome = "João"}
|
|
7524
|
+
const chaveIdentificador = this.avancarEDevolverAnterior();
|
|
7525
|
+
this.avancarEDevolverAnterior(); // consume IGUAL
|
|
7526
|
+
chave = new construtos_1.Literal(this.hashArquivo, simboloAtual.linha, chaveIdentificador.lexema);
|
|
7527
|
+
}
|
|
7528
|
+
else {
|
|
7529
|
+
chave = new construtos_1.Literal(this.hashArquivo, simboloAtual.linha, String(indice));
|
|
7498
7530
|
}
|
|
7499
7531
|
const valor = await this.ou();
|
|
7500
7532
|
chaves.push(chave);
|
|
@@ -7554,8 +7586,12 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7554
7586
|
}
|
|
7555
7587
|
throw this.erro(this.simbolos[this.atual], 'Esperado expressão.');
|
|
7556
7588
|
}
|
|
7557
|
-
expressaoImportar() {
|
|
7558
|
-
|
|
7589
|
+
async expressaoImportar() {
|
|
7590
|
+
this.avancarEDevolverAnterior();
|
|
7591
|
+
this.consumir(prisma_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
|
|
7592
|
+
const caminho = await this.expressao();
|
|
7593
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
7594
|
+
return new construtos_1.ImportarComoConstruto(caminho);
|
|
7559
7595
|
}
|
|
7560
7596
|
/**
|
|
7561
7597
|
* Construto para texto multilinhas.
|
|
@@ -7623,7 +7659,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7623
7659
|
return expressao;
|
|
7624
7660
|
}
|
|
7625
7661
|
async unario() {
|
|
7626
|
-
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.NEGACAO, prisma_1.default.SUBTRACAO, prisma_1.default.BIT_NOT)) {
|
|
7662
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.NEGACAO, prisma_1.default.SUBTRACAO, prisma_1.default.BIT_NOT, prisma_1.default.NAO, prisma_1.default.COMPRIMENTO)) {
|
|
7627
7663
|
const operador = this.simboloAnterior();
|
|
7628
7664
|
const direito = await this.unario();
|
|
7629
7665
|
return new construtos_1.Unario(this.hashArquivo, operador, direito);
|
|
@@ -7657,8 +7693,17 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7657
7693
|
}
|
|
7658
7694
|
return expressao;
|
|
7659
7695
|
}
|
|
7660
|
-
async
|
|
7696
|
+
async concatenacao() {
|
|
7661
7697
|
let expressao = await this.adicaoOuSubtracao();
|
|
7698
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.CONCATENACAO)) {
|
|
7699
|
+
const operador = this.simboloAnterior();
|
|
7700
|
+
const direito = await this.adicaoOuSubtracao();
|
|
7701
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
7702
|
+
}
|
|
7703
|
+
return expressao;
|
|
7704
|
+
}
|
|
7705
|
+
async bitShift() {
|
|
7706
|
+
let expressao = await this.concatenacao();
|
|
7662
7707
|
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.MENOR_MENOR, prisma_1.default.MAIOR_MAIOR)) {
|
|
7663
7708
|
const operador = this.simboloAnterior();
|
|
7664
7709
|
const direito = await this.adicaoOuSubtracao();
|
|
@@ -7729,8 +7774,19 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7729
7774
|
}
|
|
7730
7775
|
return expressao;
|
|
7731
7776
|
}
|
|
7777
|
+
async ternario() {
|
|
7778
|
+
let expressaoOuCondicao = await this.ou();
|
|
7779
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.INTERROGACAO)) {
|
|
7780
|
+
const operador = this.simboloAnterior();
|
|
7781
|
+
const caminhoEntao = await this.e();
|
|
7782
|
+
this.consumir(prisma_1.default.OU, "Esperado palavra reservada 'ou' após caminho positivo em operador ternário.");
|
|
7783
|
+
const caminhoSenao = await this.ternario();
|
|
7784
|
+
expressaoOuCondicao = new construtos_1.SeTernario(this.hashArquivo, expressaoOuCondicao, caminhoEntao, operador, caminhoSenao);
|
|
7785
|
+
}
|
|
7786
|
+
return expressaoOuCondicao;
|
|
7787
|
+
}
|
|
7732
7788
|
async atribuir() {
|
|
7733
|
-
const expressao = await this.
|
|
7789
|
+
const expressao = await this.ternario();
|
|
7734
7790
|
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.IGUAL) ||
|
|
7735
7791
|
this.verificarSeSimboloAtualEIgualA(prisma_1.default.MAIS_IGUAL)) {
|
|
7736
7792
|
const igual = this.simboloAnterior();
|
|
@@ -7782,7 +7838,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7782
7838
|
}
|
|
7783
7839
|
this.consumir(prisma_1.default.FIM, "Esperado 'fim' após o bloco.");
|
|
7784
7840
|
this.pilhaEscopos.removerUltimo();
|
|
7785
|
-
return declaracoes;
|
|
7841
|
+
return declaracoes.filter((d) => d);
|
|
7786
7842
|
}
|
|
7787
7843
|
async declaracaoDeLocal() {
|
|
7788
7844
|
const identificador = this.consumir(prisma_1.default.IDENTIFICADOR, 'Esperado nome de variável.');
|
|
@@ -7807,6 +7863,65 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7807
7863
|
this.blocos -= 1;
|
|
7808
7864
|
}
|
|
7809
7865
|
}
|
|
7866
|
+
async declaracaoEscolha() {
|
|
7867
|
+
try {
|
|
7868
|
+
this.blocos += 1;
|
|
7869
|
+
const condicao = await this.expressao();
|
|
7870
|
+
const caminhos = [];
|
|
7871
|
+
let caminhoPadrao = null;
|
|
7872
|
+
while (!this.verificarTipoSimboloAtual(prisma_1.default.FIM) && !this.estaNoFinal()) {
|
|
7873
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.CASO)) {
|
|
7874
|
+
const caminhoCondicoes = [await this.expressao()];
|
|
7875
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.CASO)) {
|
|
7876
|
+
caminhoCondicoes.push(await this.expressao());
|
|
7877
|
+
}
|
|
7878
|
+
this.consumir(prisma_1.default.ENTAO, "Esperado palavra reservada 'entao' ou 'então' após valor do 'caso'.");
|
|
7879
|
+
const declaracoes = [];
|
|
7880
|
+
while (!this.estaNoFinal() &&
|
|
7881
|
+
![
|
|
7882
|
+
prisma_1.default.CASO,
|
|
7883
|
+
prisma_1.default.PADRAO,
|
|
7884
|
+
prisma_1.default.FIM,
|
|
7885
|
+
].includes(this.simbolos[this.atual].tipo)) {
|
|
7886
|
+
declaracoes.push(await this.resolverDeclaracaoForaDeBloco());
|
|
7887
|
+
}
|
|
7888
|
+
caminhos.push({
|
|
7889
|
+
condicoes: caminhoCondicoes,
|
|
7890
|
+
declaracoes: declaracoes.filter((d) => d),
|
|
7891
|
+
});
|
|
7892
|
+
}
|
|
7893
|
+
else if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.PADRAO)) {
|
|
7894
|
+
if (caminhoPadrao !== null) {
|
|
7895
|
+
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.simbolos[this.atual], "Você só pode ter um 'padrao' em cada declaração de 'escolha'.");
|
|
7896
|
+
this.erros.push(excecao);
|
|
7897
|
+
throw excecao;
|
|
7898
|
+
}
|
|
7899
|
+
this.consumir(prisma_1.default.ENTAO, "Esperado palavra reservada 'entao' ou 'então' após declaração do 'padrao'.");
|
|
7900
|
+
const declaracoes = [];
|
|
7901
|
+
while (!this.estaNoFinal() &&
|
|
7902
|
+
![
|
|
7903
|
+
prisma_1.default.CASO,
|
|
7904
|
+
prisma_1.default.PADRAO,
|
|
7905
|
+
prisma_1.default.FIM,
|
|
7906
|
+
].includes(this.simbolos[this.atual].tipo)) {
|
|
7907
|
+
declaracoes.push(await this.resolverDeclaracaoForaDeBloco());
|
|
7908
|
+
}
|
|
7909
|
+
caminhoPadrao = {
|
|
7910
|
+
condicoes: [],
|
|
7911
|
+
declaracoes: declaracoes.filter((d) => d),
|
|
7912
|
+
};
|
|
7913
|
+
}
|
|
7914
|
+
else {
|
|
7915
|
+
throw this.erro(this.simbolos[this.atual], "Esperado 'caso', 'padrao' ou 'fim' em declaração 'escolha'.");
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7918
|
+
this.consumir(prisma_1.default.FIM, "Esperado palavra-chave 'fim' para fechamento de declaração 'escolha'.");
|
|
7919
|
+
return new declaracoes_1.Escolha(condicao, caminhos, caminhoPadrao);
|
|
7920
|
+
}
|
|
7921
|
+
finally {
|
|
7922
|
+
this.blocos -= 1;
|
|
7923
|
+
}
|
|
7924
|
+
}
|
|
7810
7925
|
async declaracaoSe() {
|
|
7811
7926
|
const simboloSe = this.simbolos[this.atual];
|
|
7812
7927
|
const condicao = await this.expressao();
|
|
@@ -7817,17 +7932,57 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7817
7932
|
} while (!this.estaNoFinal() &&
|
|
7818
7933
|
![prisma_1.default.SENAO, prisma_1.default.SENÃO, prisma_1.default.FIM].includes(this.simbolos[this.atual].tipo));
|
|
7819
7934
|
let caminhoSenao = null;
|
|
7935
|
+
let fimConsumidoNoCaminhoSenao = false;
|
|
7820
7936
|
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.SENAO, prisma_1.default.SENÃO)) {
|
|
7821
7937
|
const simboloSenao = this.simbolos[this.atual - 1];
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
}
|
|
7826
|
-
|
|
7938
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.SE)) {
|
|
7939
|
+
caminhoSenao = await this.declaracaoSe();
|
|
7940
|
+
fimConsumidoNoCaminhoSenao = true;
|
|
7941
|
+
}
|
|
7942
|
+
else {
|
|
7943
|
+
const declaracoesSenao = [];
|
|
7944
|
+
do {
|
|
7945
|
+
declaracoesSenao.push(await this.resolverDeclaracaoForaDeBloco());
|
|
7946
|
+
} while (![prisma_1.default.FIM].includes(this.simbolos[this.atual].tipo));
|
|
7947
|
+
caminhoSenao = new declaracoes_1.Bloco(this.hashArquivo, Number(simboloSenao.linha), declaracoesSenao.filter((d) => d));
|
|
7948
|
+
}
|
|
7949
|
+
}
|
|
7950
|
+
if (!fimConsumidoNoCaminhoSenao) {
|
|
7951
|
+
this.consumir(prisma_1.default.FIM, "Esperado palavra-chave 'fim' para fechamento de declaração 'se'.");
|
|
7827
7952
|
}
|
|
7828
|
-
this.consumir(prisma_1.default.FIM, "Esperado palavra-chave 'fimse' para fechamento de declaração 'se'.");
|
|
7829
7953
|
return new declaracoes_1.Se(condicao, new declaracoes_1.Bloco(this.hashArquivo, Number(simboloSe.linha), declaracoes.filter((d) => d)), [], caminhoSenao);
|
|
7830
7954
|
}
|
|
7955
|
+
async declaracaoTente() {
|
|
7956
|
+
const simboloTente = this.simboloAnterior();
|
|
7957
|
+
const blocoTente = [];
|
|
7958
|
+
while (!this.estaNoFinal() &&
|
|
7959
|
+
![
|
|
7960
|
+
prisma_1.default.PEGUE,
|
|
7961
|
+
prisma_1.default.FINALMENTE,
|
|
7962
|
+
prisma_1.default.FIM,
|
|
7963
|
+
].includes(this.simbolos[this.atual].tipo)) {
|
|
7964
|
+
blocoTente.push(await this.resolverDeclaracaoForaDeBloco());
|
|
7965
|
+
}
|
|
7966
|
+
let blocoPegue = null;
|
|
7967
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.PEGUE)) {
|
|
7968
|
+
const declaracoesPegue = [];
|
|
7969
|
+
while (!this.estaNoFinal() &&
|
|
7970
|
+
![prisma_1.default.FINALMENTE, prisma_1.default.FIM].includes(this.simbolos[this.atual].tipo)) {
|
|
7971
|
+
declaracoesPegue.push(await this.resolverDeclaracaoForaDeBloco());
|
|
7972
|
+
}
|
|
7973
|
+
blocoPegue = declaracoesPegue.filter((d) => d);
|
|
7974
|
+
}
|
|
7975
|
+
let blocoFinalmente = null;
|
|
7976
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.FINALMENTE)) {
|
|
7977
|
+
const declaracoesFinalmente = [];
|
|
7978
|
+
while (!this.estaNoFinal() && !this.verificarTipoSimboloAtual(prisma_1.default.FIM)) {
|
|
7979
|
+
declaracoesFinalmente.push(await this.resolverDeclaracaoForaDeBloco());
|
|
7980
|
+
}
|
|
7981
|
+
blocoFinalmente = declaracoesFinalmente.filter((d) => d);
|
|
7982
|
+
}
|
|
7983
|
+
this.consumir(prisma_1.default.FIM, "Esperado palavra-chave 'fim' para fechamento de declaração 'tente'.");
|
|
7984
|
+
return new declaracoes_1.Tente(simboloTente.hashArquivo, Number(simboloTente.linha), blocoTente.filter((d) => d), blocoPegue, null, blocoFinalmente);
|
|
7985
|
+
}
|
|
7831
7986
|
async declaracaoQuebre() {
|
|
7832
7987
|
if (this.blocos < 1) {
|
|
7833
7988
|
throw this.erro(this.simboloAnterior(), "'quebre' deve estar dentro de um laço de repetição.");
|
|
@@ -7911,11 +8066,15 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7911
8066
|
return null;
|
|
7912
8067
|
case prisma_1.default.ENTAO:
|
|
7913
8068
|
case prisma_1.default.INICIO:
|
|
8069
|
+
case prisma_1.default.FAZER:
|
|
7914
8070
|
const simboloInicioBloco = this.avancarEDevolverAnterior();
|
|
7915
8071
|
return new declaracoes_1.Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), await this.blocoEscopo());
|
|
7916
8072
|
case prisma_1.default.ENQUANTO:
|
|
7917
8073
|
this.avancarEDevolverAnterior();
|
|
7918
8074
|
return await this.declaracaoEnquanto();
|
|
8075
|
+
case prisma_1.default.ESCOLHA:
|
|
8076
|
+
this.avancarEDevolverAnterior();
|
|
8077
|
+
return await this.declaracaoEscolha();
|
|
7919
8078
|
case prisma_1.default.IDENTIFICADOR:
|
|
7920
8079
|
const proximoSimbolo = this.simbolos[this.atual + 1];
|
|
7921
8080
|
if (proximoSimbolo && proximoSimbolo.tipo === prisma_1.default.IGUAL) {
|
|
@@ -7937,6 +8096,9 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7937
8096
|
case prisma_1.default.RETORNE:
|
|
7938
8097
|
this.avancarEDevolverAnterior();
|
|
7939
8098
|
return await this.declaracaoRetorna();
|
|
8099
|
+
case prisma_1.default.TENTE:
|
|
8100
|
+
this.avancarEDevolverAnterior();
|
|
8101
|
+
return await this.declaracaoTente();
|
|
7940
8102
|
case prisma_1.default.LOCAL:
|
|
7941
8103
|
this.avancarEDevolverAnterior();
|
|
7942
8104
|
return await this.declaracaoDeLocal();
|
|
@@ -7979,20 +8141,40 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7979
8141
|
console.log(inicializador.constructor.name);
|
|
7980
8142
|
}
|
|
7981
8143
|
}
|
|
8144
|
+
async declaracaoParaCada(simboloPara) {
|
|
8145
|
+
const variavelIteracao = this.consumir(prisma_1.default.IDENTIFICADOR, "Esperado identificador de variável após 'para cada'.");
|
|
8146
|
+
this.consumir(prisma_1.default.EM, "Esperado palavra reservada 'em' após variável de iteração.");
|
|
8147
|
+
const vetorOuDicionario = await this.expressao();
|
|
8148
|
+
this.consumir(prisma_1.default.INICIO, `espera-se 'inicio' proximo a '${this.simbolos[this.atual].lexema}'.`);
|
|
8149
|
+
this.pilhaEscopos.definirInformacoesVariavel(variavelIteracao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(variavelIteracao.lexema, 'qualquer'));
|
|
8150
|
+
const declaracoesBlocoParaCada = [];
|
|
8151
|
+
while (!this.estaNoFinal() && !this.verificarTipoSimboloAtual(prisma_1.default.FIM)) {
|
|
8152
|
+
declaracoesBlocoParaCada.push(await this.resolverDeclaracaoForaDeBloco());
|
|
8153
|
+
}
|
|
8154
|
+
this.consumir(prisma_1.default.FIM, "Esperado 'fim' após bloco do para cada.");
|
|
8155
|
+
const corpo = new declaracoes_1.Bloco(this.hashArquivo, Number(simboloPara.linha) + 1, declaracoesBlocoParaCada.filter((d) => d));
|
|
8156
|
+
return new declaracoes_1.ParaCada(this.hashArquivo, Number(simboloPara.linha), new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'qualquer'), vetorOuDicionario, corpo);
|
|
8157
|
+
}
|
|
7982
8158
|
async declaracaoPara() {
|
|
7983
8159
|
try {
|
|
7984
8160
|
this.blocos += 1;
|
|
7985
8161
|
const simboloPara = this.avancarEDevolverAnterior();
|
|
8162
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.CADA)) {
|
|
8163
|
+
return await this.declaracaoParaCada(simboloPara);
|
|
8164
|
+
}
|
|
7986
8165
|
const variavelIteracao = this.consumir(prisma_1.default.IDENTIFICADOR, "Esperado identificador de variável após 'para'.");
|
|
7987
8166
|
this.consumir(prisma_1.default.IGUAL, `'=' or 'em' esperado próximo a '${this.simbolos[this.atual].lexema}'.`);
|
|
7988
8167
|
const literalOuVariavelInicio = await this.adicaoOuSubtracao();
|
|
7989
8168
|
this.consumir(prisma_1.default.VIRGULA, `Espera-se '=' próximo a '${this.simbolos[this.atual].lexema}'.`);
|
|
7990
8169
|
const literalOuVariavelFim = await this.adicaoOuSubtracao();
|
|
7991
8170
|
let operadorCondicao = new lexador_1.Simbolo(prisma_1.default.MENOR_IGUAL, '<=', null, Number(simboloPara.linha), this.hashArquivo);
|
|
7992
|
-
let operadorCondicaoIncremento = new lexador_1.Simbolo(prisma_1.default.MENOR, '<', null, Number(simboloPara.linha), this.hashArquivo);
|
|
7993
8171
|
let passo = new construtos_1.Literal(this.hashArquivo, Number(simboloPara.linha), 1);
|
|
7994
|
-
|
|
7995
|
-
|
|
8172
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.VIRGULA)) {
|
|
8173
|
+
passo = await this.adicaoOuSubtracao();
|
|
8174
|
+
}
|
|
8175
|
+
if (!this.verificarSeSimboloAtualEIgualA(prisma_1.default.INICIO, prisma_1.default.FAZER)) {
|
|
8176
|
+
throw this.erro(this.simbolos[this.atual], `espera-se 'inicio' ou 'fazer' proximo a '${this.simbolos[this.atual].lexema}'.`);
|
|
8177
|
+
}
|
|
7996
8178
|
// Aqui já é seguro inicializar a variável.
|
|
7997
8179
|
this.pilhaEscopos.definirInformacoesVariavel(variavelIteracao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(variavelIteracao.lexema, 'inteiro'));
|
|
7998
8180
|
const declaracoesBlocoPara = [];
|
|
@@ -8004,14 +8186,12 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
8004
8186
|
this.avancarEDevolverAnterior(); // fim
|
|
8005
8187
|
const corpo = new declaracoes_1.Bloco(this.hashArquivo, Number(simboloPara.linha) + 1, declaracoesBlocoPara.filter((d) => d));
|
|
8006
8188
|
const para = new declaracoes_1.Para(this.hashArquivo, Number(simboloPara.linha),
|
|
8007
|
-
// Inicialização.
|
|
8008
|
-
new declaracoes_1.
|
|
8189
|
+
// Inicialização: declara a variável de iteração.
|
|
8190
|
+
new declaracoes_1.Var(variavelIteracao, literalOuVariavelInicio, 'inteiro'),
|
|
8009
8191
|
// Condição.
|
|
8010
8192
|
new construtos_1.Binario(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), operadorCondicao, literalOuVariavelFim),
|
|
8011
|
-
// Incremento
|
|
8012
|
-
new construtos_1.
|
|
8013
|
-
para.blocoPosExecucao = corpo;
|
|
8014
|
-
para.resolverIncrementoEmExecucao = resolverIncrementoEmExecucao;
|
|
8193
|
+
// Incremento simples.
|
|
8194
|
+
new construtos_1.Atribuir(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), new construtos_1.Binario(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), new lexador_1.Simbolo(prisma_1.default.ADICAO, '+', null, Number(simboloPara.linha), this.hashArquivo), passo)), corpo);
|
|
8015
8195
|
return para;
|
|
8016
8196
|
}
|
|
8017
8197
|
finally {
|
|
@@ -8036,6 +8216,48 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
8036
8216
|
return null;
|
|
8037
8217
|
}
|
|
8038
8218
|
}
|
|
8219
|
+
async metodoClassePrisma(construtor) {
|
|
8220
|
+
const simbolo = construtor
|
|
8221
|
+
? new lexador_1.Simbolo(prisma_1.default.CONSTRUTOR, 'construtor', null, Number(this.simboloAnterior().linha), this.hashArquivo)
|
|
8222
|
+
: this.consumir(prisma_1.default.IDENTIFICADOR, 'Esperado nome do método.');
|
|
8223
|
+
this.consumir(prisma_1.default.PARENTESE_ESQUERDO, "Esperado '(' após nome do método.");
|
|
8224
|
+
let parametros = [];
|
|
8225
|
+
if (!this.verificarTipoSimboloAtual(prisma_1.default.PARENTESE_DIREITO)) {
|
|
8226
|
+
parametros = await this.logicaComumParametros();
|
|
8227
|
+
}
|
|
8228
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
8229
|
+
this.consumir(prisma_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do corpo do método.");
|
|
8230
|
+
const declaracoesCorpo = [];
|
|
8231
|
+
while (!this.estaNoFinal() && !this.verificarTipoSimboloAtual(prisma_1.default.CHAVE_DIREITA)) {
|
|
8232
|
+
declaracoesCorpo.push(await this.resolverDeclaracaoForaDeBloco());
|
|
8233
|
+
}
|
|
8234
|
+
this.consumir(prisma_1.default.CHAVE_DIREITA, "Esperado '}' após o corpo do método.");
|
|
8235
|
+
const corpoDaFuncao = new construtos_1.FuncaoConstruto(this.hashArquivo, Number(simbolo.linha), parametros, declaracoesCorpo.filter((d) => d), 'qualquer', false);
|
|
8236
|
+
const tipoDaFuncao = `função<${corpoDaFuncao.tipo}>`;
|
|
8237
|
+
return new declaracoes_1.FuncaoDeclaracao(simbolo, corpoDaFuncao, tipoDaFuncao);
|
|
8238
|
+
}
|
|
8239
|
+
propriedadesDeclaradasEmMetodo(metodo) {
|
|
8240
|
+
const propriedades = [];
|
|
8241
|
+
const nomesPropriedades = new Set();
|
|
8242
|
+
for (const declaracao of metodo.funcao.corpo) {
|
|
8243
|
+
if (!(declaracao instanceof declaracoes_1.Expressao)) {
|
|
8244
|
+
continue;
|
|
8245
|
+
}
|
|
8246
|
+
if (!(declaracao.expressao instanceof construtos_1.DefinirValor)) {
|
|
8247
|
+
continue;
|
|
8248
|
+
}
|
|
8249
|
+
if (!(declaracao.expressao.objeto instanceof construtos_1.Isto)) {
|
|
8250
|
+
continue;
|
|
8251
|
+
}
|
|
8252
|
+
const nomePropriedade = declaracao.expressao.nome.lexema;
|
|
8253
|
+
if (nomesPropriedades.has(nomePropriedade)) {
|
|
8254
|
+
continue;
|
|
8255
|
+
}
|
|
8256
|
+
nomesPropriedades.add(nomePropriedade);
|
|
8257
|
+
propriedades.push(new declaracoes_1.PropriedadeClasse(declaracao.expressao.nome, 'qualquer'));
|
|
8258
|
+
}
|
|
8259
|
+
return propriedades;
|
|
8260
|
+
}
|
|
8039
8261
|
async declaracaoDeClasse() {
|
|
8040
8262
|
const simbolo = this.consumir(prisma_1.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
8041
8263
|
let superClasse = null;
|
|
@@ -8051,47 +8273,71 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
8051
8273
|
(this.verificarTipoSimboloAtual(prisma_1.default.CONSTRUTOR) ||
|
|
8052
8274
|
this.verificarTipoSimboloAtual(prisma_1.default.FUNCAO) ||
|
|
8053
8275
|
this.verificarTipoSimboloAtual(prisma_1.default.FUNÇÃO))) {
|
|
8054
|
-
|
|
8055
|
-
|
|
8276
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.CONSTRUTOR)) {
|
|
8277
|
+
metodos.push(await this.metodoClassePrisma(true));
|
|
8278
|
+
continue;
|
|
8279
|
+
}
|
|
8280
|
+
this.verificarSeSimboloAtualEIgualA(prisma_1.default.FUNCAO, prisma_1.default.FUNÇÃO);
|
|
8281
|
+
metodos.push(await this.metodoClassePrisma(false));
|
|
8056
8282
|
}
|
|
8057
8283
|
this.consumir(prisma_1.default.CHAVE_DIREITA, "Esperado '}' após métodos da classe.");
|
|
8284
|
+
const propriedades = [];
|
|
8285
|
+
const nomesPropriedades = new Set();
|
|
8286
|
+
for (const metodo of metodos) {
|
|
8287
|
+
const propriedadesDoMetodo = this.propriedadesDeclaradasEmMetodo(metodo);
|
|
8288
|
+
for (const propriedade of propriedadesDoMetodo) {
|
|
8289
|
+
if (nomesPropriedades.has(propriedade.nome.lexema)) {
|
|
8290
|
+
continue;
|
|
8291
|
+
}
|
|
8292
|
+
nomesPropriedades.add(propriedade.nome.lexema);
|
|
8293
|
+
propriedades.push(propriedade);
|
|
8294
|
+
}
|
|
8295
|
+
}
|
|
8058
8296
|
this.superclasseAtual = undefined;
|
|
8059
|
-
const definicaoClasse = new declaracoes_1.Classe(simbolo, superClasse ? [superClasse] : [], metodos);
|
|
8297
|
+
const definicaoClasse = new declaracoes_1.Classe(simbolo, superClasse ? [superClasse] : [], metodos, propriedades);
|
|
8060
8298
|
this.tiposDefinidosEmCodigo[definicaoClasse.simbolo.lexema] = definicaoClasse;
|
|
8061
8299
|
return definicaoClasse;
|
|
8062
8300
|
}
|
|
8063
8301
|
inicializarPilhaEscopos() {
|
|
8064
8302
|
this.pilhaEscopos = new pilha_escopos_1.PilhaEscopos();
|
|
8065
8303
|
this.pilhaEscopos.empilhar(new informacao_escopo_1.InformacaoEscopo());
|
|
8066
|
-
//
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
new InformacaoElementoSintatico('
|
|
8070
|
-
);
|
|
8071
|
-
this.pilhaEscopos.definirInformacoesVariavel(
|
|
8072
|
-
'
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
);
|
|
8077
|
-
this.pilhaEscopos.definirInformacoesVariavel(
|
|
8078
|
-
'
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
);
|
|
8083
|
-
this.pilhaEscopos.definirInformacoesVariavel(
|
|
8084
|
-
'
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
);
|
|
8089
|
-
this.pilhaEscopos.definirInformacoesVariavel(
|
|
8090
|
-
|
|
8091
|
-
new InformacaoElementoSintatico('
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
8304
|
+
// Registrar funções nativas (built-ins) do Prisma no escopo do parser
|
|
8305
|
+
// para evitar erros de variável não definida durante análise semântica
|
|
8306
|
+
this.pilhaEscopos.definirInformacoesVariavel('tipo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tipo', 'função', true, [
|
|
8307
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
|
|
8308
|
+
]));
|
|
8309
|
+
this.pilhaEscopos.definirInformacoesVariavel('poe', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('poe', 'função', true, [
|
|
8310
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valores', 'qualquer'),
|
|
8311
|
+
]));
|
|
8312
|
+
this.pilhaEscopos.definirInformacoesVariavel('tamanho', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tamanho', 'número', true, [
|
|
8313
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('objeto', 'qualquer'),
|
|
8314
|
+
]));
|
|
8315
|
+
this.pilhaEscopos.definirInformacoesVariavel('pares', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('pares', 'tabela', true, [
|
|
8316
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tabela', 'tabela'),
|
|
8317
|
+
]));
|
|
8318
|
+
this.pilhaEscopos.definirInformacoesVariavel('ipares', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('ipares', 'tabela', true, [
|
|
8319
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tabela', 'tabela'),
|
|
8320
|
+
]));
|
|
8321
|
+
this.pilhaEscopos.definirInformacoesVariavel('convnumero', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('convnumero', 'número', true, [
|
|
8322
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
|
|
8323
|
+
]));
|
|
8324
|
+
this.pilhaEscopos.definirInformacoesVariavel('convstring', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('convstring', 'texto', true, [
|
|
8325
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
|
|
8326
|
+
]));
|
|
8327
|
+
this.pilhaEscopos.definirInformacoesVariavel('aleatorio', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('aleatorio', 'função', true, []));
|
|
8328
|
+
this.pilhaEscopos.definirInformacoesVariavel('aleatorio_entre', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('aleatorio_entre', 'número', true, [
|
|
8329
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('minimo', 'número'),
|
|
8330
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('maximo', 'número'),
|
|
8331
|
+
]));
|
|
8332
|
+
this.pilhaEscopos.definirInformacoesVariavel('coletelixo', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('coletelixo', 'número', true, [
|
|
8333
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('acao', 'texto'),
|
|
8334
|
+
]));
|
|
8335
|
+
this.pilhaEscopos.definirInformacoesVariavel('piso', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('piso', 'número', true, [
|
|
8336
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('n', 'número'),
|
|
8337
|
+
]));
|
|
8338
|
+
this.pilhaEscopos.definirInformacoesVariavel('teto', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('teto', 'número', true, [
|
|
8339
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('n', 'número'),
|
|
8340
|
+
]));
|
|
8095
8341
|
}
|
|
8096
8342
|
async analisar(retornoLexador, hashArquivo) {
|
|
8097
8343
|
const inicioAnalise = (0, browser_process_hrtime_1.default)();
|
|
@@ -8124,7 +8370,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
8124
8370
|
}
|
|
8125
8371
|
exports.AvaliadorSintaticoPrisma = AvaliadorSintaticoPrisma;
|
|
8126
8372
|
|
|
8127
|
-
},{"../../bibliotecas/primitivas-dicionario":29,"../../bibliotecas/primitivas-numero":30,"../../bibliotecas/primitivas-texto":31,"../../bibliotecas/primitivas-vetor":32,"../../construtos":62,"../../declaracoes":110,"../../inferenciador":137,"../../informacao-elemento-sintatico":138,"../../lexador":207,"../../tipos-de-simbolos/prisma":228,"../avaliador-sintatico-base":9,"../comum":11,"../informacao-escopo":22,"../pilha-escopos":26,"browser-process-hrtime":415}],16:[function(require,module,exports){
|
|
8373
|
+
},{"../../bibliotecas/primitivas-dicionario":29,"../../bibliotecas/primitivas-numero":30,"../../bibliotecas/primitivas-texto":31,"../../bibliotecas/primitivas-vetor":32,"../../construtos":62,"../../declaracoes":110,"../../inferenciador":137,"../../informacao-elemento-sintatico":138,"../../lexador":207,"../../tipos-de-simbolos/prisma":228,"../avaliador-sintatico-base":9,"../comum":11,"../erro-avaliador-sintatico":20,"../informacao-escopo":22,"../pilha-escopos":26,"browser-process-hrtime":415}],16:[function(require,module,exports){
|
|
8128
8374
|
"use strict";
|
|
8129
8375
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8130
8376
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -8313,6 +8559,16 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8313
8559
|
this.avancarEDevolverAnterior();
|
|
8314
8560
|
return new construtos_1.ExpressaoRegular(this.hashArquivo, simboloAtual, valor);
|
|
8315
8561
|
}
|
|
8562
|
+
case tenda_1.default.BIBLIOTECA_GLOBAL: {
|
|
8563
|
+
const simboloBiblioteca = this.avancarEDevolverAnterior();
|
|
8564
|
+
return new construtos_1.Variavel(this.hashArquivo, simboloBiblioteca, 'qualquer');
|
|
8565
|
+
}
|
|
8566
|
+
case tenda_1.default.INFINITO:
|
|
8567
|
+
this.avancarEDevolverAnterior();
|
|
8568
|
+
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), Infinity, 'número');
|
|
8569
|
+
case tenda_1.default.NAN:
|
|
8570
|
+
this.avancarEDevolverAnterior();
|
|
8571
|
+
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), NaN, 'número');
|
|
8316
8572
|
case tenda_1.default.FALSO:
|
|
8317
8573
|
this.avancarEDevolverAnterior();
|
|
8318
8574
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), false, 'lógico');
|
|
@@ -8371,6 +8627,7 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8371
8627
|
throw this.erro(this.simbolos[this.atual], 'Esperado expressão.');
|
|
8372
8628
|
}
|
|
8373
8629
|
async chamar() {
|
|
8630
|
+
var _a;
|
|
8374
8631
|
let expressao = await this.primario();
|
|
8375
8632
|
while (true) {
|
|
8376
8633
|
let tipoPrimitiva = undefined;
|
|
@@ -8378,7 +8635,21 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8378
8635
|
expressao = await this.finalizarChamada(expressao, tipoPrimitiva);
|
|
8379
8636
|
}
|
|
8380
8637
|
else if (this.verificarSeSimboloAtualEIgualA(tenda_1.default.PONTO)) {
|
|
8381
|
-
|
|
8638
|
+
// Alguns tokens de biblioteca global são palavras reservadas (ex: `exiba`, `leia`, `entrada`),
|
|
8639
|
+
// mas precisam ser aceitos como nomes de métodos após o ponto.
|
|
8640
|
+
const tiposAceitosComoNomeDeMetodo = [
|
|
8641
|
+
tenda_1.default.IDENTIFICADOR,
|
|
8642
|
+
tenda_1.default.EXIBA,
|
|
8643
|
+
tenda_1.default.LEIA,
|
|
8644
|
+
tenda_1.default.ENTRADA,
|
|
8645
|
+
];
|
|
8646
|
+
let nome;
|
|
8647
|
+
if (tiposAceitosComoNomeDeMetodo.includes((_a = this.simbolos[this.atual]) === null || _a === void 0 ? void 0 : _a.tipo)) {
|
|
8648
|
+
nome = this.avancarEDevolverAnterior();
|
|
8649
|
+
}
|
|
8650
|
+
else {
|
|
8651
|
+
nome = this.consumir(tenda_1.default.IDENTIFICADOR, "Esperado nome de método ou propriedade após '.'.");
|
|
8652
|
+
}
|
|
8382
8653
|
tipoPrimitiva = expressao.tipo;
|
|
8383
8654
|
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
8384
8655
|
}
|
|
@@ -8919,7 +9190,9 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8919
9190
|
if (this.primitivasConhecidas.hasOwnProperty(entidadeChamadaAcessoMetodoOuPropriedade.simbolo.lexema)) {
|
|
8920
9191
|
return this.primitivasConhecidas[entidadeChamadaAcessoMetodoOuPropriedade.simbolo.lexema].tipo;
|
|
8921
9192
|
}
|
|
8922
|
-
|
|
9193
|
+
// Para métodos de namespaces da biblioteca global (Lista, Matemática, etc.),
|
|
9194
|
+
// o tipo não é conhecido estaticamente. Retorna 'qualquer'.
|
|
9195
|
+
return 'qualquer';
|
|
8923
9196
|
case construtos_1.AcessoPropriedade:
|
|
8924
9197
|
const entidadeChamadaAcessoPropriedade = entidadeChamadaChamada;
|
|
8925
9198
|
return entidadeChamadaAcessoPropriedade.tipoRetornoPropriedade;
|
|
@@ -9067,6 +9340,10 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
9067
9340
|
inicializarPilhaEscopos() {
|
|
9068
9341
|
this.pilhaEscopos = new pilha_escopos_1.PilhaEscopos();
|
|
9069
9342
|
this.pilhaEscopos.empilhar(new informacao_escopo_1.InformacaoEscopo());
|
|
9343
|
+
// Registrar namespaces da biblioteca global de Tenda.
|
|
9344
|
+
for (const nomeBiblioteca of ['Data', 'Lista', 'Matemática', 'Saída', 'Texto']) {
|
|
9345
|
+
this.pilhaEscopos.definirInformacoesVariavel(nomeBiblioteca, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(nomeBiblioteca, 'qualquer'));
|
|
9346
|
+
}
|
|
9070
9347
|
// TODO: Escrever algum tipo de validação aqui.
|
|
9071
9348
|
for (const tipos of Object.values(this.tiposDeFerramentasExternas)) {
|
|
9072
9349
|
for (const [nomeTipo, tipo] of Object.entries(tipos)) {
|
|
@@ -10065,15 +10342,13 @@ async function aleatorio(interpretador) {
|
|
|
10065
10342
|
* @returns {Promise<number>} Um número real entre os valores máximo e mínimo especificados.
|
|
10066
10343
|
*/
|
|
10067
10344
|
async function aleatorioEntre(interpretador, minimo, maximo) {
|
|
10068
|
-
if (arguments.length <=
|
|
10345
|
+
if (arguments.length <= 1) {
|
|
10069
10346
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10070
10347
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
10071
10348
|
linha: interpretador.linhaDeclaracaoAtual,
|
|
10072
10349
|
}, 'A função recebe ao menos um parâmetro.'));
|
|
10073
10350
|
}
|
|
10074
|
-
const valorMinimo =
|
|
10075
|
-
? minimo.valor
|
|
10076
|
-
: minimo;
|
|
10351
|
+
const valorMinimo = interpretador.resolverValor(minimo);
|
|
10077
10352
|
if (arguments.length === 2) {
|
|
10078
10353
|
if (typeof valorMinimo !== 'number') {
|
|
10079
10354
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
@@ -10089,9 +10364,7 @@ async function aleatorioEntre(interpretador, minimo, maximo) {
|
|
|
10089
10364
|
linha: interpretador.linhaDeclaracaoAtual,
|
|
10090
10365
|
}, 'A quantidade de parâmetros máxima para esta função é 2.'));
|
|
10091
10366
|
}
|
|
10092
|
-
const valorMaximo =
|
|
10093
|
-
? maximo.valor
|
|
10094
|
-
: maximo;
|
|
10367
|
+
const valorMaximo = interpretador.resolverValor(maximo);
|
|
10095
10368
|
if (typeof valorMinimo !== 'number' || typeof valorMaximo !== 'number') {
|
|
10096
10369
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10097
10370
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
@@ -21087,6 +21360,27 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21087
21360
|
pontoInicializacaoBibliotecasGlobais() {
|
|
21088
21361
|
(0, comum_1.carregarBibliotecasGlobais)(this.pilhaEscoposExecucao);
|
|
21089
21362
|
}
|
|
21363
|
+
async avaliarArgumentosEscreva(argumentos) {
|
|
21364
|
+
if (this.constructor !== Interpretador) {
|
|
21365
|
+
return await super.avaliarArgumentosEscreva(argumentos);
|
|
21366
|
+
}
|
|
21367
|
+
let formatoTexto = '';
|
|
21368
|
+
for (const argumento of argumentos) {
|
|
21369
|
+
let resultadoAvaliacao = await this.avaliar(argumento);
|
|
21370
|
+
if (resultadoAvaliacao &&
|
|
21371
|
+
resultadoAvaliacao.hasOwnProperty &&
|
|
21372
|
+
resultadoAvaliacao.hasOwnProperty('valorRetornado')) {
|
|
21373
|
+
resultadoAvaliacao = resultadoAvaliacao.valorRetornado;
|
|
21374
|
+
}
|
|
21375
|
+
if (argumento instanceof construtos_1.Atribuir || argumento instanceof construtos_1.AtribuicaoPorIndice) {
|
|
21376
|
+
formatoTexto += `${argumento.paraTexto()} `;
|
|
21377
|
+
continue;
|
|
21378
|
+
}
|
|
21379
|
+
const valor = this.resolverValor(resultadoAvaliacao);
|
|
21380
|
+
formatoTexto += `${this.paraTexto(valor)} `;
|
|
21381
|
+
}
|
|
21382
|
+
return formatoTexto.trimEnd();
|
|
21383
|
+
}
|
|
21090
21384
|
resolverReferenciaMontao(referenciaMontao) {
|
|
21091
21385
|
const valorMontao = this.montao.obterReferencia(this.hashArquivoDeclaracaoAtual, this.linhaDeclaracaoAtual, referenciaMontao.endereco);
|
|
21092
21386
|
return valorMontao;
|
|
@@ -21248,7 +21542,9 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21248
21542
|
const nomeDecorador = decorador.nome.slice(1);
|
|
21249
21543
|
const variavelDecoradora = this.pilhaEscoposExecucao.obterVariavelPorNome(nomeDecorador);
|
|
21250
21544
|
const funcaoDecoradora = variavelDecoradora.valor;
|
|
21251
|
-
const resultado = await funcaoDecoradora.chamar(this, [
|
|
21545
|
+
const resultado = await funcaoDecoradora.chamar(this, [
|
|
21546
|
+
{ nome: null, valor: funcao },
|
|
21547
|
+
]);
|
|
21252
21548
|
funcao = this.resolverValorRecursivo(resultado);
|
|
21253
21549
|
}
|
|
21254
21550
|
}
|
|
@@ -22363,6 +22659,7 @@ const lexador_1 = require("../lexador");
|
|
|
22363
22659
|
const inferenciador_1 = require("../inferenciador");
|
|
22364
22660
|
const delegua_1 = __importDefault(require("../tipos-de-dados/delegua"));
|
|
22365
22661
|
const tiposNumericos = ['inteiro', 'número', 'numero', 'real', 'longo'];
|
|
22662
|
+
const tiposLogicos = ['logico', 'lógico'];
|
|
22366
22663
|
class PilhaEscoposExecucao {
|
|
22367
22664
|
constructor() {
|
|
22368
22665
|
this.pilha = [];
|
|
@@ -22394,6 +22691,8 @@ class PilhaEscoposExecucao {
|
|
|
22394
22691
|
return true;
|
|
22395
22692
|
if (tiposNumericos.includes(tipoVariavel) && tiposNumericos.includes(tipoValor))
|
|
22396
22693
|
return true;
|
|
22694
|
+
if (tiposLogicos.includes(tipoVariavel) && tiposLogicos.includes(tipoValor))
|
|
22695
|
+
return true;
|
|
22397
22696
|
return false;
|
|
22398
22697
|
}
|
|
22399
22698
|
converterValor(tipo, valor) {
|
|
@@ -22808,6 +23107,24 @@ class LexadorCalango {
|
|
|
22808
23107
|
const textoCompleto = this.codigo[this.linha].substring(this.inicioSimbolo + 1, this.atual);
|
|
22809
23108
|
this.simbolos.push(new simbolo_1.Simbolo(calango_2.default.TEXTO, textoCompleto, textoCompleto, linhaPrimeiroCaracter + 1, this.hashArquivo));
|
|
22810
23109
|
}
|
|
23110
|
+
analisarCaracter() {
|
|
23111
|
+
const linhaPrimeiroCaracter = this.linha;
|
|
23112
|
+
// Restringe leitura à linha atual (como analisarNumero), evitando
|
|
23113
|
+
// que avancar() mude this.linha e corrompa o cálculo do substring.
|
|
23114
|
+
while (this.simboloAtual() !== "'" && this.linha === linhaPrimeiroCaracter && !this.eFinalDoCodigo()) {
|
|
23115
|
+
this.avancar();
|
|
23116
|
+
}
|
|
23117
|
+
if (this.linha !== linhaPrimeiroCaracter || this.eFinalDoCodigo()) {
|
|
23118
|
+
this.erros.push({
|
|
23119
|
+
linha: linhaPrimeiroCaracter + 1,
|
|
23120
|
+
caractere: this.simboloAnterior(),
|
|
23121
|
+
mensagem: 'Caractere não finalizado.',
|
|
23122
|
+
});
|
|
23123
|
+
return;
|
|
23124
|
+
}
|
|
23125
|
+
const valorCaracter = this.codigo[linhaPrimeiroCaracter].substring(this.inicioSimbolo + 1, this.atual);
|
|
23126
|
+
this.simbolos.push(new simbolo_1.Simbolo(calango_2.default.LITERAL_CARACTER, valorCaracter, valorCaracter, linhaPrimeiroCaracter + 1, this.hashArquivo));
|
|
23127
|
+
}
|
|
22811
23128
|
analisarNumero() {
|
|
22812
23129
|
const linhaPrimeiroDigito = this.linha;
|
|
22813
23130
|
while (this.eDigito(this.simboloAtual()) && this.linha === linhaPrimeiroDigito) {
|
|
@@ -22870,6 +23187,23 @@ class LexadorCalango {
|
|
|
22870
23187
|
this.analisarTexto('"');
|
|
22871
23188
|
this.avancar();
|
|
22872
23189
|
break;
|
|
23190
|
+
case "'":
|
|
23191
|
+
this.avancar();
|
|
23192
|
+
this.analisarCaracter();
|
|
23193
|
+
this.avancar();
|
|
23194
|
+
break;
|
|
23195
|
+
case ':':
|
|
23196
|
+
this.adicionarSimbolo(calango_2.default.DOIS_PONTOS);
|
|
23197
|
+
this.avancar();
|
|
23198
|
+
break;
|
|
23199
|
+
case '[':
|
|
23200
|
+
this.adicionarSimbolo(calango_2.default.COLCHETE_ESQUERDO);
|
|
23201
|
+
this.avancar();
|
|
23202
|
+
break;
|
|
23203
|
+
case ']':
|
|
23204
|
+
this.adicionarSimbolo(calango_2.default.COLCHETE_DIREITO);
|
|
23205
|
+
this.avancar();
|
|
23206
|
+
break;
|
|
22873
23207
|
case '(':
|
|
22874
23208
|
this.adicionarSimbolo(calango_2.default.PARENTESE_ESQUERDO);
|
|
22875
23209
|
this.avancar();
|
|
@@ -22878,6 +23212,36 @@ class LexadorCalango {
|
|
|
22878
23212
|
this.adicionarSimbolo(calango_2.default.PARENTESE_DIREITO);
|
|
22879
23213
|
this.avancar();
|
|
22880
23214
|
break;
|
|
23215
|
+
case ',':
|
|
23216
|
+
this.adicionarSimbolo(calango_2.default.VIRGULA);
|
|
23217
|
+
this.avancar();
|
|
23218
|
+
break;
|
|
23219
|
+
case '+':
|
|
23220
|
+
this.adicionarSimbolo(calango_2.default.ADICAO);
|
|
23221
|
+
this.avancar();
|
|
23222
|
+
break;
|
|
23223
|
+
case '-':
|
|
23224
|
+
this.adicionarSimbolo(calango_2.default.SUBTRACAO);
|
|
23225
|
+
this.avancar();
|
|
23226
|
+
break;
|
|
23227
|
+
case '*':
|
|
23228
|
+
this.adicionarSimbolo(calango_2.default.MULTIPLICACAO);
|
|
23229
|
+
this.avancar();
|
|
23230
|
+
break;
|
|
23231
|
+
case '/':
|
|
23232
|
+
if (this.proximoSimbolo() === '/') {
|
|
23233
|
+
// Comentário de linha: consumir até ao fim da linha sem emitir símbolo.
|
|
23234
|
+
// Guardamos o número da linha para parar quando avancar() mudar para a próxima.
|
|
23235
|
+
const linhaComentario = this.linha;
|
|
23236
|
+
while (this.linha === linhaComentario && !this.eFinalDoCodigo()) {
|
|
23237
|
+
this.avancar();
|
|
23238
|
+
}
|
|
23239
|
+
}
|
|
23240
|
+
else {
|
|
23241
|
+
this.adicionarSimbolo(calango_2.default.DIVISAO);
|
|
23242
|
+
this.avancar();
|
|
23243
|
+
}
|
|
23244
|
+
break;
|
|
22881
23245
|
case '=':
|
|
22882
23246
|
this.adicionarSimbolo(calango_2.default.IGUAL_ATRIBUICAO);
|
|
22883
23247
|
this.avancar();
|
|
@@ -22898,10 +23262,22 @@ class LexadorCalango {
|
|
|
22898
23262
|
this.adicionarSimbolo(calango_2.default.MENOR_IGUAL, '<=');
|
|
22899
23263
|
this.avancar();
|
|
22900
23264
|
}
|
|
23265
|
+
else if (this.simboloAtual() === '>') {
|
|
23266
|
+
this.adicionarSimbolo(calango_2.default.DIFERENTE, '<>');
|
|
23267
|
+
this.avancar();
|
|
23268
|
+
}
|
|
22901
23269
|
else {
|
|
22902
23270
|
this.adicionarSimbolo(calango_2.default.MENOR);
|
|
22903
23271
|
}
|
|
22904
23272
|
break;
|
|
23273
|
+
case '%':
|
|
23274
|
+
this.adicionarSimbolo(calango_2.default.MODULO);
|
|
23275
|
+
this.avancar();
|
|
23276
|
+
break;
|
|
23277
|
+
case '^':
|
|
23278
|
+
this.adicionarSimbolo(calango_2.default.EXPONENCIACAO);
|
|
23279
|
+
this.avancar();
|
|
23280
|
+
break;
|
|
22905
23281
|
default:
|
|
22906
23282
|
if (this.eDigito(caractere))
|
|
22907
23283
|
this.analisarNumero();
|
|
@@ -23555,15 +23931,13 @@ class LexadorPitugues {
|
|
|
23555
23931
|
}
|
|
23556
23932
|
analisarNumero() {
|
|
23557
23933
|
const linhaInicial = this.linha;
|
|
23558
|
-
while (this.linha === linhaInicial &&
|
|
23559
|
-
this.eDigito(this.simboloAtual()))
|
|
23934
|
+
while (this.linha === linhaInicial && this.eDigito(this.simboloAtual()))
|
|
23560
23935
|
this.avancar();
|
|
23561
23936
|
const temPonto = this.simboloAtual() === '.';
|
|
23562
23937
|
const proximoEhDigito = this.eDigito(this.proximoSimbolo());
|
|
23563
23938
|
if (this.linha === linhaInicial && temPonto && proximoEhDigito) {
|
|
23564
23939
|
this.avancar();
|
|
23565
|
-
while (this.linha === linhaInicial &&
|
|
23566
|
-
this.eDigito(this.simboloAtual()))
|
|
23940
|
+
while (this.linha === linhaInicial && this.eDigito(this.simboloAtual()))
|
|
23567
23941
|
this.avancar();
|
|
23568
23942
|
}
|
|
23569
23943
|
let numeroCompleto;
|
|
@@ -24332,7 +24706,17 @@ class LexadorPrisma {
|
|
|
24332
24706
|
this.avancar();
|
|
24333
24707
|
break;
|
|
24334
24708
|
case '.':
|
|
24335
|
-
this.
|
|
24709
|
+
this.avancar();
|
|
24710
|
+
if (this.simboloAtual() === '.') {
|
|
24711
|
+
this.avancar();
|
|
24712
|
+
this.adicionarSimbolo(prisma_2.default.CONCATENACAO);
|
|
24713
|
+
}
|
|
24714
|
+
else {
|
|
24715
|
+
this.adicionarSimbolo(prisma_2.default.PONTO);
|
|
24716
|
+
}
|
|
24717
|
+
break;
|
|
24718
|
+
case '#':
|
|
24719
|
+
this.adicionarSimbolo(prisma_2.default.COMPRIMENTO);
|
|
24336
24720
|
this.avancar();
|
|
24337
24721
|
break;
|
|
24338
24722
|
case ';':
|
|
@@ -24343,6 +24727,10 @@ class LexadorPrisma {
|
|
|
24343
24727
|
this.adicionarSimbolo(prisma_2.default.DOIS_PONTOS);
|
|
24344
24728
|
this.avancar();
|
|
24345
24729
|
break;
|
|
24730
|
+
case '?':
|
|
24731
|
+
this.adicionarSimbolo(prisma_2.default.INTERROGACAO);
|
|
24732
|
+
this.avancar();
|
|
24733
|
+
break;
|
|
24346
24734
|
case '=':
|
|
24347
24735
|
this.avancar();
|
|
24348
24736
|
if (this.simboloAtual() === '=') {
|
|
@@ -24424,10 +24812,8 @@ class LexadorPrisma {
|
|
|
24424
24812
|
case '/':
|
|
24425
24813
|
this.avancar();
|
|
24426
24814
|
if (this.simboloAtual() === '/') {
|
|
24427
|
-
// Comentário de linha
|
|
24428
|
-
|
|
24429
|
-
this.avancar();
|
|
24430
|
-
}
|
|
24815
|
+
// Comentário de linha — ignorar até o final da linha
|
|
24816
|
+
this.atual = this.codigo[this.linha].length;
|
|
24431
24817
|
}
|
|
24432
24818
|
else if (this.simboloAtual() === '*') {
|
|
24433
24819
|
// Comentário de bloco
|
|
@@ -24462,8 +24848,14 @@ class LexadorPrisma {
|
|
|
24462
24848
|
this.avancar();
|
|
24463
24849
|
break;
|
|
24464
24850
|
case '~':
|
|
24465
|
-
this.adicionarSimbolo(prisma_2.default.BIT_NOT);
|
|
24466
24851
|
this.avancar();
|
|
24852
|
+
if (this.simboloAtual() === '=') {
|
|
24853
|
+
this.adicionarSimbolo(prisma_2.default.DIFERENTE);
|
|
24854
|
+
this.avancar();
|
|
24855
|
+
}
|
|
24856
|
+
else {
|
|
24857
|
+
this.adicionarSimbolo(prisma_2.default.BIT_XOR);
|
|
24858
|
+
}
|
|
24467
24859
|
break;
|
|
24468
24860
|
case '"':
|
|
24469
24861
|
this.avancar();
|
|
@@ -24919,16 +25311,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24919
25311
|
const calango_1 = __importDefault(require("../../../tipos-de-simbolos/calango"));
|
|
24920
25312
|
exports.default = {
|
|
24921
25313
|
algoritmo: calango_1.default.ALGORITMO,
|
|
24922
|
-
|
|
24923
|
-
|
|
25314
|
+
ate: calango_1.default.ATE,
|
|
25315
|
+
caracter: calango_1.default.CARACTER,
|
|
25316
|
+
caso: calango_1.default.CASO,
|
|
25317
|
+
de: calango_1.default.DE,
|
|
25318
|
+
div: calango_1.default.DIVISAO_INTEIRA,
|
|
25319
|
+
escolha: calango_1.default.ESCOLHA,
|
|
25320
|
+
enquanto: calango_1.default.ENQUANTO,
|
|
25321
|
+
entao: calango_1.default.ENTAO,
|
|
24924
25322
|
escreva: calango_1.default.ESCREVA,
|
|
24925
25323
|
escreval: calango_1.default.ESCREVAL,
|
|
25324
|
+
faca: calango_1.default.FACA,
|
|
25325
|
+
falso: calango_1.default.FALSO,
|
|
25326
|
+
fimEnquanto: calango_1.default.FIM_ENQUANTO,
|
|
25327
|
+
fimEscolha: calango_1.default.FIM_ESCOLHA,
|
|
25328
|
+
fimFuncao: calango_1.default.FIM_FUNCAO,
|
|
25329
|
+
fimPara: calango_1.default.FIM_PARA,
|
|
25330
|
+
fimProcedimento: calango_1.default.FIM_PROCEDIMENTO,
|
|
25331
|
+
fimPrincipal: calango_1.default.FIM_PRINCIPAL,
|
|
25332
|
+
fimSe: calango_1.default.FIM_SE,
|
|
25333
|
+
outroCaso: calango_1.default.OUTRO_CASO,
|
|
25334
|
+
procedimento: calango_1.default.PROCEDIMENTO,
|
|
24926
25335
|
inteiro: calango_1.default.INTEIRO,
|
|
25336
|
+
funcao: calango_1.default.FUNCAO,
|
|
25337
|
+
interrompa: calango_1.default.INTERROMPA,
|
|
24927
25338
|
leia: calango_1.default.LEIA,
|
|
25339
|
+
logico: calango_1.default.LOGICO,
|
|
25340
|
+
mod: calango_1.default.MODULO,
|
|
25341
|
+
nao: calango_1.default.NEGACAO,
|
|
25342
|
+
para: calango_1.default.PARA,
|
|
25343
|
+
passo: calango_1.default.PASSO,
|
|
25344
|
+
principal: calango_1.default.PRINCIPAL,
|
|
25345
|
+
real: calango_1.default.REAL,
|
|
25346
|
+
retorna: calango_1.default.RETORNA,
|
|
24928
25347
|
se: calango_1.default.SE,
|
|
24929
|
-
entao: calango_1.default.ENTAO,
|
|
24930
25348
|
senao: calango_1.default.SENAO,
|
|
24931
|
-
|
|
25349
|
+
texto: calango_1.default.TIPO_TEXTO,
|
|
25350
|
+
verdadeiro: calango_1.default.VERDADEIRO,
|
|
24932
25351
|
};
|
|
24933
25352
|
|
|
24934
25353
|
},{"../../../tipos-de-simbolos/calango":220}],201:[function(require,module,exports){
|
|
@@ -25102,6 +25521,8 @@ exports.palavrasReservadas = {
|
|
|
25102
25521
|
leia: prisma_1.default.LEIA,
|
|
25103
25522
|
local: prisma_1.default.LOCAL,
|
|
25104
25523
|
nulo: prisma_1.default.NULO,
|
|
25524
|
+
nao: prisma_1.default.NAO,
|
|
25525
|
+
não: prisma_1.default.NAO,
|
|
25105
25526
|
ou: prisma_1.default.OU,
|
|
25106
25527
|
padrao: prisma_1.default.PADRAO,
|
|
25107
25528
|
padrão: prisma_1.default.PADRAO,
|
|
@@ -25113,6 +25534,7 @@ exports.palavrasReservadas = {
|
|
|
25113
25534
|
senao: prisma_1.default.SENAO,
|
|
25114
25535
|
senão: prisma_1.default.SENÃO,
|
|
25115
25536
|
super: prisma_1.default.SUPER,
|
|
25537
|
+
quebra: prisma_1.default.QUEBRE,
|
|
25116
25538
|
quebre: prisma_1.default.QUEBRE,
|
|
25117
25539
|
tente: prisma_1.default.TENTE,
|
|
25118
25540
|
verdadeiro: prisma_1.default.VERDADEIRO,
|
|
@@ -25610,13 +26032,13 @@ class Lexador {
|
|
|
25610
26032
|
return this.codigo[this.linha].charAt(this.atual - 1);
|
|
25611
26033
|
}
|
|
25612
26034
|
analisarTexto(delimitador = '"') {
|
|
25613
|
-
let
|
|
26035
|
+
let valor = '';
|
|
25614
26036
|
this.avancar();
|
|
25615
26037
|
while (!this.eFinalDoCodigo()) {
|
|
25616
26038
|
const caractere = this.simboloAtual();
|
|
25617
26039
|
if (caractere === delimitador) {
|
|
25618
26040
|
this.avancar();
|
|
25619
|
-
this.adicionarSimbolo(delegua_1.default.TEXTO,
|
|
26041
|
+
this.adicionarSimbolo(delegua_1.default.TEXTO, valor);
|
|
25620
26042
|
return;
|
|
25621
26043
|
}
|
|
25622
26044
|
if (caractere === '\0' && this.eUltimaLinha()) {
|
|
@@ -25628,11 +26050,62 @@ class Lexador {
|
|
|
25628
26050
|
return;
|
|
25629
26051
|
}
|
|
25630
26052
|
if (caractere === '\0') {
|
|
25631
|
-
|
|
26053
|
+
valor += '\n';
|
|
25632
26054
|
this.avancar();
|
|
25633
26055
|
continue;
|
|
25634
26056
|
}
|
|
25635
|
-
|
|
26057
|
+
if (caractere === '\\') {
|
|
26058
|
+
this.avancar();
|
|
26059
|
+
const proximoCaractere = this.simboloAtual();
|
|
26060
|
+
switch (proximoCaractere) {
|
|
26061
|
+
case 'n':
|
|
26062
|
+
valor += '\n';
|
|
26063
|
+
break;
|
|
26064
|
+
case 't':
|
|
26065
|
+
valor += '\t';
|
|
26066
|
+
break;
|
|
26067
|
+
case 'r':
|
|
26068
|
+
valor += '\r';
|
|
26069
|
+
break;
|
|
26070
|
+
case 'b':
|
|
26071
|
+
valor += '\b';
|
|
26072
|
+
break;
|
|
26073
|
+
case "'":
|
|
26074
|
+
valor += "'";
|
|
26075
|
+
break;
|
|
26076
|
+
case '"':
|
|
26077
|
+
valor += '"';
|
|
26078
|
+
break;
|
|
26079
|
+
case '\\':
|
|
26080
|
+
valor += '\\';
|
|
26081
|
+
break;
|
|
26082
|
+
case 'e':
|
|
26083
|
+
valor += '\x1B';
|
|
26084
|
+
break;
|
|
26085
|
+
case 'x': {
|
|
26086
|
+
let hex = '';
|
|
26087
|
+
for (let i = 0; i < 2; i++) {
|
|
26088
|
+
const c = this.proximoSimbolo();
|
|
26089
|
+
if (/[0-9a-fA-F]/.test(c)) {
|
|
26090
|
+
this.avancar();
|
|
26091
|
+
hex += c;
|
|
26092
|
+
}
|
|
26093
|
+
else {
|
|
26094
|
+
break;
|
|
26095
|
+
}
|
|
26096
|
+
}
|
|
26097
|
+
valor += hex.length === 2 ? String.fromCharCode(parseInt(hex, 16)) : '\\x' + hex;
|
|
26098
|
+
break;
|
|
26099
|
+
}
|
|
26100
|
+
case '\0': break; // barra invertida no fim de linha: ignora e continua na próxima linha
|
|
26101
|
+
default:
|
|
26102
|
+
valor += '\\' + proximoCaractere;
|
|
26103
|
+
break;
|
|
26104
|
+
}
|
|
26105
|
+
}
|
|
26106
|
+
else {
|
|
26107
|
+
valor += caractere;
|
|
26108
|
+
}
|
|
25636
26109
|
this.avancar();
|
|
25637
26110
|
}
|
|
25638
26111
|
this.erros.push({
|
|
@@ -26901,14 +27374,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26901
27374
|
exports.default = {
|
|
26902
27375
|
ADICAO: 'ADICAO',
|
|
26903
27376
|
ALGORITMO: 'ALGORITMO',
|
|
27377
|
+
CARACTER: 'CARACTER',
|
|
26904
27378
|
DIFERENTE: 'DIFERENTE',
|
|
26905
27379
|
DIVISAO: 'DIVISAO',
|
|
26906
27380
|
DIVISAO_INTEIRA: 'DIVISAO_INTEIRA',
|
|
26907
27381
|
E: 'E',
|
|
27382
|
+
ENQUANTO: 'ENQUANTO',
|
|
26908
27383
|
ENTAO: 'ENTAO',
|
|
26909
27384
|
ESCREVA: 'ESCREVA',
|
|
26910
27385
|
ESCREVAL: 'ESCREVAL',
|
|
26911
27386
|
EXPONENCIACAO: 'EXPONENCIACAO',
|
|
27387
|
+
FACA: 'FACA',
|
|
27388
|
+
FALSO: 'FALSO',
|
|
27389
|
+
ATE: 'ATE',
|
|
27390
|
+
CASO: 'CASO',
|
|
27391
|
+
COLCHETE_DIREITO: 'COLCHETE_DIREITO',
|
|
27392
|
+
COLCHETE_ESQUERDO: 'COLCHETE_ESQUERDO',
|
|
27393
|
+
DE: 'DE',
|
|
27394
|
+
DOIS_PONTOS: 'DOIS_PONTOS',
|
|
27395
|
+
ESCOLHA: 'ESCOLHA',
|
|
27396
|
+
FIM_ESCOLHA: 'FIM_ESCOLHA',
|
|
27397
|
+
FIM_FUNCAO: 'FIM_FUNCAO',
|
|
27398
|
+
FIM_PROCEDIMENTO: 'FIM_PROCEDIMENTO',
|
|
27399
|
+
FUNCAO: 'FUNCAO',
|
|
27400
|
+
FIM_ENQUANTO: 'FIM_ENQUANTO',
|
|
27401
|
+
FIM_PARA: 'FIM_PARA',
|
|
26912
27402
|
FIM_PRINCIPAL: 'FIM_PRINCIPAL',
|
|
26913
27403
|
FIM_SE: 'FIM_SE',
|
|
26914
27404
|
IDENTIFICADOR: 'IDENTIFICADOR',
|
|
@@ -26916,7 +27406,10 @@ exports.default = {
|
|
|
26916
27406
|
IGUAL_ATRIBUICAO: 'IGUAL_ATRIBUICAO',
|
|
26917
27407
|
IGUAL_IGUAL: 'IGUAL_IGUAL',
|
|
26918
27408
|
INTEIRO: 'INTEIRO',
|
|
27409
|
+
INTERROMPA: 'INTERROMPA',
|
|
26919
27410
|
LEIA: 'LEIA',
|
|
27411
|
+
LITERAL_CARACTER: 'LITERAL_CARACTER',
|
|
27412
|
+
LOGICO: 'LOGICO',
|
|
26920
27413
|
MAIOR: 'MAIOR',
|
|
26921
27414
|
MAIOR_IGUAL: 'MAIOR_IGUAL',
|
|
26922
27415
|
MENOR: 'MENOR',
|
|
@@ -26929,13 +27422,21 @@ exports.default = {
|
|
|
26929
27422
|
PARENTESE_DIREITO: 'PARENTESE_DIREITO',
|
|
26930
27423
|
PARENTESE_ESQUERDO: 'PARENTESE_ESQUERDO',
|
|
26931
27424
|
PRINCIPAL: 'PRINCIPAL',
|
|
27425
|
+
OUTRO_CASO: 'OUTRO_CASO',
|
|
27426
|
+
PARA: 'PARA',
|
|
27427
|
+
PROCEDIMENTO: 'PROCEDIMENTO',
|
|
27428
|
+
PASSO: 'PASSO',
|
|
26932
27429
|
PONTO: 'PONTO',
|
|
26933
27430
|
PONTO_E_VIRGULA: 'PONTO_E_VIRGULA',
|
|
26934
27431
|
QUEBRA_LINHA: 'QUEBRA_LINHA',
|
|
27432
|
+
REAL: 'REAL',
|
|
27433
|
+
RETORNA: 'RETORNA',
|
|
26935
27434
|
SE: 'SE',
|
|
26936
27435
|
SENAO: 'SENAO',
|
|
26937
27436
|
SUBTRACAO: 'SUBTRACAO',
|
|
26938
27437
|
TEXTO: 'TEXTO',
|
|
27438
|
+
TIPO_TEXTO: 'TIPO_TEXTO',
|
|
27439
|
+
VERDADEIRO: 'VERDADEIRO',
|
|
26939
27440
|
VIRGULA: 'VIRGULA',
|
|
26940
27441
|
};
|
|
26941
27442
|
|
|
@@ -27400,6 +27901,7 @@ exports.default = {
|
|
|
27400
27901
|
IGUAL_IGUAL: 'IGUAL_IGUAL',
|
|
27401
27902
|
IMPORTAR: 'IMPORTAR',
|
|
27402
27903
|
INICIO: 'INICIO',
|
|
27904
|
+
INTERROGACAO: 'INTERROGACAO',
|
|
27403
27905
|
ISTO: 'ISTO',
|
|
27404
27906
|
LEIA: 'LEIA',
|
|
27405
27907
|
LOCAL: 'LOCAL',
|
|
@@ -27412,6 +27914,7 @@ exports.default = {
|
|
|
27412
27914
|
MENOR_MENOR: 'MENOR_MENOR',
|
|
27413
27915
|
MODULO: 'MODULO',
|
|
27414
27916
|
MULTIPLICACAO: 'MULTIPLICACAO',
|
|
27917
|
+
NAO: 'NAO',
|
|
27415
27918
|
NEGACAO: 'NEGACAO',
|
|
27416
27919
|
NULO: 'NULO',
|
|
27417
27920
|
NUMERO: 'NUMERO',
|
|
@@ -27423,6 +27926,8 @@ exports.default = {
|
|
|
27423
27926
|
PEGUE: 'PEGUE',
|
|
27424
27927
|
PONTO: 'PONTO',
|
|
27425
27928
|
PONTO_E_VIRGULA: 'PONTO_E_VIRGULA',
|
|
27929
|
+
COMPRIMENTO: 'COMPRIMENTO',
|
|
27930
|
+
CONCATENACAO: 'CONCATENACAO',
|
|
27426
27931
|
QUEBRA_LINHA: 'QUEBRA_LINHA',
|
|
27427
27932
|
RETORNE: 'RETORNE',
|
|
27428
27933
|
SE: 'SE',
|
|
@@ -40965,10 +41470,10 @@ class TradutorAssemblyRISCV {
|
|
|
40965
41470
|
Var: this.traduzirDeclaracaoVar.bind(this),
|
|
40966
41471
|
};
|
|
40967
41472
|
this.indentacao = 0;
|
|
40968
|
-
this.text = `
|
|
40969
|
-
.text
|
|
40970
|
-
.global _start
|
|
40971
|
-
|
|
41473
|
+
this.text = `
|
|
41474
|
+
.text
|
|
41475
|
+
.global _start
|
|
41476
|
+
|
|
40972
41477
|
_start:`;
|
|
40973
41478
|
}
|
|
40974
41479
|
gerarDigitoAleatorio() {
|
|
@@ -41035,9 +41540,9 @@ _start:`;
|
|
|
41035
41540
|
const reg = this.obterRegistrador();
|
|
41036
41541
|
this.text += `\n la ${reg}, ${nomeVar}`;
|
|
41037
41542
|
this.emitirCarga('a0', indice);
|
|
41038
|
-
this.text += `
|
|
41039
|
-
slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
|
|
41040
|
-
add ${reg}, ${reg}, a0
|
|
41543
|
+
this.text += `
|
|
41544
|
+
slli a0, a0, 3 # multiplicar índice por 8 (palavra de 64 bits)
|
|
41545
|
+
add ${reg}, ${reg}, a0
|
|
41041
41546
|
ld a0, 0(${reg})`;
|
|
41042
41547
|
this.liberarRegistrador(reg);
|
|
41043
41548
|
return 'a0';
|
|
@@ -41062,8 +41567,8 @@ _start:`;
|
|
|
41062
41567
|
const reg = this.obterRegistrador();
|
|
41063
41568
|
this.text += `\n la ${reg}, ${nomeVar}`;
|
|
41064
41569
|
this.emitirCarga('a1', indice);
|
|
41065
|
-
this.text += `
|
|
41066
|
-
slli a1, a1, 3 # multiplicar índice por 8
|
|
41570
|
+
this.text += `
|
|
41571
|
+
slli a1, a1, 3 # multiplicar índice por 8
|
|
41067
41572
|
add ${reg}, ${reg}, a1`;
|
|
41068
41573
|
this.emitirCarga('a1', valor);
|
|
41069
41574
|
this.text += `\n sd a1, 0(${reg})`;
|
|
@@ -41084,8 +41589,8 @@ _start:`;
|
|
|
41084
41589
|
this.variaveis.set(nomeVar, varLabel);
|
|
41085
41590
|
}
|
|
41086
41591
|
this.emitirCarga('a0', valor);
|
|
41087
|
-
this.text += `
|
|
41088
|
-
la a1, ${this.variaveis.get(nomeVar)}
|
|
41592
|
+
this.text += `
|
|
41593
|
+
la a1, ${this.variaveis.get(nomeVar)}
|
|
41089
41594
|
sd a0, 0(a1)`;
|
|
41090
41595
|
}
|
|
41091
41596
|
traduzirConstrutoBinario(construto) {
|
|
@@ -41170,18 +41675,18 @@ _start:`;
|
|
|
41170
41675
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
41171
41676
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
41172
41677
|
this.emitirCarga('a0', valor);
|
|
41173
|
-
this.text += `
|
|
41174
|
-
la a1, ${objeto}
|
|
41678
|
+
this.text += `
|
|
41679
|
+
la a1, ${objeto}
|
|
41175
41680
|
sd a0, 0(a1)`;
|
|
41176
41681
|
}
|
|
41177
41682
|
traduzirFuncaoConstruto(construto) {
|
|
41178
41683
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
41179
|
-
this.text += `
|
|
41180
|
-
|
|
41181
|
-
${labelFuncao}:
|
|
41182
|
-
addi sp, sp, -16
|
|
41183
|
-
sd ra, 8(sp)
|
|
41184
|
-
sd s0, 0(sp)
|
|
41684
|
+
this.text += `
|
|
41685
|
+
|
|
41686
|
+
${labelFuncao}:
|
|
41687
|
+
addi sp, sp, -16
|
|
41688
|
+
sd ra, 8(sp)
|
|
41689
|
+
sd s0, 0(sp)
|
|
41185
41690
|
addi s0, sp, 16`;
|
|
41186
41691
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
41187
41692
|
construto.corpo.forEach((declaracao) => {
|
|
@@ -41190,10 +41695,10 @@ ${labelFuncao}:
|
|
|
41190
41695
|
}
|
|
41191
41696
|
});
|
|
41192
41697
|
}
|
|
41193
|
-
this.text += `
|
|
41194
|
-
ld ra, 8(sp)
|
|
41195
|
-
ld s0, 0(sp)
|
|
41196
|
-
addi sp, sp, 16
|
|
41698
|
+
this.text += `
|
|
41699
|
+
ld ra, 8(sp)
|
|
41700
|
+
ld s0, 0(sp)
|
|
41701
|
+
addi sp, sp, 16
|
|
41197
41702
|
ret`;
|
|
41198
41703
|
}
|
|
41199
41704
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -41212,21 +41717,21 @@ ${labelFuncao}:
|
|
|
41212
41717
|
if (operador === 'e' || operador === '&&') {
|
|
41213
41718
|
this.text += `\n beqz a0, ${labelFim}`;
|
|
41214
41719
|
this.emitirCarga('a0', direita);
|
|
41215
|
-
this.text += `
|
|
41216
|
-
beqz a0, ${labelFim}
|
|
41217
|
-
${labelVerdadeiro}:
|
|
41218
|
-
li a0, 1
|
|
41720
|
+
this.text += `
|
|
41721
|
+
beqz a0, ${labelFim}
|
|
41722
|
+
${labelVerdadeiro}:
|
|
41723
|
+
li a0, 1
|
|
41219
41724
|
${labelFim}:`;
|
|
41220
41725
|
}
|
|
41221
41726
|
else if (operador === 'ou' || operador === '||') {
|
|
41222
41727
|
this.text += `\n bnez a0, ${labelVerdadeiro}`;
|
|
41223
41728
|
this.emitirCarga('a0', direita);
|
|
41224
|
-
this.text += `
|
|
41225
|
-
bnez a0, ${labelVerdadeiro}
|
|
41226
|
-
li a0, 0
|
|
41227
|
-
j ${labelFim}
|
|
41228
|
-
${labelVerdadeiro}:
|
|
41229
|
-
li a0, 1
|
|
41729
|
+
this.text += `
|
|
41730
|
+
bnez a0, ${labelVerdadeiro}
|
|
41731
|
+
li a0, 0
|
|
41732
|
+
j ${labelFim}
|
|
41733
|
+
${labelVerdadeiro}:
|
|
41734
|
+
li a0, 1
|
|
41230
41735
|
${labelFim}:`;
|
|
41231
41736
|
}
|
|
41232
41737
|
return 'a0';
|
|
@@ -41252,8 +41757,8 @@ ${labelFim}:`;
|
|
|
41252
41757
|
const nomeVar = (_a = construto.simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
41253
41758
|
if (nomeVar && this.variaveis.has(nomeVar)) {
|
|
41254
41759
|
const varLabel = this.variaveis.get(nomeVar);
|
|
41255
|
-
this.text += `
|
|
41256
|
-
la a0, ${varLabel}
|
|
41760
|
+
this.text += `
|
|
41761
|
+
la a0, ${varLabel}
|
|
41257
41762
|
ld a0, 0(a0)`;
|
|
41258
41763
|
return 'a0';
|
|
41259
41764
|
}
|
|
@@ -41269,8 +41774,8 @@ ${labelFim}:`;
|
|
|
41269
41774
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
41270
41775
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
41271
41776
|
this.emitirCarga('a0', valorTraduzido);
|
|
41272
|
-
this.text += `
|
|
41273
|
-
la a1, ${labelVetor}
|
|
41777
|
+
this.text += `
|
|
41778
|
+
la a1, ${labelVetor}
|
|
41274
41779
|
sd a0, ${index * 8}(a1)`;
|
|
41275
41780
|
}
|
|
41276
41781
|
});
|
|
@@ -41298,8 +41803,8 @@ ${labelFim}:`;
|
|
|
41298
41803
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
41299
41804
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
41300
41805
|
}
|
|
41301
|
-
this.text += `
|
|
41302
|
-
j ${labelInicio}
|
|
41806
|
+
this.text += `
|
|
41807
|
+
j ${labelInicio}
|
|
41303
41808
|
${labelFim}:`;
|
|
41304
41809
|
}
|
|
41305
41810
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -41320,8 +41825,8 @@ ${labelFim}:`;
|
|
|
41320
41825
|
}
|
|
41321
41826
|
});
|
|
41322
41827
|
}
|
|
41323
|
-
this.text += `
|
|
41324
|
-
j ${labelFim}
|
|
41828
|
+
this.text += `
|
|
41829
|
+
j ${labelFim}
|
|
41325
41830
|
${labelProximo}:`;
|
|
41326
41831
|
}
|
|
41327
41832
|
});
|
|
@@ -41362,21 +41867,21 @@ ${labelProximo}:`;
|
|
|
41362
41867
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
41363
41868
|
}
|
|
41364
41869
|
}
|
|
41365
|
-
this.text += `
|
|
41366
|
-
# Falhar com mensagem: ${mensagem}
|
|
41367
|
-
li a0, 1
|
|
41368
|
-
li a7, 93 # sys_exit
|
|
41870
|
+
this.text += `
|
|
41871
|
+
# Falhar com mensagem: ${mensagem}
|
|
41872
|
+
li a0, 1
|
|
41873
|
+
li a7, 93 # sys_exit
|
|
41369
41874
|
ecall`;
|
|
41370
41875
|
}
|
|
41371
41876
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
41372
41877
|
var _a;
|
|
41373
41878
|
const nomeFuncao = ((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'funcao';
|
|
41374
|
-
this.text += `
|
|
41375
|
-
|
|
41376
|
-
${nomeFuncao}:
|
|
41377
|
-
addi sp, sp, -16
|
|
41378
|
-
sd ra, 8(sp)
|
|
41379
|
-
sd s0, 0(sp)
|
|
41879
|
+
this.text += `
|
|
41880
|
+
|
|
41881
|
+
${nomeFuncao}:
|
|
41882
|
+
addi sp, sp, -16
|
|
41883
|
+
sd ra, 8(sp)
|
|
41884
|
+
sd s0, 0(sp)
|
|
41380
41885
|
addi s0, sp, 16`;
|
|
41381
41886
|
if (declaracao.funcao &&
|
|
41382
41887
|
declaracao.funcao.corpo &&
|
|
@@ -41387,10 +41892,10 @@ ${nomeFuncao}:
|
|
|
41387
41892
|
}
|
|
41388
41893
|
});
|
|
41389
41894
|
}
|
|
41390
|
-
this.text += `
|
|
41391
|
-
ld ra, 8(sp)
|
|
41392
|
-
ld s0, 0(sp)
|
|
41393
|
-
addi sp, sp, 16
|
|
41895
|
+
this.text += `
|
|
41896
|
+
ld ra, 8(sp)
|
|
41897
|
+
ld s0, 0(sp)
|
|
41898
|
+
addi sp, sp, 16
|
|
41394
41899
|
ret`;
|
|
41395
41900
|
}
|
|
41396
41901
|
traduzirDeclaracaoImportar(declaracao) {
|
|
@@ -41411,11 +41916,11 @@ ${nomeFuncao}:
|
|
|
41411
41916
|
this.bss += ` ${varLabel}: .space 256\n`;
|
|
41412
41917
|
this.variaveis.set(nomeVar, varLabel);
|
|
41413
41918
|
}
|
|
41414
|
-
this.text += `
|
|
41415
|
-
li a0, 0 # fd stdin
|
|
41416
|
-
la a1, ${this.variaveis.get(nomeVar)}
|
|
41417
|
-
li a2, 256
|
|
41418
|
-
li a7, 63 # sys_read
|
|
41919
|
+
this.text += `
|
|
41920
|
+
li a0, 0 # fd stdin
|
|
41921
|
+
la a1, ${this.variaveis.get(nomeVar)}
|
|
41922
|
+
li a2, 256
|
|
41923
|
+
li a7, 63 # sys_read
|
|
41419
41924
|
ecall`;
|
|
41420
41925
|
}
|
|
41421
41926
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -41446,8 +41951,8 @@ ${nomeFuncao}:
|
|
|
41446
41951
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
41447
41952
|
}
|
|
41448
41953
|
}
|
|
41449
|
-
this.text += `
|
|
41450
|
-
j ${labelInicio}
|
|
41954
|
+
this.text += `
|
|
41955
|
+
j ${labelInicio}
|
|
41451
41956
|
${labelFim}:`;
|
|
41452
41957
|
}
|
|
41453
41958
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -41459,17 +41964,17 @@ ${labelFim}:`;
|
|
|
41459
41964
|
tamanhoVetor = vetor.tamanho || 0;
|
|
41460
41965
|
}
|
|
41461
41966
|
// t0: contador; t1: limite (caller-saved, seguros aqui)
|
|
41462
|
-
this.text += `
|
|
41463
|
-
li t0, 0 # contador
|
|
41464
|
-
li t1, ${tamanhoVetor}
|
|
41465
|
-
${labelInicio}:
|
|
41967
|
+
this.text += `
|
|
41968
|
+
li t0, 0 # contador
|
|
41969
|
+
li t1, ${tamanhoVetor}
|
|
41970
|
+
${labelInicio}:
|
|
41466
41971
|
bge t0, t1, ${labelFim}`;
|
|
41467
41972
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
41468
41973
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
41469
41974
|
}
|
|
41470
|
-
this.text += `
|
|
41471
|
-
addi t0, t0, 1
|
|
41472
|
-
j ${labelInicio}
|
|
41975
|
+
this.text += `
|
|
41976
|
+
addi t0, t0, 1
|
|
41977
|
+
j ${labelInicio}
|
|
41473
41978
|
${labelFim}:`;
|
|
41474
41979
|
}
|
|
41475
41980
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
@@ -41477,10 +41982,10 @@ ${labelFim}:`;
|
|
|
41477
41982
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
41478
41983
|
this.emitirCarga('a0', valor);
|
|
41479
41984
|
}
|
|
41480
|
-
this.text += `
|
|
41481
|
-
ld ra, 8(sp)
|
|
41482
|
-
ld s0, 0(sp)
|
|
41483
|
-
addi sp, sp, 16
|
|
41985
|
+
this.text += `
|
|
41986
|
+
ld ra, 8(sp)
|
|
41987
|
+
ld s0, 0(sp)
|
|
41988
|
+
addi sp, sp, 16
|
|
41484
41989
|
ret`;
|
|
41485
41990
|
}
|
|
41486
41991
|
traduzirDeclaracaoSe(declaracao) {
|
|
@@ -41494,8 +41999,8 @@ ${labelFim}:`;
|
|
|
41494
41999
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
41495
42000
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
41496
42001
|
}
|
|
41497
|
-
this.text += `
|
|
41498
|
-
j ${labelFim}
|
|
42002
|
+
this.text += `
|
|
42003
|
+
j ${labelFim}
|
|
41499
42004
|
${labelSenao}:`;
|
|
41500
42005
|
if (declaracao.caminhoSenao &&
|
|
41501
42006
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
@@ -41544,8 +42049,8 @@ ${labelSenao}:`;
|
|
|
41544
42049
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
41545
42050
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
41546
42051
|
this.emitirCarga('a0', valor);
|
|
41547
|
-
this.text += `
|
|
41548
|
-
la a1, ${varLabel}
|
|
42052
|
+
this.text += `
|
|
42053
|
+
la a1, ${varLabel}
|
|
41549
42054
|
sd a0, 0(a1)`;
|
|
41550
42055
|
}
|
|
41551
42056
|
}
|
|
@@ -41567,17 +42072,17 @@ ${labelSenao}:`;
|
|
|
41567
42072
|
tamanhoString = String(stringValue.length);
|
|
41568
42073
|
}
|
|
41569
42074
|
// sys_write(fd=1, buf, count): a7=64, a0=fd, a1=buf, a2=count
|
|
41570
|
-
this.text += `
|
|
41571
|
-
la a1, ${nomeStringLiteral}
|
|
41572
|
-
li a2, ${tamanhoString}
|
|
41573
|
-
li a0, 1 # fd stdout
|
|
41574
|
-
li a7, 64 # sys_write
|
|
42075
|
+
this.text += `
|
|
42076
|
+
la a1, ${nomeStringLiteral}
|
|
42077
|
+
li a2, ${tamanhoString}
|
|
42078
|
+
li a0, 1 # fd stdout
|
|
42079
|
+
li a7, 64 # sys_write
|
|
41575
42080
|
ecall`;
|
|
41576
42081
|
}
|
|
41577
42082
|
saidaSistema() {
|
|
41578
|
-
this.text += `
|
|
41579
|
-
li a0, 0 # código de saída
|
|
41580
|
-
li a7, 93 # sys_exit
|
|
42083
|
+
this.text += `
|
|
42084
|
+
li a0, 0 # código de saída
|
|
42085
|
+
li a7, 93 # sys_exit
|
|
41581
42086
|
ecall`;
|
|
41582
42087
|
}
|
|
41583
42088
|
traduzir(declaracoes) {
|
|
@@ -43148,7 +43653,7 @@ class TradutorAssemblyScript {
|
|
|
43148
43653
|
let resultado = '';
|
|
43149
43654
|
this.indentacao += 4;
|
|
43150
43655
|
resultado += ' '.repeat(this.indentacao);
|
|
43151
|
-
for (let condicao of
|
|
43656
|
+
for (let condicao of caminho.condicoes || []) {
|
|
43152
43657
|
resultado +=
|
|
43153
43658
|
'case ' + this.dicionarioConstrutos[condicao.constructor.name](condicao) + ':\n';
|
|
43154
43659
|
resultado += ' '.repeat(this.indentacao);
|
|
@@ -43513,9 +44018,72 @@ class TradutorAssemblyScript {
|
|
|
43513
44018
|
traduzirConstrutoAgrupamento(agrupamento) {
|
|
43514
44019
|
return this.dicionarioConstrutos[agrupamento.constructor.name](agrupamento.expressao || agrupamento);
|
|
43515
44020
|
}
|
|
44021
|
+
detectarImportacoesNecessarias(declaracoes) {
|
|
44022
|
+
const importsNecessarios = new Set();
|
|
44023
|
+
this.varrerDeclaracoesParaImports(declaracoes, importsNecessarios);
|
|
44024
|
+
if (importsNecessarios.size === 0) {
|
|
44025
|
+
return '';
|
|
44026
|
+
}
|
|
44027
|
+
return Array.from(importsNecessarios).join('\n') + '\n\n';
|
|
44028
|
+
}
|
|
44029
|
+
varrerDeclaracoesParaImports(declaracoes, imports) {
|
|
44030
|
+
for (const declaracao of declaracoes) {
|
|
44031
|
+
const nome = declaracao.constructor.name;
|
|
44032
|
+
if (nome === 'Escreva' || nome === 'EscrevaMesmaLinha') {
|
|
44033
|
+
imports.add('import "wasi";');
|
|
44034
|
+
}
|
|
44035
|
+
else if (nome === 'Bloco') {
|
|
44036
|
+
this.varrerDeclaracoesParaImports(declaracao.declaracoes, imports);
|
|
44037
|
+
}
|
|
44038
|
+
else if (nome === 'Se') {
|
|
44039
|
+
const se = declaracao;
|
|
44040
|
+
if (se.caminhoEntao) {
|
|
44041
|
+
this.varrerDeclaracoesParaImports([se.caminhoEntao], imports);
|
|
44042
|
+
}
|
|
44043
|
+
if (se.caminhoSenao) {
|
|
44044
|
+
this.varrerDeclaracoesParaImports([se.caminhoSenao], imports);
|
|
44045
|
+
}
|
|
44046
|
+
}
|
|
44047
|
+
else if (nome === 'Enquanto') {
|
|
44048
|
+
const enquanto = declaracao;
|
|
44049
|
+
this.varrerDeclaracoesParaImports([enquanto.corpo], imports);
|
|
44050
|
+
}
|
|
44051
|
+
else if (nome === 'Para') {
|
|
44052
|
+
const para = declaracao;
|
|
44053
|
+
this.varrerDeclaracoesParaImports([para.corpo], imports);
|
|
44054
|
+
}
|
|
44055
|
+
else if (nome === 'ParaCada') {
|
|
44056
|
+
const paraCada = declaracao;
|
|
44057
|
+
this.varrerDeclaracoesParaImports([paraCada.corpo], imports);
|
|
44058
|
+
}
|
|
44059
|
+
else if (nome === 'Fazer') {
|
|
44060
|
+
const fazer = declaracao;
|
|
44061
|
+
this.varrerDeclaracoesParaImports([fazer.caminhoFazer], imports);
|
|
44062
|
+
}
|
|
44063
|
+
else if (nome === 'FuncaoDeclaracao') {
|
|
44064
|
+
const funcao = declaracao;
|
|
44065
|
+
this.varrerDeclaracoesParaImports(funcao.funcao.corpo, imports);
|
|
44066
|
+
}
|
|
44067
|
+
else if (nome === 'Classe') {
|
|
44068
|
+
const classe = declaracao;
|
|
44069
|
+
this.varrerDeclaracoesParaImports(classe.metodos, imports);
|
|
44070
|
+
}
|
|
44071
|
+
else if (nome === 'Tente') {
|
|
44072
|
+
const tente = declaracao;
|
|
44073
|
+
this.varrerDeclaracoesParaImports(tente.caminhoTente, imports);
|
|
44074
|
+
if (Array.isArray(tente.caminhoPegue)) {
|
|
44075
|
+
this.varrerDeclaracoesParaImports(tente.caminhoPegue, imports);
|
|
44076
|
+
}
|
|
44077
|
+
if (tente.caminhoFinalmente && tente.caminhoFinalmente.length > 0) {
|
|
44078
|
+
this.varrerDeclaracoesParaImports(tente.caminhoFinalmente, imports);
|
|
44079
|
+
}
|
|
44080
|
+
}
|
|
44081
|
+
}
|
|
44082
|
+
}
|
|
43516
44083
|
traduzir(declaracoes) {
|
|
43517
44084
|
let resultado = '';
|
|
43518
44085
|
this.declaracoesDeClasses = declaracoes.filter((declaracao) => declaracao instanceof declaracoes_1.Classe);
|
|
44086
|
+
resultado += this.detectarImportacoesNecessarias(declaracoes);
|
|
43519
44087
|
for (const declaracao of declaracoes) {
|
|
43520
44088
|
resultado += `${this.dicionarioDeclaracoes[declaracao.constructor.name](declaracao)} \n`;
|
|
43521
44089
|
}
|
|
@@ -48914,19 +49482,30 @@ class TradutorWebAssembly {
|
|
|
48914
49482
|
const dir = this.traduzirConstruto(construto.direita);
|
|
48915
49483
|
const op = construto.operador.lexema;
|
|
48916
49484
|
switch (op) {
|
|
48917
|
-
case '+':
|
|
48918
|
-
|
|
48919
|
-
case '
|
|
48920
|
-
|
|
48921
|
-
case '
|
|
48922
|
-
|
|
48923
|
-
case '
|
|
48924
|
-
|
|
48925
|
-
case '
|
|
49485
|
+
case '+':
|
|
49486
|
+
return `(i64.add ${esq} ${dir})`;
|
|
49487
|
+
case '-':
|
|
49488
|
+
return `(i64.sub ${esq} ${dir})`;
|
|
49489
|
+
case '*':
|
|
49490
|
+
return `(i64.mul ${esq} ${dir})`;
|
|
49491
|
+
case '/':
|
|
49492
|
+
return `(i64.div_s ${esq} ${dir})`;
|
|
49493
|
+
case '%':
|
|
49494
|
+
return `(i64.rem_s ${esq} ${dir})`;
|
|
49495
|
+
case '<':
|
|
49496
|
+
return `(i64.extend_i32_s (i64.lt_s ${esq} ${dir}))`;
|
|
49497
|
+
case '>':
|
|
49498
|
+
return `(i64.extend_i32_s (i64.gt_s ${esq} ${dir}))`;
|
|
49499
|
+
case '<=':
|
|
49500
|
+
return `(i64.extend_i32_s (i64.le_s ${esq} ${dir}))`;
|
|
49501
|
+
case '>=':
|
|
49502
|
+
return `(i64.extend_i32_s (i64.ge_s ${esq} ${dir}))`;
|
|
48926
49503
|
case '==':
|
|
48927
|
-
case '===':
|
|
49504
|
+
case '===':
|
|
49505
|
+
return `(i64.extend_i32_s (i64.eq ${esq} ${dir}))`;
|
|
48928
49506
|
case '!=':
|
|
48929
|
-
case '!==':
|
|
49507
|
+
case '!==':
|
|
49508
|
+
return `(i64.extend_i32_s (i64.ne ${esq} ${dir}))`;
|
|
48930
49509
|
default:
|
|
48931
49510
|
return `(i64.const 0) ;; operador não suportado: ${op}`;
|
|
48932
49511
|
}
|
|
@@ -49458,12 +50037,7 @@ class TradutorWebAssembly {
|
|
|
49458
50037
|
const { watLiteral } = this.escaparStringWat(s.conteudo);
|
|
49459
50038
|
return ` (data (i32.const ${s.deslocamento}) "${watLiteral}")`;
|
|
49460
50039
|
});
|
|
49461
|
-
const partes = [
|
|
49462
|
-
'(module',
|
|
49463
|
-
...linhasImports,
|
|
49464
|
-
'',
|
|
49465
|
-
linhaMemoria,
|
|
49466
|
-
];
|
|
50040
|
+
const partes = ['(module', ...linhasImports, '', linhaMemoria];
|
|
49467
50041
|
if (linhasDados.length > 0) {
|
|
49468
50042
|
partes.push('');
|
|
49469
50043
|
partes.push(...linhasDados);
|
|
@@ -49487,35 +50061,35 @@ class TradutorWebAssembly {
|
|
|
49487
50061
|
* Fornece os imports necessários (`delegua.escreva_texto`, `delegua.escreva_inteiro`).
|
|
49488
50062
|
*/
|
|
49489
50063
|
gerarArquivoHost() {
|
|
49490
|
-
return `// Gerado por Delégua -> WebAssembly
|
|
49491
|
-
// Uso: node delegua-host.mjs <arquivo.wasm>
|
|
49492
|
-
import { readFileSync } from 'fs';
|
|
49493
|
-
|
|
49494
|
-
const args = process.argv.slice(2);
|
|
49495
|
-
const wasmPath = args[0] ?? 'saida.wasm';
|
|
49496
|
-
|
|
49497
|
-
let memoryExport;
|
|
49498
|
-
|
|
49499
|
-
const importObject = {
|
|
49500
|
-
delegua: {
|
|
49501
|
-
/** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
|
|
49502
|
-
escreva_texto(ptr, len) {
|
|
49503
|
-
const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
|
|
49504
|
-
process.stdout.write(new TextDecoder('utf-8').decode(bytes));
|
|
49505
|
-
},
|
|
49506
|
-
/** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
|
|
49507
|
-
escreva_inteiro(valor) {
|
|
49508
|
-
process.stdout.write(String(valor));
|
|
49509
|
-
},
|
|
49510
|
-
}
|
|
49511
|
-
};
|
|
49512
|
-
|
|
49513
|
-
const wasmBuffer = readFileSync(wasmPath);
|
|
49514
|
-
const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
|
|
49515
|
-
memoryExport = instance.exports.memory;
|
|
49516
|
-
|
|
49517
|
-
const codigoSaida = Number(instance.exports.principal());
|
|
49518
|
-
process.exit(codigoSaida);
|
|
50064
|
+
return `// Gerado por Delégua -> WebAssembly
|
|
50065
|
+
// Uso: node delegua-host.mjs <arquivo.wasm>
|
|
50066
|
+
import { readFileSync } from 'fs';
|
|
50067
|
+
|
|
50068
|
+
const args = process.argv.slice(2);
|
|
50069
|
+
const wasmPath = args[0] ?? 'saida.wasm';
|
|
50070
|
+
|
|
50071
|
+
let memoryExport;
|
|
50072
|
+
|
|
50073
|
+
const importObject = {
|
|
50074
|
+
delegua: {
|
|
50075
|
+
/** Imprime texto a partir de um ponteiro e comprimento na memória linear. */
|
|
50076
|
+
escreva_texto(ptr, len) {
|
|
50077
|
+
const bytes = new Uint8Array(memoryExport.buffer, ptr, len);
|
|
50078
|
+
process.stdout.write(new TextDecoder('utf-8').decode(bytes));
|
|
50079
|
+
},
|
|
50080
|
+
/** Imprime um inteiro de 64 bits (recebido como BigInt no JS). */
|
|
50081
|
+
escreva_inteiro(valor) {
|
|
50082
|
+
process.stdout.write(String(valor));
|
|
50083
|
+
},
|
|
50084
|
+
}
|
|
50085
|
+
};
|
|
50086
|
+
|
|
50087
|
+
const wasmBuffer = readFileSync(wasmPath);
|
|
50088
|
+
const { instance } = await WebAssembly.instantiate(wasmBuffer, importObject);
|
|
50089
|
+
memoryExport = instance.exports.memory;
|
|
50090
|
+
|
|
50091
|
+
const codigoSaida = Number(instance.exports.principal());
|
|
50092
|
+
process.exit(codigoSaida);
|
|
49519
50093
|
`;
|
|
49520
50094
|
}
|
|
49521
50095
|
}
|