@designliquido/delegua 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analisador-semantico/analisador-semantico-base.d.ts +2 -2
- package/analisador-semantico/analisador-semantico-base.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico-base.js +14 -6
- package/analisador-semantico/analisador-semantico-base.js.map +1 -1
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +38 -19
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +41 -18
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -1
- package/analisador-semantico/funcao-hipotetica-interface.d.ts +1 -1
- package/analisador-semantico/gerenciador-escopos.d.ts +1 -1
- package/analisador-semantico/pilha-variaveis.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +99 -42
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/comum.d.ts.map +1 -1
- package/avaliador-sintatico/comum.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.js +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +91 -96
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js +4 -4
- 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 +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.js.map +1 -1
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/erro-avaliador-sintatico.d.ts +18 -0
- package/avaliador-sintatico/erro-avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/erro-avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.d.ts.map +1 -1
- package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/biblioteca-global.js +93 -31
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js +12 -8
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-numero.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-numero.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-texto.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-texto.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-tupla.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-tupla.js +3 -4
- package/bibliotecas/dialetos/pitugues/primitivas-tupla.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.js +9 -11
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.js.map +1 -1
- package/bibliotecas/primitivas-dicionario.d.ts.map +1 -1
- package/bibliotecas/primitivas-dicionario.js +1 -1
- package/bibliotecas/primitivas-dicionario.js.map +1 -1
- package/bibliotecas/primitivas-numero.d.ts.map +1 -1
- package/bibliotecas/primitivas-numero.js.map +1 -1
- package/bibliotecas/primitivas-texto.d.ts.map +1 -1
- package/bibliotecas/primitivas-texto.js +1 -1
- package/bibliotecas/primitivas-texto.js.map +1 -1
- package/bibliotecas/primitivas-tupla.d.ts.map +1 -1
- package/bibliotecas/primitivas-tupla.js +34 -14
- package/bibliotecas/primitivas-tupla.js.map +1 -1
- package/bibliotecas/primitivas-vetor.d.ts.map +1 -1
- package/bibliotecas/primitivas-vetor.js +1 -1
- package/bibliotecas/primitivas-vetor.js.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/ajuda-como-construto.d.ts +2 -2
- package/construtos/ajuda-como-construto.js +1 -1
- package/construtos/atribuir.d.ts.map +1 -1
- package/construtos/atribuir.js +5 -2
- package/construtos/atribuir.js.map +1 -1
- package/construtos/binario.d.ts.map +1 -1
- package/construtos/binario.js +1 -2
- package/construtos/binario.js.map +1 -1
- package/construtos/comentario-como-construto.d.ts.map +1 -1
- package/construtos/comentario-como-construto.js.map +1 -1
- package/construtos/decorador.d.ts.map +1 -1
- package/construtos/decorador.js +3 -1
- package/construtos/decorador.js.map +1 -1
- package/construtos/dicionario.d.ts.map +1 -1
- package/construtos/dicionario.js.map +1 -1
- package/construtos/tupla-n.d.ts +3 -3
- package/construtos/tupla-n.d.ts.map +1 -1
- package/construtos/tupla-n.js +4 -2
- package/construtos/tupla-n.js.map +1 -1
- package/declaracoes/ajuda.d.ts +3 -3
- package/declaracoes/funcao.d.ts +2 -1
- package/declaracoes/funcao.d.ts.map +1 -1
- package/declaracoes/funcao.js +2 -1
- package/declaracoes/funcao.js.map +1 -1
- package/declaracoes/interface.d.ts.map +1 -1
- package/declaracoes/interface.js.map +1 -1
- package/declaracoes/texto-documentacao.d.ts.map +1 -1
- package/declaracoes/texto-documentacao.js.map +1 -1
- package/estilizador/estilizador-delegua.d.ts.map +1 -1
- package/estilizador/estilizador-delegua.js +5 -1
- package/estilizador/estilizador-delegua.js.map +1 -1
- package/formatadores/formatador-delegua.d.ts.map +1 -1
- package/formatadores/formatador-delegua.js.map +1 -1
- package/formatadores/formatador-pitugues.d.ts.map +1 -1
- package/formatadores/formatador-pitugues.js +74 -29
- package/formatadores/formatador-pitugues.js.map +1 -1
- package/geracao-identificadores/index.js +2 -2
- package/geracao-identificadores/index.js.map +1 -1
- package/interfaces/componente-modulo-classe-interface.d.ts.map +1 -1
- package/interfaces/componente-modulo-funcao-interface.d.ts.map +1 -1
- package/interfaces/interpretador-com-depuracao-interface.d.ts.map +1 -1
- package/interfaces/modulo-interface.d.ts +2 -2
- package/interfaces/modulo-interface.d.ts.map +1 -1
- package/interfaces/visitante-comum-interface.d.ts.map +1 -1
- package/interpretador/comum.d.ts.map +1 -1
- package/interpretador/comum.js +55 -55
- package/interpretador/comum.js.map +1 -1
- package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts.map +1 -1
- package/interpretador/depuracao/avaliador-expressao-depuracao.js.map +1 -1
- package/interpretador/depuracao/comum.d.ts.map +1 -1
- package/interpretador/depuracao/comum.js +8 -4
- package/interpretador/depuracao/comum.js.map +1 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js +1 -3
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js.map +1 -1
- package/interpretador/dialetos/pitugues/comum.d.ts +2 -2
- package/interpretador/dialetos/pitugues/comum.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/comum.js +2 -3
- package/interpretador/dialetos/pitugues/comum.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.d.ts +2 -2
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.js +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts +3 -3
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js +3 -2
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.d.ts.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js.map +1 -1
- package/interpretador/estruturas/classe-de-modulo.d.ts.map +1 -1
- package/interpretador/estruturas/delegua-funcao.d.ts.map +1 -1
- package/interpretador/estruturas/delegua-funcao.js +3 -1
- package/interpretador/estruturas/delegua-funcao.js.map +1 -1
- package/interpretador/estruturas/descritor-tipo-classe.d.ts.map +1 -1
- package/interpretador/estruturas/descritor-tipo-classe.js +6 -6
- package/interpretador/estruturas/descritor-tipo-classe.js.map +1 -1
- package/interpretador/estruturas/metodo-polimorfico.d.ts.map +1 -1
- package/interpretador/estruturas/metodo-polimorfico.js +13 -9
- package/interpretador/estruturas/metodo-polimorfico.js.map +1 -1
- package/interpretador/estruturas/metodo-primitiva.d.ts.map +1 -1
- package/interpretador/estruturas/metodo-primitiva.js.map +1 -1
- package/interpretador/estruturas/objeto-base.d.ts.map +1 -1
- package/interpretador/estruturas/objeto-base.js.map +1 -1
- package/interpretador/estruturas/objeto-delegua-classe.d.ts.map +1 -1
- package/interpretador/estruturas/objeto-delegua-classe.js +10 -6
- package/interpretador/estruturas/objeto-delegua-classe.js.map +1 -1
- package/interpretador/interpretador-base.d.ts +4 -4
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +123 -54
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +28 -17
- package/interpretador/interpretador.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts.map +1 -1
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/lexador/dialetos/lexador-calango.d.ts.map +1 -1
- package/lexador/dialetos/lexador-calango.js.map +1 -1
- package/lexador/dialetos/lexador-egua-classico.d.ts.map +1 -1
- package/lexador/dialetos/lexador-egua-classico.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts.map +1 -1
- package/lexador/dialetos/lexador-pitugues.js +21 -13
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/lexador/dialetos/lexador-portugol-ipt.d.ts.map +1 -1
- package/lexador/dialetos/lexador-portugol-ipt.js.map +1 -1
- package/lexador/dialetos/lexador-prisma.d.ts.map +1 -1
- package/lexador/dialetos/lexador-prisma.js +25 -3
- package/lexador/dialetos/lexador-prisma.js.map +1 -1
- package/lexador/dialetos/lexador-tenda.d.ts.map +1 -1
- package/lexador/dialetos/lexador-tenda.js.map +1 -1
- package/lexador/filtro-paradigma.d.ts.map +1 -1
- package/lexador/filtro-paradigma.js.map +1 -1
- package/lexador/lexador-base-linha-unica.d.ts.map +1 -1
- package/lexador/lexador-base-linha-unica.js.map +1 -1
- package/lexador/lexador-base.d.ts.map +1 -1
- package/lexador/lexador-base.js.map +1 -1
- package/lexador/lexador.d.ts.map +1 -1
- package/lexador/lexador.js.map +1 -1
- package/lexador/mapeamento-paradigmas.d.ts.map +1 -1
- package/lexador/mapeamento-paradigmas.js.map +1 -1
- package/lexador/palavras-reservadas.js +2 -2
- package/lexador/palavras-reservadas.js.map +1 -1
- package/lexador/simbolo.d.ts.map +1 -1
- package/lexador/simbolo.js.map +1 -1
- package/lexador/traducao/lexador-javascript.d.ts.map +1 -1
- package/package.json +1 -1
- package/tradutores/mermaid/aresta-fluxograma.d.ts +1 -1
- package/tradutores/mermaid/subgrafo-classe.d.ts +3 -3
- package/tradutores/mermaid/subgrafo-funcao.d.ts +2 -2
- package/tradutores/mermaid/subgrafo-funcao.d.ts.map +1 -1
- package/tradutores/mermaid/subgrafo-funcao.js.map +1 -1
- package/tradutores/mermaid/subgrafo-metodo.d.ts +2 -2
- package/tradutores/mermaid/vertice-fluxograma.d.ts +1 -1
- package/tradutores/tradutor-assembly-arm.d.ts.map +1 -1
- package/tradutores/tradutor-assembly-arm.js +164 -156
- package/tradutores/tradutor-assembly-arm.js.map +1 -1
- package/tradutores/tradutor-assembly-x64.d.ts.map +1 -1
- package/tradutores/tradutor-assembly-x64.js +136 -127
- package/tradutores/tradutor-assembly-x64.js.map +1 -1
- package/tradutores/tradutor-assemblyscript.d.ts.map +1 -1
- package/tradutores/tradutor-assemblyscript.js +10 -6
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-calango.d.ts.map +1 -1
- package/tradutores/tradutor-calango.js.map +1 -1
- package/tradutores/tradutor-elixir.d.ts.map +1 -1
- package/tradutores/tradutor-elixir.js +9 -7
- package/tradutores/tradutor-elixir.js.map +1 -1
- package/tradutores/tradutor-javascript.d.ts.map +1 -1
- package/tradutores/tradutor-javascript.js +2 -1
- package/tradutores/tradutor-javascript.js.map +1 -1
- package/tradutores/tradutor-mermaidjs.d.ts.map +1 -1
- package/tradutores/tradutor-mermaidjs.js +4 -8
- package/tradutores/tradutor-mermaidjs.js.map +1 -1
- package/tradutores/tradutor-portugol-ipt.d.ts.map +1 -1
- package/tradutores/tradutor-portugol-ipt.js.map +1 -1
- package/tradutores/tradutor-python.d.ts.map +1 -1
- package/tradutores/tradutor-python.js +1 -1
- package/tradutores/tradutor-python.js.map +1 -1
- package/tradutores/tradutor-reverso-javascript.d.ts.map +1 -1
- package/tradutores/tradutor-ruby.d.ts.map +1 -1
- package/tradutores/tradutor-ruby.js +1 -1
- package/tradutores/tradutor-ruby.js.map +1 -1
- package/umd/delegua.js +1056 -720
package/umd/delegua.js
CHANGED
|
@@ -12,7 +12,7 @@ const interfaces_1 = require("../interfaces");
|
|
|
12
12
|
*/
|
|
13
13
|
class AnalisadorSemanticoBase {
|
|
14
14
|
diagnosticoJaExiste(simbolo, mensagem) {
|
|
15
|
-
return this.diagnosticos.some(d => d.linha === simbolo.linha &&
|
|
15
|
+
return this.diagnosticos.some((d) => d.linha === simbolo.linha &&
|
|
16
16
|
d.mensagem === mensagem &&
|
|
17
17
|
d.simbolo.lexema === simbolo.lexema);
|
|
18
18
|
}
|
|
@@ -63,7 +63,7 @@ class AnalisadorSemanticoBase {
|
|
|
63
63
|
for (let [indice, parametro] of parametros.entries()) {
|
|
64
64
|
const argumento = argumentos[indice];
|
|
65
65
|
if (argumento) {
|
|
66
|
-
// Usando `obterTipoExpressao` para resolver adequadamente o tipo do argumento,
|
|
66
|
+
// Usando `obterTipoExpressao` para resolver adequadamente o tipo do argumento,
|
|
67
67
|
// independentemente de ser um `Literal` (tipo já resolvido), `Variavel` (tipo inferido do
|
|
68
68
|
// escopo), `Binario`, `Agrupamento`, ou qualquer outro construto (retorna `null` quando
|
|
69
69
|
// o tipo não pode ser determinado em tempo de compilação).
|
|
@@ -119,7 +119,14 @@ class AnalisadorSemanticoBase {
|
|
|
119
119
|
*/
|
|
120
120
|
inferirTipoBinario(binario) {
|
|
121
121
|
const operadoresMatematicos = ['ADICAO', 'SUBTRACAO', 'MULTIPLICACAO', 'DIVISAO', 'MODULO'];
|
|
122
|
-
const operadoresComparacao = [
|
|
122
|
+
const operadoresComparacao = [
|
|
123
|
+
'MAIOR',
|
|
124
|
+
'MAIOR_IGUAL',
|
|
125
|
+
'MENOR',
|
|
126
|
+
'MENOR_IGUAL',
|
|
127
|
+
'IGUAL',
|
|
128
|
+
'DIFERENTE',
|
|
129
|
+
];
|
|
123
130
|
// Operadores de comparação sempre retornam lógico
|
|
124
131
|
if (operadoresComparacao.includes(binario.operador.tipo)) {
|
|
125
132
|
return 'lógico';
|
|
@@ -146,8 +153,8 @@ class AnalisadorSemanticoBase {
|
|
|
146
153
|
return 'qualquer';
|
|
147
154
|
}
|
|
148
155
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
* Marca as variáveis usadas em uma expressão.
|
|
157
|
+
*/
|
|
151
158
|
marcarVariaveisUsadasEmExpressao(expressao) {
|
|
152
159
|
if (expressao instanceof construtos_1.Variavel) {
|
|
153
160
|
this.gerenciadorEscopos.marcarComoUsada(expressao.simbolo.lexema);
|
|
@@ -233,7 +240,8 @@ class AnalisadorSemanticoBase {
|
|
|
233
240
|
if (!caminhoSenaoResolvido || ((_a = caminhoSenaoResolvido.declaracoes) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
234
241
|
return false;
|
|
235
242
|
}
|
|
236
|
-
if (caminhoSenaoResolvido instanceof declaracoes_1.Se &&
|
|
243
|
+
if (caminhoSenaoResolvido instanceof declaracoes_1.Se &&
|
|
244
|
+
((_b = caminhoSenaoResolvido.caminhoEntao.declaracoes) === null || _b === void 0 ? void 0 : _b.length) === 1) {
|
|
237
245
|
const senaoSeRetorna = this.verificarSeRetorna(caminhoSenaoResolvido);
|
|
238
246
|
return entaoRetorna && senaoSeRetorna;
|
|
239
247
|
}
|
|
@@ -592,7 +600,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
592
600
|
}
|
|
593
601
|
visitarChamadaPorVariavel(entidadeChamadaVariavel, argumentos) {
|
|
594
602
|
const variavel = entidadeChamadaVariavel;
|
|
595
|
-
const funcaoChamada = this.gerenciadorEscopos.buscar(variavel.simbolo.lexema) ||
|
|
603
|
+
const funcaoChamada = this.gerenciadorEscopos.buscar(variavel.simbolo.lexema) ||
|
|
604
|
+
this.funcoes[variavel.simbolo.lexema];
|
|
596
605
|
if (!funcaoChamada) {
|
|
597
606
|
this.erro(entidadeChamadaVariavel.simbolo, `Chamada da função '${entidadeChamadaVariavel.simbolo.lexema}' não existe.`);
|
|
598
607
|
return Promise.resolve();
|
|
@@ -889,15 +898,18 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
889
898
|
// Verifica se a expressão problemática é um Leia ou uma variável inicializada com Leia
|
|
890
899
|
let mensagemAdicional = '';
|
|
891
900
|
if (expressaoProblematica instanceof construtos_1.Leia) {
|
|
892
|
-
mensagemAdicional =
|
|
901
|
+
mensagemAdicional =
|
|
902
|
+
" Função 'leia()' retorna texto. Use 'inteiro(leia(...))' ou 'real(leia(...))' para converter.";
|
|
893
903
|
}
|
|
894
904
|
else if (expressaoProblematica instanceof construtos_1.Variavel) {
|
|
895
905
|
const variavel = this.gerenciadorEscopos.buscar(expressaoProblematica.simbolo.lexema);
|
|
896
906
|
if (variavel && variavel.valor instanceof construtos_1.Leia) {
|
|
897
|
-
mensagemAdicional =
|
|
907
|
+
mensagemAdicional =
|
|
908
|
+
" A variável foi inicializada com 'leia()' que retorna texto. Use 'inteiro(leia(...))' ou 'real(leia(...))' para converter.";
|
|
898
909
|
}
|
|
899
910
|
else {
|
|
900
|
-
mensagemAdicional =
|
|
911
|
+
mensagemAdicional =
|
|
912
|
+
" Use 'inteiro(...)' ou 'real(...)' para converter texto em número.";
|
|
901
913
|
}
|
|
902
914
|
}
|
|
903
915
|
this.erro(binario.operador, `Operação aritmética com tipo incompatível: operando ${ladoProblematico} é do tipo 'texto', mas a operação requer número.${mensagemAdicional}`);
|
|
@@ -906,8 +918,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
906
918
|
}
|
|
907
919
|
if (tipoEsquerda && tipoDireita && tipoEsquerda !== tipoDireita) {
|
|
908
920
|
// Verificar se são tipos numéricos compatíveis
|
|
909
|
-
const ambosNumericos = tiposNumericos.includes(tipoEsquerda) &&
|
|
910
|
-
tiposNumericos.includes(tipoDireita);
|
|
921
|
+
const ambosNumericos = tiposNumericos.includes(tipoEsquerda) && tiposNumericos.includes(tipoDireita);
|
|
911
922
|
if (!ambosNumericos) {
|
|
912
923
|
this.aviso(binario.operador, `Operação entre tipos diferentes: tipo esquerdo '${tipoEsquerda}' e tipo direito '${tipoDireita}'. O resultado será resolvido implicitamente.`);
|
|
913
924
|
}
|
|
@@ -1015,7 +1026,15 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1015
1026
|
let entidadeChamadaVariavel = chamada.entidadeChamada;
|
|
1016
1027
|
const nomeFuncao = entidadeChamadaVariavel.simbolo.lexema;
|
|
1017
1028
|
// Lista de funções built-in que não precisam ser declaradas
|
|
1018
|
-
const funcoesBuiltIn = [
|
|
1029
|
+
const funcoesBuiltIn = [
|
|
1030
|
+
'inteiro',
|
|
1031
|
+
'real',
|
|
1032
|
+
'número',
|
|
1033
|
+
'texto',
|
|
1034
|
+
'leia',
|
|
1035
|
+
'escreva',
|
|
1036
|
+
'tipo',
|
|
1037
|
+
];
|
|
1019
1038
|
// Classes/construtores geralmente começam com letra maiúscula
|
|
1020
1039
|
const pareceSerClasse = nomeFuncao[0] === nomeFuncao[0].toUpperCase();
|
|
1021
1040
|
// Só verifica se a função existe se não for built-in e não parecer ser classe
|
|
@@ -1070,7 +1089,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1070
1089
|
tipo: 'IDENTIFICADOR',
|
|
1071
1090
|
linha: literal.linha,
|
|
1072
1091
|
hashArquivo: literal.hashArquivo,
|
|
1073
|
-
literal: null
|
|
1092
|
+
literal: null,
|
|
1074
1093
|
}, `Variável ou função '${nomeVariavel}' usada em interpolação não existe.`);
|
|
1075
1094
|
}
|
|
1076
1095
|
else if (variavel) {
|
|
@@ -1083,7 +1102,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1083
1102
|
tipo: 'IDENTIFICADOR',
|
|
1084
1103
|
linha: literal.linha,
|
|
1085
1104
|
hashArquivo: literal.hashArquivo,
|
|
1086
|
-
literal: null
|
|
1105
|
+
literal: null,
|
|
1087
1106
|
}, `Variável '${nomeVariavel}' usada em interpolação pode não ter sido inicializada.`);
|
|
1088
1107
|
}
|
|
1089
1108
|
}
|
|
@@ -1146,7 +1165,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1146
1165
|
inicializada: true,
|
|
1147
1166
|
usada: false,
|
|
1148
1167
|
hashArquivo: declaracao.simbolo.hashArquivo,
|
|
1149
|
-
linha: declaracao.simbolo.linha
|
|
1168
|
+
linha: declaracao.simbolo.linha,
|
|
1150
1169
|
});
|
|
1151
1170
|
// TODO: Verificar inicializador.
|
|
1152
1171
|
return Promise.resolve();
|
|
@@ -1178,7 +1197,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1178
1197
|
if (tipoValor === 'string' && tipoRetornoFuncao !== 'texto') {
|
|
1179
1198
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1180
1199
|
}
|
|
1181
|
-
if (tipoValor === 'number' &&
|
|
1200
|
+
if (tipoValor === 'number' &&
|
|
1201
|
+
!['inteiro', 'real', 'número'].includes(tipoRetornoFuncao)) {
|
|
1182
1202
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1183
1203
|
}
|
|
1184
1204
|
}
|
|
@@ -1203,17 +1223,21 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1203
1223
|
tipoInferido = this.obterTipoExpressao(declaracao.inicializador);
|
|
1204
1224
|
}
|
|
1205
1225
|
// Sugestão de tipo melhor quando 'qualquer' é usado explicitamente
|
|
1206
|
-
if (declaracao.tipoExplicito &&
|
|
1226
|
+
if (declaracao.tipoExplicito &&
|
|
1227
|
+
declaracao.tipoOriginal === 'qualquer' &&
|
|
1228
|
+
declaracao.inicializador) {
|
|
1207
1229
|
const tipoMelhor = this.obterTipoExpressao(declaracao.inicializador);
|
|
1208
1230
|
if (tipoMelhor && tipoMelhor !== 'qualquer') {
|
|
1209
|
-
this.sugestao(declaracao.simbolo, 'Um tipo melhor pode ser inferido.', [
|
|
1231
|
+
this.sugestao(declaracao.simbolo, 'Um tipo melhor pode ser inferido.', [
|
|
1232
|
+
{
|
|
1210
1233
|
titulo: `Alterar tipo para '${tipoMelhor}'`,
|
|
1211
1234
|
textoOriginal: 'qualquer',
|
|
1212
1235
|
textoSubstituto: tipoMelhor,
|
|
1213
1236
|
linha: declaracao.simbolo.linha,
|
|
1214
1237
|
colunaInicio: declaracao.simbolo.colunaInicio,
|
|
1215
1238
|
colunaFim: declaracao.simbolo.colunaFim,
|
|
1216
|
-
}
|
|
1239
|
+
},
|
|
1240
|
+
]);
|
|
1217
1241
|
}
|
|
1218
1242
|
}
|
|
1219
1243
|
const variavel = {
|
|
@@ -1224,7 +1248,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1224
1248
|
inicializada: declaracao.inicializador !== null && declaracao.inicializador !== undefined,
|
|
1225
1249
|
usada: false,
|
|
1226
1250
|
hashArquivo: declaracao.simbolo.hashArquivo,
|
|
1227
|
-
linha: declaracao.simbolo.linha
|
|
1251
|
+
linha: declaracao.simbolo.linha,
|
|
1228
1252
|
};
|
|
1229
1253
|
const declaradaComSucesso = this.gerenciadorEscopos.declarar(declaracao.simbolo.lexema, variavel);
|
|
1230
1254
|
if (!declaradaComSucesso) {
|
|
@@ -1369,7 +1393,9 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1369
1393
|
retorno.tipo === 'qualquer');
|
|
1370
1394
|
// Se a função é 'vazio' e há retornos com tipo indeterminado,
|
|
1371
1395
|
// tenta inferir o tipo e fornece mensagem útil ao desenvolvedor
|
|
1372
|
-
if (tipoRetornoFuncao === 'vazio' &&
|
|
1396
|
+
if (tipoRetornoFuncao === 'vazio' &&
|
|
1397
|
+
declaracao.funcao.tipoExplicito &&
|
|
1398
|
+
retornosComTipoIndeterminado.length > 0) {
|
|
1373
1399
|
const retornoComValor = retornosComTipoIndeterminado[0];
|
|
1374
1400
|
const tipoInferido = this.obterTipoExpressao(retornoComValor.valor);
|
|
1375
1401
|
if (tipoInferido && tipoInferido !== 'qualquer') {
|
|
@@ -1388,7 +1414,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1388
1414
|
if (tipoValor === 'string' && tipoRetornoFuncao !== 'texto') {
|
|
1389
1415
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1390
1416
|
}
|
|
1391
|
-
if (tipoValor === 'number' &&
|
|
1417
|
+
if (tipoValor === 'number' &&
|
|
1418
|
+
!['inteiro', 'real', 'número'].includes(tipoRetornoFuncao)) {
|
|
1392
1419
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1393
1420
|
}
|
|
1394
1421
|
}
|
|
@@ -1404,7 +1431,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1404
1431
|
const naoUsadas = this.gerenciadorEscopos.obterVariaveisNaoUsadas();
|
|
1405
1432
|
for (let variavel of naoUsadas) {
|
|
1406
1433
|
// Verifica se já existe um erro associado à variável.
|
|
1407
|
-
const temErro = this.diagnosticos.some(d => d.severidade === erros_1.DiagnosticoSeveridade.ERRO &&
|
|
1434
|
+
const temErro = this.diagnosticos.some((d) => d.severidade === erros_1.DiagnosticoSeveridade.ERRO &&
|
|
1408
1435
|
d.simbolo.lexema === variavel.nome);
|
|
1409
1436
|
// Se a variável já tem um erro associado, não emitir aviso de não usada.
|
|
1410
1437
|
if (temErro) {
|
|
@@ -1414,7 +1441,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1414
1441
|
lexema: variavel.nome,
|
|
1415
1442
|
linha: variavel.linha,
|
|
1416
1443
|
tipo: variavel.tipo,
|
|
1417
|
-
hashArquivo: variavel.hashArquivo
|
|
1444
|
+
hashArquivo: variavel.hashArquivo,
|
|
1418
1445
|
}, `Variável '${variavel.nome}' foi declarada mas nunca usada.`);
|
|
1419
1446
|
}
|
|
1420
1447
|
}
|
|
@@ -1952,7 +1979,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
1952
1979
|
}
|
|
1953
1980
|
async construtoAjuda() {
|
|
1954
1981
|
const simboloAjuda = this.avancarEDevolverAnterior();
|
|
1955
|
-
if (this.estaNoFinal() ||
|
|
1982
|
+
if (this.estaNoFinal() ||
|
|
1983
|
+
this.simbolos[this.atual].tipo !== delegua_2.default.PARENTESE_ESQUERDO) {
|
|
1956
1984
|
return new construtos_1.AjudaComoConstruto(simboloAjuda.hashArquivo, simboloAjuda.linha, undefined, false);
|
|
1957
1985
|
}
|
|
1958
1986
|
this.avancarEDevolverAnterior(); // parêntese esquerdo
|
|
@@ -2379,7 +2407,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2379
2407
|
// o analisador semântico emitir o diagnóstico quando apropriado.
|
|
2380
2408
|
tipoIdentificadorCorrespondente = 'qualquer';
|
|
2381
2409
|
}
|
|
2382
|
-
if (!tipoIdentificadorCorrespondente.endsWith('[]') &&
|
|
2410
|
+
if (!tipoIdentificadorCorrespondente.endsWith('[]') &&
|
|
2411
|
+
!['dicionário', 'qualquer', 'texto', 'tupla', 'vetor'].includes(tipoIdentificadorCorrespondente)) {
|
|
2383
2412
|
throw this.erro(this.simbolos[this.atual], `Tipo ${tipoIdentificadorCorrespondente} não suporta acesso por índice.`);
|
|
2384
2413
|
}
|
|
2385
2414
|
let tipoAcesso = 'qualquer';
|
|
@@ -2453,8 +2482,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2453
2482
|
if (expressaoAnterior.tipo === 'dicionário' &&
|
|
2454
2483
|
expressaoAnterior.constructor !== construtos_1.Dicionario) {
|
|
2455
2484
|
const elementoMontaoTipos = this.resolverElementoMontao(expressaoAnterior);
|
|
2456
|
-
if (elementoMontaoTipos &&
|
|
2457
|
-
nome.lexema in elementoMontaoTipos.subElementos) {
|
|
2485
|
+
if (elementoMontaoTipos && nome.lexema in elementoMontaoTipos.subElementos) {
|
|
2458
2486
|
tipoInferido = elementoMontaoTipos.subElementos[nome.lexema].tipo;
|
|
2459
2487
|
}
|
|
2460
2488
|
}
|
|
@@ -2711,7 +2739,9 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2711
2739
|
if (construto instanceof construtos_1.Unario) {
|
|
2712
2740
|
const operando = construto.operando;
|
|
2713
2741
|
// Verifica se o operando é um vetor
|
|
2714
|
-
if (operando instanceof construtos_1.Vetor ||
|
|
2742
|
+
if (operando instanceof construtos_1.Vetor ||
|
|
2743
|
+
operando.tipo === 'vetor' ||
|
|
2744
|
+
operando.tipo.endsWith('[]')) {
|
|
2715
2745
|
return true;
|
|
2716
2746
|
}
|
|
2717
2747
|
// Verifica recursivamente para casos como !![]
|
|
@@ -3322,7 +3352,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3322
3352
|
}
|
|
3323
3353
|
async declaracaoSe() {
|
|
3324
3354
|
const condicao = await this.expressao();
|
|
3325
|
-
const caminhoEntao = await this.resolverDeclaracao();
|
|
3355
|
+
const caminhoEntao = (await this.resolverDeclaracao());
|
|
3326
3356
|
let caminhoSenao = null;
|
|
3327
3357
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SENAO, delegua_2.default.SENÃO)) {
|
|
3328
3358
|
caminhoSenao = await this.resolverDeclaracao();
|
|
@@ -3453,20 +3483,16 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3453
3483
|
// Uma delas é a variável/constante ser uma classe padrão.
|
|
3454
3484
|
// Isso ocorre quando a importação é feita de uma biblioteca Node.js.
|
|
3455
3485
|
// Nesse caso, o tipo de `entidadeChamada.objeto` começa com uma letra maiúscula.
|
|
3456
|
-
if (entidadeChamada.objeto.tipo &&
|
|
3457
|
-
entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
3486
|
+
if (entidadeChamada.objeto.tipo && entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
3458
3487
|
const tipoCorrespondente = this.tiposDefinidosPorBibliotecas[entidadeChamada.objeto.tipo];
|
|
3459
3488
|
if (!tipoCorrespondente) {
|
|
3460
3489
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Tipo '${entidadeChamada.objeto.tipo}' não foi encontrado entre os tipos definidos por bibliotecas.`);
|
|
3461
3490
|
}
|
|
3462
|
-
if (!(entidadeChamada.simbolo.lexema in
|
|
3463
|
-
tipoCorrespondente.
|
|
3464
|
-
!(entidadeChamada.simbolo.lexema in
|
|
3465
|
-
tipoCorrespondente.propriedades)) {
|
|
3491
|
+
if (!(entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) &&
|
|
3492
|
+
!(entidadeChamada.simbolo.lexema in tipoCorrespondente.propriedades)) {
|
|
3466
3493
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Membro '${entidadeChamada.simbolo.lexema}' não existe no tipo '${entidadeChamada.objeto.tipo}'.`);
|
|
3467
3494
|
}
|
|
3468
|
-
if (entidadeChamada.simbolo.lexema in
|
|
3469
|
-
tipoCorrespondente.metodos) {
|
|
3495
|
+
if (entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) {
|
|
3470
3496
|
const metodoCorrespondente = tipoCorrespondente.metodos[entidadeChamada.simbolo.lexema];
|
|
3471
3497
|
return metodoCorrespondente.tipoRetorno || 'qualquer';
|
|
3472
3498
|
}
|
|
@@ -3819,7 +3845,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3819
3845
|
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' antes do corpo da interface.");
|
|
3820
3846
|
const metodos = [];
|
|
3821
3847
|
const propriedades = [];
|
|
3822
|
-
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3848
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3849
|
+
!this.estaNoFinal()) {
|
|
3823
3850
|
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
3824
3851
|
if (this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA))
|
|
3825
3852
|
break;
|
|
@@ -3870,7 +3897,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3870
3897
|
const simbolo = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
3871
3898
|
// Pré-registro para permitir auto-referência no corpo da própria classe,
|
|
3872
3899
|
// como em `MinhaClasse.propriedadeEstatica` dentro de métodos.
|
|
3873
|
-
this.tiposDefinidosEmCodigo[simbolo.lexema] =
|
|
3900
|
+
this.tiposDefinidosEmCodigo[simbolo.lexema] =
|
|
3901
|
+
(_a = this.tiposDefinidosEmCodigo[simbolo.lexema]) !== null && _a !== void 0 ? _a : {};
|
|
3874
3902
|
const pilhaDecoradoresClasse = Array.from(this.pilhaDecoradores);
|
|
3875
3903
|
// Verificar `herda SuperclasseA, SuperclasseB`
|
|
3876
3904
|
const superClasses = [];
|
|
@@ -3908,7 +3936,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3908
3936
|
*/
|
|
3909
3937
|
const compreenderMembros = async (acessoPadrao, ehEstaticoPadrao, ehAbstratoPadrao = false) => {
|
|
3910
3938
|
var _a;
|
|
3911
|
-
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3939
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3940
|
+
!this.estaNoFinal()) {
|
|
3912
3941
|
// Pular comentários normais dentro do corpo da classe.
|
|
3913
3942
|
if (this.simbolos[this.atual].tipo === delegua_2.default.COMENTARIO ||
|
|
3914
3943
|
this.simbolos[this.atual].tipo === delegua_2.default.LINHA_COMENTARIO) {
|
|
@@ -3929,12 +3958,12 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3929
3958
|
// Detecção de bloco de contexto: modificador seguido de '{'
|
|
3930
3959
|
const tipoAtual = this.simbolos[this.atual].tipo;
|
|
3931
3960
|
const tipoProximo = (_a = this.simbolos[this.atual + 1]) === null || _a === void 0 ? void 0 : _a.tipo;
|
|
3932
|
-
const ehBlocoAcesso = [delegua_2.default.PRIVADO, delegua_2.default.PROTEGIDO].includes(tipoAtual)
|
|
3933
|
-
|
|
3934
|
-
const ehBlocoEstatico = tipoAtual === delegua_2.default.ESTATICO
|
|
3935
|
-
|
|
3936
|
-
const ehBlocoAbstrato = tipoAtual === delegua_2.default.ABSTRATO
|
|
3937
|
-
|
|
3961
|
+
const ehBlocoAcesso = [delegua_2.default.PRIVADO, delegua_2.default.PROTEGIDO].includes(tipoAtual) &&
|
|
3962
|
+
tipoProximo === delegua_2.default.CHAVE_ESQUERDA;
|
|
3963
|
+
const ehBlocoEstatico = tipoAtual === delegua_2.default.ESTATICO &&
|
|
3964
|
+
tipoProximo === delegua_2.default.CHAVE_ESQUERDA;
|
|
3965
|
+
const ehBlocoAbstrato = tipoAtual === delegua_2.default.ABSTRATO &&
|
|
3966
|
+
tipoProximo === delegua_2.default.CHAVE_ESQUERDA;
|
|
3938
3967
|
if (ehBlocoAcesso) {
|
|
3939
3968
|
const novoAcesso = tipoAtual === delegua_2.default.PRIVADO ? 'privado' : 'protegido';
|
|
3940
3969
|
this.avancarEDevolverAnterior(); // consume modificador de acesso
|
|
@@ -4031,14 +4060,17 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4031
4060
|
for (const declaracao of corpo) {
|
|
4032
4061
|
expressoesRetorna = expressoesRetorna.concat((0, comum_1.buscarRetornos)(declaracao));
|
|
4033
4062
|
}
|
|
4034
|
-
const tiposRetornos = new Set(expressoesRetorna
|
|
4063
|
+
const tiposRetornos = new Set(expressoesRetorna
|
|
4064
|
+
.filter((e) => e.tipo !== 'qualquer')
|
|
4065
|
+
.map((e) => e.tipo));
|
|
4035
4066
|
const retornaChamadoExplicitamente = tiposRetornos.size > 0;
|
|
4036
4067
|
tiposRetornos.delete('qualquer');
|
|
4037
4068
|
if (tipoRetorno === 'qualquer') {
|
|
4038
4069
|
if (tiposRetornos.size > 0) {
|
|
4039
4070
|
tipoRetorno = tiposRetornos.values().next().value;
|
|
4040
4071
|
}
|
|
4041
|
-
else if (!retornaChamadoExplicitamente &&
|
|
4072
|
+
else if (!retornaChamadoExplicitamente &&
|
|
4073
|
+
!definicaoExplicitaDeTipo) {
|
|
4042
4074
|
tipoRetorno = 'vazio';
|
|
4043
4075
|
}
|
|
4044
4076
|
}
|
|
@@ -4094,13 +4126,18 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4094
4126
|
let tipoAcessor = 'qualquer';
|
|
4095
4127
|
let expressoesRetornaAcessor = [];
|
|
4096
4128
|
for (const declaracao of corpoAcessor) {
|
|
4097
|
-
expressoesRetornaAcessor =
|
|
4129
|
+
expressoesRetornaAcessor =
|
|
4130
|
+
expressoesRetornaAcessor.concat((0, comum_1.buscarRetornos)(declaracao));
|
|
4098
4131
|
}
|
|
4099
|
-
const tiposRetornosAcessor = new Set(expressoesRetornaAcessor
|
|
4132
|
+
const tiposRetornosAcessor = new Set(expressoesRetornaAcessor
|
|
4133
|
+
.filter((e) => e.tipo !== 'qualquer')
|
|
4134
|
+
.map((e) => e.tipo));
|
|
4100
4135
|
const retornaExplicitamenteAcessor = tiposRetornosAcessor.size > 0;
|
|
4101
4136
|
tiposRetornosAcessor.delete('qualquer');
|
|
4102
4137
|
if (tiposRetornosAcessor.size > 0) {
|
|
4103
|
-
tipoAcessor = tiposRetornosAcessor
|
|
4138
|
+
tipoAcessor = tiposRetornosAcessor
|
|
4139
|
+
.values()
|
|
4140
|
+
.next().value;
|
|
4104
4141
|
}
|
|
4105
4142
|
else if (!retornaExplicitamenteAcessor) {
|
|
4106
4143
|
tipoAcessor = 'vazio';
|
|
@@ -4152,24 +4189,55 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4152
4189
|
await compreenderMembros('publico', false);
|
|
4153
4190
|
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' após o escopo da classe.");
|
|
4154
4191
|
// Verificação em tempo de análise: classe deve implementar todos os contratos das interfaces.
|
|
4192
|
+
const linhaFinalClasse = this.simbolos[this.atual - 1].linha;
|
|
4155
4193
|
for (const nomeInterface of implementaInterfaces) {
|
|
4156
4194
|
const interfaceDecl = this.interfacesDeclaradas[nomeInterface.lexema];
|
|
4157
4195
|
if (!interfaceDecl) {
|
|
4158
4196
|
this.erros.push(this.erro(nomeInterface, `Interface '${nomeInterface.lexema}' não foi declarada antes da classe '${simbolo.lexema}'.`));
|
|
4159
4197
|
continue;
|
|
4160
4198
|
}
|
|
4199
|
+
const membrosFaltando = [];
|
|
4161
4200
|
for (const assinatura of interfaceDecl.metodos) {
|
|
4162
4201
|
const nomeMetodo = assinatura.nome.lexema;
|
|
4163
4202
|
const implementado = metodos.some((m) => m.simbolo.lexema === nomeMetodo);
|
|
4164
4203
|
if (!implementado) {
|
|
4165
|
-
|
|
4204
|
+
membrosFaltando.push({
|
|
4205
|
+
tipo: 'metodo',
|
|
4206
|
+
nome: nomeMetodo,
|
|
4207
|
+
parametros: assinatura.parametros.map((p) => ({
|
|
4208
|
+
nome: p.nome.lexema,
|
|
4209
|
+
tipoDado: p.tipoDado,
|
|
4210
|
+
})),
|
|
4211
|
+
tipoRetorno: assinatura.tipoRetorno,
|
|
4212
|
+
});
|
|
4166
4213
|
}
|
|
4167
4214
|
}
|
|
4168
4215
|
for (const prop of interfaceDecl.propriedades) {
|
|
4169
4216
|
const nomeProp = prop.nome.lexema;
|
|
4170
4217
|
const implementada = propriedades.some((p) => p.nome.lexema === nomeProp);
|
|
4171
4218
|
if (!implementada) {
|
|
4172
|
-
|
|
4219
|
+
membrosFaltando.push({
|
|
4220
|
+
tipo: 'propriedade',
|
|
4221
|
+
nome: nomeProp,
|
|
4222
|
+
tipoPropriedade: prop.tipo,
|
|
4223
|
+
});
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
if (membrosFaltando.length > 0) {
|
|
4227
|
+
const correcaoSugerida = {
|
|
4228
|
+
tipo: 'implementar-interface',
|
|
4229
|
+
nomeInterface: nomeInterface.lexema,
|
|
4230
|
+
nomeClasse: simbolo.lexema,
|
|
4231
|
+
membrosFaltando,
|
|
4232
|
+
linhaFinalClasse,
|
|
4233
|
+
};
|
|
4234
|
+
for (const membro of membrosFaltando) {
|
|
4235
|
+
const mensagem = membro.tipo === 'metodo'
|
|
4236
|
+
? `Classe '${simbolo.lexema}' não implementa o método '${membro.nome}' exigido pela interface '${nomeInterface.lexema}'.`
|
|
4237
|
+
: `Classe '${simbolo.lexema}' não declara a propriedade '${membro.nome}' exigida pela interface '${nomeInterface.lexema}'.`;
|
|
4238
|
+
const erro = this.erro(simbolo, mensagem);
|
|
4239
|
+
erro.correcaoSugerida = correcaoSugerida;
|
|
4240
|
+
this.erros.push(erro);
|
|
4173
4241
|
}
|
|
4174
4242
|
}
|
|
4175
4243
|
}
|
|
@@ -4197,7 +4265,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4197
4265
|
if (!this.primitivasConhecidas[nomeTipo]) {
|
|
4198
4266
|
this.primitivasConhecidas[nomeTipo] = {};
|
|
4199
4267
|
}
|
|
4200
|
-
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
4268
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
4269
|
+
!this.estaNoFinal()) {
|
|
4201
4270
|
// Pular comentários dentro do corpo da extensão.
|
|
4202
4271
|
if (this.simbolos[this.atual].tipo === delegua_2.default.COMENTARIO ||
|
|
4203
4272
|
this.simbolos[this.atual].tipo === delegua_2.default.LINHA_COMENTARIO) {
|
|
@@ -4245,7 +4314,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4245
4314
|
const metodo = new declaracoes_1.FuncaoDeclaracao(nomeMetodo, corpoFuncao, tipoDaFuncao);
|
|
4246
4315
|
metodos.push(metodo);
|
|
4247
4316
|
const argumentos = params.map((parametro) => new informacao_elemento_sintatico_1.InformacaoElementoSintatico(parametro.nome.lexema, parametro.tipoDado || 'qualquer', parametro.valorPadrao === undefined));
|
|
4248
|
-
this.primitivasConhecidas[nomeTipo][nomeMetodo.lexema] =
|
|
4317
|
+
this.primitivasConhecidas[nomeTipo][nomeMetodo.lexema] =
|
|
4318
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico(nomeMetodo.lexema, tipoRetorno, true, argumentos);
|
|
4249
4319
|
}
|
|
4250
4320
|
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' ao final da extensão.");
|
|
4251
4321
|
return new declaracoes_1.Extensao(simboloTipo, metodos, ehGlobal, this.hashArquivo);
|
|
@@ -4273,13 +4343,26 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4273
4343
|
const simboloDoc = this.avancarEDevolverAnterior();
|
|
4274
4344
|
docTopLevel = new construtos_1.ComentarioComoConstruto(simboloDoc);
|
|
4275
4345
|
}
|
|
4276
|
-
if (
|
|
4277
|
-
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO))
|
|
4278
|
-
this.verificarTipoProximoSimbolo(delegua_2.default.
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4346
|
+
if (this.verificarTipoSimboloAtual(delegua_2.default.FUNCAO) ||
|
|
4347
|
+
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO)) {
|
|
4348
|
+
if (this.verificarTipoProximoSimbolo(delegua_2.default.DE)) {
|
|
4349
|
+
this.avancarEDevolverAnterior(); // `função`
|
|
4350
|
+
this.avancarEDevolverAnterior(); // `de`
|
|
4351
|
+
const simboloDecorador = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado 'decorador' após 'função de'.");
|
|
4352
|
+
if (simboloDecorador.lexema !== 'decorador') {
|
|
4353
|
+
throw this.erro(simboloDecorador, "Esperado 'decorador' após 'função de'.");
|
|
4354
|
+
}
|
|
4355
|
+
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4356
|
+
declaracaoFuncao.eFuncaoDeDecorador = true;
|
|
4357
|
+
declaracaoFuncao.documentacao = docTopLevel;
|
|
4358
|
+
return declaracaoFuncao;
|
|
4359
|
+
}
|
|
4360
|
+
if (this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
4361
|
+
this.avancarEDevolverAnterior();
|
|
4362
|
+
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4363
|
+
declaracaoFuncao.documentacao = docTopLevel;
|
|
4364
|
+
return declaracaoFuncao;
|
|
4365
|
+
}
|
|
4283
4366
|
}
|
|
4284
4367
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CLASSE)) {
|
|
4285
4368
|
return await this.declaracaoDeClasse();
|
|
@@ -4351,7 +4434,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4351
4434
|
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO)) &&
|
|
4352
4435
|
this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
4353
4436
|
this.avancarEDevolverAnterior();
|
|
4354
|
-
const declaracaoFuncao = await this.funcao('funcao');
|
|
4437
|
+
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4355
4438
|
declaracaoFuncao.documentacao = new construtos_1.ComentarioComoConstruto(simboloDoc);
|
|
4356
4439
|
return declaracaoFuncao;
|
|
4357
4440
|
}
|
|
@@ -4421,7 +4504,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4421
4504
|
}
|
|
4422
4505
|
async declaracaoAjuda() {
|
|
4423
4506
|
const simboloAjuda = this.avancarEDevolverAnterior();
|
|
4424
|
-
if (this.estaNoFinal() ||
|
|
4507
|
+
if (this.estaNoFinal() ||
|
|
4508
|
+
this.simbolos[this.atual].tipo !== delegua_2.default.PARENTESE_ESQUERDO) {
|
|
4425
4509
|
return new declaracoes_1.Ajuda(simboloAjuda.hashArquivo, simboloAjuda.linha, undefined, false);
|
|
4426
4510
|
}
|
|
4427
4511
|
this.avancarEDevolverAnterior(); // parêntese esquerdo
|
|
@@ -4563,7 +4647,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4563
4647
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorParaConverter', 'qualquer'),
|
|
4564
4648
|
]));
|
|
4565
4649
|
this.pilhaEscopos.definirInformacoesVariavel('todos', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todos', 'lógico', true, [
|
|
4566
|
-
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer')
|
|
4650
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
4567
4651
|
]));
|
|
4568
4652
|
this.pilhaEscopos.definirInformacoesVariavel('todosEmCondicao', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todosEmCondicao', 'lógico', true, [
|
|
4569
4653
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
@@ -5442,20 +5526,16 @@ class AvaliadorSintaticoPitugues {
|
|
|
5442
5526
|
// Uma delas é a variável/constante ser uma classe padrão.
|
|
5443
5527
|
// Isso ocorre quando a importação é feita de uma biblioteca Node.js.
|
|
5444
5528
|
// Nesse caso, o tipo de `entidadeChamada.objeto` começa com uma letra maiúscula.
|
|
5445
|
-
if (entidadeChamada.objeto.tipo &&
|
|
5446
|
-
entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
5529
|
+
if (entidadeChamada.objeto.tipo && entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
5447
5530
|
const tipoCorrespondente = this.tiposDefinidosPorBibliotecas[entidadeChamada.objeto.tipo];
|
|
5448
5531
|
if (!tipoCorrespondente) {
|
|
5449
5532
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Tipo '${entidadeChamada.objeto.tipo}' não foi encontrado entre os tipos definidos por bibliotecas.`);
|
|
5450
5533
|
}
|
|
5451
|
-
if (!(entidadeChamada.simbolo.lexema in
|
|
5452
|
-
tipoCorrespondente.
|
|
5453
|
-
!(entidadeChamada.simbolo.lexema in
|
|
5454
|
-
tipoCorrespondente.propriedades)) {
|
|
5534
|
+
if (!(entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) &&
|
|
5535
|
+
!(entidadeChamada.simbolo.lexema in tipoCorrespondente.propriedades)) {
|
|
5455
5536
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Membro '${entidadeChamada.simbolo.lexema}' não existe no tipo '${entidadeChamada.objeto.tipo}'.`);
|
|
5456
5537
|
}
|
|
5457
|
-
if (entidadeChamada.simbolo.lexema in
|
|
5458
|
-
tipoCorrespondente.metodos) {
|
|
5538
|
+
if (entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) {
|
|
5459
5539
|
const metodoCorrespondente = tipoCorrespondente.metodos[entidadeChamada.simbolo.lexema];
|
|
5460
5540
|
return metodoCorrespondente.tipoRetorno || 'qualquer';
|
|
5461
5541
|
}
|
|
@@ -5588,7 +5668,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
5588
5668
|
pos++;
|
|
5589
5669
|
}
|
|
5590
5670
|
// Verifica se há um identificador obrigatório
|
|
5591
|
-
if (pos >= this.simbolos.length ||
|
|
5671
|
+
if (pos >= this.simbolos.length ||
|
|
5672
|
+
this.simbolos[pos].tipo !== pitugues_2.default.IDENTIFICADOR) {
|
|
5592
5673
|
return false;
|
|
5593
5674
|
}
|
|
5594
5675
|
pos++;
|
|
@@ -5611,7 +5692,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5611
5692
|
}
|
|
5612
5693
|
temPadraoVarComoPalavraChave() {
|
|
5613
5694
|
// Verifica padrão: var identificador = ...
|
|
5614
|
-
if (this.simbolos[this.atual].lexema !==
|
|
5695
|
+
if (this.simbolos[this.atual].lexema !== 'var') {
|
|
5615
5696
|
return false;
|
|
5616
5697
|
}
|
|
5617
5698
|
const proximo = this.simbolos[this.atual + 1];
|
|
@@ -5644,7 +5725,9 @@ class AvaliadorSintaticoPitugues {
|
|
|
5644
5725
|
this.consumir(pitugues_2.default.MULTIPLICACAO, '');
|
|
5645
5726
|
ehRestoAtual = true;
|
|
5646
5727
|
}
|
|
5647
|
-
const identificador = this.consumir(pitugues_2.default.IDENTIFICADOR, ehRestoAtual
|
|
5728
|
+
const identificador = this.consumir(pitugues_2.default.IDENTIFICADOR, ehRestoAtual
|
|
5729
|
+
? 'Esperado nome de variável após operador *.'
|
|
5730
|
+
: 'Esperado nome de variável.');
|
|
5648
5731
|
// Verifica * no nome da variável
|
|
5649
5732
|
if (identificador.lexema.startsWith('*')) {
|
|
5650
5733
|
ehRestoAtual = true;
|
|
@@ -5672,10 +5755,10 @@ class AvaliadorSintaticoPitugues {
|
|
|
5672
5755
|
}
|
|
5673
5756
|
construirValidacaoDesempacotamento(identificador, origem, qtdEsperada) {
|
|
5674
5757
|
const linha = identificador.linha;
|
|
5675
|
-
const chamadaTamanho = new construtos_1.Chamada(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR,
|
|
5676
|
-
const condicaoErro = new construtos_1.Binario(this.hashArquivo, chamadaTamanho, new lexador_1.Simbolo(pitugues_2.default.DIFERENTE,
|
|
5758
|
+
const chamadaTamanho = new construtos_1.Chamada(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR, 'tamanho', null, linha, -1)), [origem]);
|
|
5759
|
+
const condicaoErro = new construtos_1.Binario(this.hashArquivo, chamadaTamanho, new lexador_1.Simbolo(pitugues_2.default.DIFERENTE, '!=', null, linha, -1), new construtos_1.Literal(this.hashArquivo, linha, qtdEsperada, 'número'));
|
|
5677
5760
|
const mensagem = `Erro de execução: Você tentou desempacotar em ${qtdEsperada} variáveis, mas o vetor possui tamanho diferente.`;
|
|
5678
|
-
const falha = new declaracoes_1.Falhar(new lexador_1.Simbolo(pitugues_2.default.FALHAR,
|
|
5761
|
+
const falha = new declaracoes_1.Falhar(new lexador_1.Simbolo(pitugues_2.default.FALHAR, 'falhar', null, linha, -1), new construtos_1.Literal(this.hashArquivo, linha, mensagem, 'texto'));
|
|
5679
5762
|
return new declaracoes_1.Se(condicaoErro, new declaracoes_1.Bloco(this.hashArquivo, linha, [falha]), [], null);
|
|
5680
5763
|
}
|
|
5681
5764
|
async declaracaoDeVariaveis() {
|
|
@@ -5687,7 +5770,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
5687
5770
|
const ehDesempacotamento = qtdIdentificadores > 1 && qtdValores === 1;
|
|
5688
5771
|
if (indexResto > -1) {
|
|
5689
5772
|
if (qtdValores < qtdIdentificadores - 1) {
|
|
5690
|
-
if (!ehDesempacotamento ||
|
|
5773
|
+
if (!ehDesempacotamento ||
|
|
5774
|
+
(ehDesempacotamento && inicializadores[0] instanceof construtos_1.Literal)) {
|
|
5691
5775
|
throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
|
|
5692
5776
|
}
|
|
5693
5777
|
}
|
|
@@ -5723,7 +5807,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5723
5807
|
for (let i = 0; i < identificadores.length; i++) {
|
|
5724
5808
|
const identificador = identificadores[i];
|
|
5725
5809
|
let inicializador;
|
|
5726
|
-
let tipo =
|
|
5810
|
+
let tipo = 'qualquer';
|
|
5727
5811
|
if (i === indexResto) {
|
|
5728
5812
|
const valoresResto = inicializadores.slice(cursorValores, cursorValores + qtdParaResto);
|
|
5729
5813
|
let tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(valoresResto);
|
|
@@ -5770,7 +5854,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
5770
5854
|
}
|
|
5771
5855
|
}
|
|
5772
5856
|
erro(simbolo, mensagemDeErro) {
|
|
5773
|
-
const
|
|
5857
|
+
const simboloParaErro = simbolo || this.simboloAnterior();
|
|
5858
|
+
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simboloParaErro, mensagemDeErro);
|
|
5774
5859
|
this.erros.push(excecao);
|
|
5775
5860
|
return excecao;
|
|
5776
5861
|
}
|
|
@@ -5785,7 +5870,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5785
5870
|
return this.simboloAtual().tipo === tipo;
|
|
5786
5871
|
}
|
|
5787
5872
|
verificarTipoProximoSimbolo(tipo) {
|
|
5788
|
-
if (this.
|
|
5873
|
+
if (this.atual + 1 >= this.simbolos.length)
|
|
5789
5874
|
return false;
|
|
5790
5875
|
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
5791
5876
|
}
|
|
@@ -5930,17 +6015,19 @@ class AvaliadorSintaticoPitugues {
|
|
|
5930
6015
|
case pitugues_2.default.INTERPOLACAO:
|
|
5931
6016
|
const simboloInterpolacao = this.avancarEDevolverAnterior();
|
|
5932
6017
|
const conteudoOriginal = simboloInterpolacao.literal;
|
|
5933
|
-
const codigoTransformado = '"' +
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
6018
|
+
const codigoTransformado = '"' +
|
|
6019
|
+
conteudoOriginal.replace(/\{(.*?)\}/g, (_, miolo) => {
|
|
6020
|
+
// 'miolo' é o texto que estava dentro das chaves. Ex: "valor" ou "valor:.2f"
|
|
6021
|
+
if (miolo.includes(':')) {
|
|
6022
|
+
const [variavel, formato] = miolo.split(':').map((s) => s.trim());
|
|
6023
|
+
if (variavel !== '') {
|
|
6024
|
+
// Transforma {valor:.2f} em "{:.2f}".formatar(valor)
|
|
6025
|
+
return '" + "{:' + formato + '}".formatar(' + variavel + ') + "';
|
|
6026
|
+
}
|
|
5940
6027
|
}
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
6028
|
+
return '" + (' + miolo.trim() + ') + "';
|
|
6029
|
+
}) +
|
|
6030
|
+
'"';
|
|
5944
6031
|
const microLexador = new micro_lexador_pitugues_1.MicroLexadorPitugues();
|
|
5945
6032
|
const retornoMicroLexador = microLexador.mapear(codigoTransformado);
|
|
5946
6033
|
const microAvaliadorSintatico = new micro_avaliador_sintatico_pitugues_1.MicroAvaliadorSintaticoPitugues();
|
|
@@ -5953,7 +6040,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5953
6040
|
}
|
|
5954
6041
|
catch (erro) {
|
|
5955
6042
|
this.erros.push(erro);
|
|
5956
|
-
return new construtos_1.Literal(this.hashArquivo, simboloInterpolacao.linha,
|
|
6043
|
+
return new construtos_1.Literal(this.hashArquivo, simboloInterpolacao.linha, '');
|
|
5957
6044
|
}
|
|
5958
6045
|
const declaracao = retornoMicroAvaliador.declaracoes[0];
|
|
5959
6046
|
return declaracao.expressao;
|
|
@@ -6011,11 +6098,11 @@ class AvaliadorSintaticoPitugues {
|
|
|
6011
6098
|
let passo = null;
|
|
6012
6099
|
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.DOIS_PONTOS)) {
|
|
6013
6100
|
ehFatiamento = true;
|
|
6014
|
-
if (!this.verificarTipoSimboloAtual(pitugues_2.default.DOIS_PONTOS)
|
|
6015
|
-
|
|
6101
|
+
if (!this.verificarTipoSimboloAtual(pitugues_2.default.DOIS_PONTOS) &&
|
|
6102
|
+
!this.verificarTipoSimboloAtual(pitugues_2.default.COLCHETE_DIREITO))
|
|
6016
6103
|
fim = await this.expressao();
|
|
6017
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.DOIS_PONTOS)
|
|
6018
|
-
|
|
6104
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.DOIS_PONTOS) &&
|
|
6105
|
+
!this.verificarTipoSimboloAtual(pitugues_2.default.COLCHETE_DIREITO))
|
|
6019
6106
|
passo = await this.expressao();
|
|
6020
6107
|
}
|
|
6021
6108
|
const simboloFechamento = this.consumir(pitugues_2.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
@@ -6147,7 +6234,9 @@ class AvaliadorSintaticoPitugues {
|
|
|
6147
6234
|
}
|
|
6148
6235
|
async seTernario() {
|
|
6149
6236
|
let expressaoEntao = await this.ou();
|
|
6150
|
-
if (this.simbolos[this.atual] &&
|
|
6237
|
+
if (this.simbolos[this.atual] &&
|
|
6238
|
+
this.simbolos[this.atual].tipo === pitugues_2.default.SE &&
|
|
6239
|
+
expressaoEntao.linha === this.simbolos[this.atual].linha) {
|
|
6151
6240
|
while (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.SE)) {
|
|
6152
6241
|
const operador = this.simbolos[this.atual - 1];
|
|
6153
6242
|
const expressaoOuCondicao = await this.seTernario();
|
|
@@ -6249,54 +6338,40 @@ class AvaliadorSintaticoPitugues {
|
|
|
6249
6338
|
let declaracoes = [];
|
|
6250
6339
|
let simboloAtual = this.simboloAtual();
|
|
6251
6340
|
const simboloAnterior = this.simboloAnterior();
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
//
|
|
6341
|
+
if (!simboloAtual) {
|
|
6342
|
+
throw this.erro(simboloAnterior, 'Esperado corpo do escopo após a declaração.');
|
|
6343
|
+
}
|
|
6344
|
+
// Declaração na mesma linha (ex: 'se verdadeiro: escreva("Oi")')
|
|
6256
6345
|
if (simboloAtual.linha === simboloAnterior.linha) {
|
|
6257
|
-
const
|
|
6258
|
-
if (
|
|
6259
|
-
|
|
6260
|
-
declaracoes = declaracoes.concat(declaracoesBloco);
|
|
6261
|
-
}
|
|
6262
|
-
else {
|
|
6263
|
-
declaracoes.push(declaracoesBloco);
|
|
6264
|
-
}
|
|
6265
|
-
}
|
|
6346
|
+
const retorno = await this.resolverDeclaracaoForaDeBloco();
|
|
6347
|
+
if (retorno !== null)
|
|
6348
|
+
declaracoes = declaracoes.concat(retorno);
|
|
6266
6349
|
}
|
|
6267
6350
|
else {
|
|
6268
|
-
//
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
if (
|
|
6351
|
+
// Bloco de múltiplas linhas baseado em indentação
|
|
6352
|
+
let espacosAtual = this
|
|
6353
|
+
.localizacoes[simboloAtual.linha]
|
|
6354
|
+
.espacosIndentacao;
|
|
6355
|
+
const espacosAnterior = this
|
|
6356
|
+
.localizacoes[simboloAnterior.linha]
|
|
6357
|
+
.espacosIndentacao;
|
|
6358
|
+
if (espacosAtual <= espacosAnterior) {
|
|
6276
6359
|
throw this.erro(simboloAtual, `Indentação inconsistente na linha ${simboloAtual.linha}. ` +
|
|
6277
|
-
`Esperado: >= ${
|
|
6278
|
-
`Atual: ${
|
|
6279
|
-
}
|
|
6280
|
-
|
|
6281
|
-
//
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
while (espacosIndentacaoLinhaAtual === espacosIndentacaoBloco) {
|
|
6287
|
-
const retornoDeclaracao = await this.resolverDeclaracaoForaDeBloco();
|
|
6288
|
-
if (retornoDeclaracao !== null) {
|
|
6289
|
-
if (Array.isArray(retornoDeclaracao)) {
|
|
6290
|
-
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
6291
|
-
}
|
|
6292
|
-
else {
|
|
6293
|
-
declaracoes.push(retornoDeclaracao);
|
|
6294
|
-
}
|
|
6295
|
-
}
|
|
6360
|
+
`Esperado: >= ${espacosAnterior}. ` +
|
|
6361
|
+
`Atual: ${espacosAtual}`);
|
|
6362
|
+
}
|
|
6363
|
+
const indentacaoBloco = espacosAtual;
|
|
6364
|
+
// Consome as declarações enquanto a indentação for estritamente igual à do bloco
|
|
6365
|
+
while (simboloAtual && espacosAtual === indentacaoBloco) {
|
|
6366
|
+
const retorno = await this.resolverDeclaracaoForaDeBloco();
|
|
6367
|
+
if (retorno !== null)
|
|
6368
|
+
declaracoes = declaracoes.concat(retorno);
|
|
6296
6369
|
simboloAtual = this.simboloAtual();
|
|
6297
|
-
if (
|
|
6298
|
-
|
|
6299
|
-
|
|
6370
|
+
if (simboloAtual) {
|
|
6371
|
+
espacosAtual = this
|
|
6372
|
+
.localizacoes[simboloAtual.linha]
|
|
6373
|
+
.espacosIndentacao;
|
|
6374
|
+
}
|
|
6300
6375
|
}
|
|
6301
6376
|
}
|
|
6302
6377
|
this.pilhaEscopos.removerUltimo();
|
|
@@ -6306,7 +6381,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6306
6381
|
try {
|
|
6307
6382
|
this.blocos += 1;
|
|
6308
6383
|
const condicao = await this.expressao();
|
|
6309
|
-
const bloco = await this.resolverDeclaracao();
|
|
6384
|
+
const bloco = (await this.resolverDeclaracao());
|
|
6310
6385
|
return new declaracoes_1.Enquanto(condicao, bloco);
|
|
6311
6386
|
}
|
|
6312
6387
|
finally {
|
|
@@ -6380,7 +6455,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6380
6455
|
}
|
|
6381
6456
|
this.pilhaEscopos.definirInformacoesVariavel(nomeVariavelIteracao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(nomeVariavelIteracao.lexema, tipoVetor.slice(0, -2)));
|
|
6382
6457
|
// TODO: Talvez não seja uma ideia melhor chamar o método de `Bloco` aqui?
|
|
6383
|
-
const corpo = await this.resolverDeclaracao();
|
|
6458
|
+
const corpo = (await this.resolverDeclaracao());
|
|
6384
6459
|
return new declaracoes_1.ParaCada(this.hashArquivo, Number(simboloPara.linha), new construtos_1.Variavel(this.hashArquivo, nomeVariavelIteracao), vetor, corpo);
|
|
6385
6460
|
}
|
|
6386
6461
|
async declaracaoPara() {
|
|
@@ -6412,7 +6487,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6412
6487
|
this.pilhaEscopos.definirInformacoesVariavel(simboloSegundaVariavel.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(simboloSegundaVariavel.lexema, 'qualquer'));
|
|
6413
6488
|
}
|
|
6414
6489
|
// TODO: Talvez não seja uma ideia melhor chamar o método de `Bloco` aqui?
|
|
6415
|
-
const corpo = await this.resolverDeclaracao();
|
|
6490
|
+
const corpo = (await this.resolverDeclaracao());
|
|
6416
6491
|
return new declaracoes_1.ParaCada(this.hashArquivo, Number(simboloPara.linha), variavelIteracao, alvoIteracao, corpo);
|
|
6417
6492
|
}
|
|
6418
6493
|
finally {
|
|
@@ -6441,7 +6516,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6441
6516
|
}
|
|
6442
6517
|
async declaracaoSe() {
|
|
6443
6518
|
const condicao = await this.expressao();
|
|
6444
|
-
const caminhoEntao = await this.resolverDeclaracao();
|
|
6519
|
+
const caminhoEntao = (await this.resolverDeclaracao());
|
|
6445
6520
|
let caminhoSenao = null;
|
|
6446
6521
|
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.SENAO, pitugues_2.default.SENÃO)) {
|
|
6447
6522
|
caminhoSenao = await this.resolverDeclaracao();
|
|
@@ -6519,11 +6594,13 @@ class AvaliadorSintaticoPitugues {
|
|
|
6519
6594
|
this.consumir(pitugues_2.default.DOIS_PONTOS, `Esperado ':' antes do escopo do bloco 'pegue'.`);
|
|
6520
6595
|
this.pilhaEscopos.definirInformacoesVariavel(variavelExcecao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(variavelExcecao.lexema, 'qualquer'));
|
|
6521
6596
|
const corpo = await this.blocoEscopo();
|
|
6522
|
-
blocoPegue = new construtos_1.FuncaoConstruto(this.hashArquivo, simboloTente.linha, [
|
|
6523
|
-
|
|
6597
|
+
blocoPegue = new construtos_1.FuncaoConstruto(this.hashArquivo, simboloTente.linha, [
|
|
6598
|
+
{
|
|
6599
|
+
abrangencia: 'padrao',
|
|
6524
6600
|
nome: variavelExcecao,
|
|
6525
|
-
tipoDado:
|
|
6526
|
-
}
|
|
6601
|
+
tipoDado: 'qualquer',
|
|
6602
|
+
},
|
|
6603
|
+
], corpo, 'vazio', false);
|
|
6527
6604
|
}
|
|
6528
6605
|
else {
|
|
6529
6606
|
// Caso 2: sem parâmetro de erro.
|
|
@@ -6548,7 +6625,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6548
6625
|
const simboloFazer = this.simboloAnterior();
|
|
6549
6626
|
try {
|
|
6550
6627
|
this.blocos += 1;
|
|
6551
|
-
const declaracaoOuBlocoFazer = await this.resolverDeclaracao();
|
|
6628
|
+
const declaracaoOuBlocoFazer = (await this.resolverDeclaracao());
|
|
6552
6629
|
this.consumir(pitugues_2.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo da declaração 'fazer'.");
|
|
6553
6630
|
const condicaoEnquanto = await this.expressao();
|
|
6554
6631
|
return new declaracoes_1.Fazer(simboloFazer.hashArquivo, Number(simboloFazer.linha), declaracaoOuBlocoFazer, condicaoEnquanto);
|
|
@@ -6714,7 +6791,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6714
6791
|
const simboloAnterior = this.simbolos[this.atual - 1];
|
|
6715
6792
|
if (simboloAnterior.tipo === pitugues_2.default.IDENTIFICADOR) {
|
|
6716
6793
|
this.consumir(pitugues_2.default.DOIS_PONTOS, "Esperado ':' antes do escopo da classe.");
|
|
6717
|
-
const tipoPropriedade = this.consumir(pitugues_2.default.IDENTIFICADOR,
|
|
6794
|
+
const tipoPropriedade = this.consumir(pitugues_2.default.IDENTIFICADOR, 'Esperado tipo de propriedade após dois-pontos, em declaração de classe.');
|
|
6718
6795
|
const propriedade = new declaracoes_1.PropriedadeClasse(simboloAnterior, tipoPropriedade.lexema, []);
|
|
6719
6796
|
propriedades.push(propriedade);
|
|
6720
6797
|
}
|
|
@@ -6770,11 +6847,10 @@ class AvaliadorSintaticoPitugues {
|
|
|
6770
6847
|
*/
|
|
6771
6848
|
async resolverDeclaracaoForaDeBloco() {
|
|
6772
6849
|
try {
|
|
6773
|
-
if (
|
|
6774
|
-
this.verificarTipoSimboloAtual(pitugues_2.default.FUNÇÃO))
|
|
6775
|
-
this.verificarTipoProximoSimbolo(pitugues_2.default.IDENTIFICADOR)) {
|
|
6850
|
+
if (this.verificarTipoSimboloAtual(pitugues_2.default.FUNCAO) ||
|
|
6851
|
+
this.verificarTipoSimboloAtual(pitugues_2.default.FUNÇÃO)) {
|
|
6776
6852
|
this.avancarEDevolverAnterior();
|
|
6777
|
-
return await this.funcao('
|
|
6853
|
+
return await this.funcao('da função');
|
|
6778
6854
|
}
|
|
6779
6855
|
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.CLASSE))
|
|
6780
6856
|
return await this.declaracaoDeClasse();
|
|
@@ -6869,8 +6945,10 @@ class AvaliadorSintaticoPitugues {
|
|
|
6869
6945
|
case pitugues_2.default.DE: {
|
|
6870
6946
|
const proximo = this.simbolos[this.atual + 1];
|
|
6871
6947
|
const aposProximo = this.simbolos[this.atual + 2];
|
|
6872
|
-
if (proximo &&
|
|
6873
|
-
|
|
6948
|
+
if (proximo &&
|
|
6949
|
+
proximo.tipo === pitugues_2.default.IDENTIFICADOR &&
|
|
6950
|
+
aposProximo &&
|
|
6951
|
+
aposProximo.tipo === pitugues_2.default.IMPORTAR) {
|
|
6874
6952
|
this.avancarEDevolverAnterior();
|
|
6875
6953
|
return this.declaracaoImportarDe();
|
|
6876
6954
|
}
|
|
@@ -6985,7 +7063,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6985
7063
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'qualquer'),
|
|
6986
7064
|
]));
|
|
6987
7065
|
this.pilhaEscopos.definirInformacoesVariavel('todos', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todos', 'lógico', true, [
|
|
6988
|
-
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer')
|
|
7066
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
6989
7067
|
]));
|
|
6990
7068
|
this.pilhaEscopos.definirInformacoesVariavel('todosEmCondicao', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todosEmCondicao', 'lógico', true, [
|
|
6991
7069
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
@@ -6995,7 +7073,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6995
7073
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
|
|
6996
7074
|
]));
|
|
6997
7075
|
this.pilhaEscopos.definirInformacoesVariavel('vetor', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'vetor', true, [
|
|
6998
|
-
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tupla', 'qualquer')
|
|
7076
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tupla', 'qualquer'),
|
|
6999
7077
|
]));
|
|
7000
7078
|
}
|
|
7001
7079
|
async analisar(retornoLexador, hashArquivo) {
|
|
@@ -7022,7 +7100,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
7022
7100
|
else {
|
|
7023
7101
|
declaracoes.push(retornoDeclaracao);
|
|
7024
7102
|
}
|
|
7025
|
-
if (!this.estaNoFinal() &&
|
|
7103
|
+
if (!this.estaNoFinal() &&
|
|
7104
|
+
this.verificarTipoSimboloAtual(pitugues_2.default.PONTO_E_VIRGULA)) {
|
|
7026
7105
|
// Verificar se este ; está na mesma linha da declaração anterior
|
|
7027
7106
|
const declaracaoAnterior = declaracoes[declaracoes.length - 1];
|
|
7028
7107
|
const linhaDeclaraoAnterior = declaracaoAnterior.linha || 0;
|
|
@@ -7408,12 +7487,12 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7408
7487
|
*/
|
|
7409
7488
|
construtoTextoMultilinhas() {
|
|
7410
7489
|
const segundoColchete = this.consumir(prisma_1.default.COLCHETE_ESQUERDO, "Esperado '[' antes do texto multilinhas.");
|
|
7411
|
-
let texto =
|
|
7490
|
+
let texto = '';
|
|
7412
7491
|
let linha = segundoColchete.linha;
|
|
7413
7492
|
while (!this.verificarSeSimboloAtualEIgualA(prisma_1.default.COLCHETE_DIREITO)) {
|
|
7414
|
-
texto += this.simbolos[this.atual].lexema +
|
|
7493
|
+
texto += this.simbolos[this.atual].lexema + ' ';
|
|
7415
7494
|
if (this.simbolos[this.atual].linha !== linha) {
|
|
7416
|
-
texto +=
|
|
7495
|
+
texto += '\n';
|
|
7417
7496
|
linha = this.simbolos[this.atual].linha;
|
|
7418
7497
|
}
|
|
7419
7498
|
this.avancarEDevolverAnterior();
|
|
@@ -7645,7 +7724,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7645
7724
|
try {
|
|
7646
7725
|
this.blocos += 1;
|
|
7647
7726
|
const condicao = await this.expressao();
|
|
7648
|
-
const bloco = await this.resolverDeclaracao();
|
|
7727
|
+
const bloco = (await this.resolverDeclaracao());
|
|
7649
7728
|
return new declaracoes_1.Enquanto(condicao, bloco);
|
|
7650
7729
|
}
|
|
7651
7730
|
finally {
|
|
@@ -8671,7 +8750,7 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8671
8750
|
async declaracaoSe() {
|
|
8672
8751
|
const condicao = await this.expressao();
|
|
8673
8752
|
this.consumir(tenda_1.default.ENTÃO, "Esperado 'então' após a condição.");
|
|
8674
|
-
const caminhoEntao = await this.resolverDeclaracao();
|
|
8753
|
+
const caminhoEntao = (await this.resolverDeclaracao());
|
|
8675
8754
|
let caminhoSenao = null;
|
|
8676
8755
|
if (this.verificarSeSimboloAtualEIgualA(tenda_1.default.SENÃO)) {
|
|
8677
8756
|
caminhoSenao = await this.resolverDeclaracao();
|
|
@@ -9782,15 +9861,51 @@ const estruturas_1 = require("../interpretador/estruturas");
|
|
|
9782
9861
|
const construtos_1 = require("../construtos");
|
|
9783
9862
|
const quebras_1 = require("../quebras");
|
|
9784
9863
|
const configTuplas = {
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
|
|
9792
|
-
|
|
9793
|
-
|
|
9864
|
+
Dupla: { Classe: construtos_1.Dupla, props: ['primeiro', 'segundo'] },
|
|
9865
|
+
Trio: { Classe: construtos_1.Trio, props: ['primeiro', 'segundo', 'terceiro'] },
|
|
9866
|
+
Quarteto: { Classe: construtos_1.Quarteto, props: ['primeiro', 'segundo', 'terceiro', 'quarto'] },
|
|
9867
|
+
Quinteto: { Classe: construtos_1.Quinteto, props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto'] },
|
|
9868
|
+
Sexteto: {
|
|
9869
|
+
Classe: construtos_1.Sexteto,
|
|
9870
|
+
props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto'],
|
|
9871
|
+
},
|
|
9872
|
+
Septeto: {
|
|
9873
|
+
Classe: construtos_1.Septeto,
|
|
9874
|
+
props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo'],
|
|
9875
|
+
},
|
|
9876
|
+
Octeto: {
|
|
9877
|
+
Classe: construtos_1.Octeto,
|
|
9878
|
+
props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo', 'oitavo'],
|
|
9879
|
+
},
|
|
9880
|
+
Noneto: {
|
|
9881
|
+
Classe: construtos_1.Noneto,
|
|
9882
|
+
props: [
|
|
9883
|
+
'primeiro',
|
|
9884
|
+
'segundo',
|
|
9885
|
+
'terceiro',
|
|
9886
|
+
'quarto',
|
|
9887
|
+
'quinto',
|
|
9888
|
+
'sexto',
|
|
9889
|
+
'setimo',
|
|
9890
|
+
'oitavo',
|
|
9891
|
+
'nono',
|
|
9892
|
+
],
|
|
9893
|
+
},
|
|
9894
|
+
Deceto: {
|
|
9895
|
+
Classe: construtos_1.Deceto,
|
|
9896
|
+
props: [
|
|
9897
|
+
'primeiro',
|
|
9898
|
+
'segundo',
|
|
9899
|
+
'terceiro',
|
|
9900
|
+
'quarto',
|
|
9901
|
+
'quinto',
|
|
9902
|
+
'sexto',
|
|
9903
|
+
'setimo',
|
|
9904
|
+
'oitavo',
|
|
9905
|
+
'nono',
|
|
9906
|
+
'decimo',
|
|
9907
|
+
],
|
|
9908
|
+
},
|
|
9794
9909
|
};
|
|
9795
9910
|
const mapaConstrutoresTupla = {
|
|
9796
9911
|
2: construtos_1.Dupla,
|
|
@@ -9801,18 +9916,39 @@ const mapaConstrutoresTupla = {
|
|
|
9801
9916
|
7: construtos_1.Septeto,
|
|
9802
9917
|
8: construtos_1.Octeto,
|
|
9803
9918
|
9: construtos_1.Noneto,
|
|
9804
|
-
10: construtos_1.Deceto
|
|
9919
|
+
10: construtos_1.Deceto,
|
|
9805
9920
|
};
|
|
9806
9921
|
const mapaPropriedadesTuplas = {
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9922
|
+
Dupla: ['primeiro', 'segundo'],
|
|
9923
|
+
Trio: ['primeiro', 'segundo', 'terceiro'],
|
|
9924
|
+
Quarteto: ['primeiro', 'segundo', 'terceiro', 'quarto'],
|
|
9925
|
+
Quinteto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto'],
|
|
9926
|
+
Sexteto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto'],
|
|
9927
|
+
Septeto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo'],
|
|
9928
|
+
Octeto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo', 'oitavo'],
|
|
9929
|
+
Noneto: [
|
|
9930
|
+
'primeiro',
|
|
9931
|
+
'segundo',
|
|
9932
|
+
'terceiro',
|
|
9933
|
+
'quarto',
|
|
9934
|
+
'quinto',
|
|
9935
|
+
'sexto',
|
|
9936
|
+
'setimo',
|
|
9937
|
+
'oitavo',
|
|
9938
|
+
'nono',
|
|
9939
|
+
],
|
|
9940
|
+
Deceto: [
|
|
9941
|
+
'primeiro',
|
|
9942
|
+
'segundo',
|
|
9943
|
+
'terceiro',
|
|
9944
|
+
'quarto',
|
|
9945
|
+
'quinto',
|
|
9946
|
+
'sexto',
|
|
9947
|
+
'setimo',
|
|
9948
|
+
'oitavo',
|
|
9949
|
+
'nono',
|
|
9950
|
+
'decimo',
|
|
9951
|
+
],
|
|
9816
9952
|
};
|
|
9817
9953
|
/**
|
|
9818
9954
|
* Compara dois valores (números ou vetores).
|
|
@@ -9930,16 +10066,15 @@ async function arredondar(interpretador, numero, casasDecimais) {
|
|
|
9930
10066
|
const valorNumero = interpretador.resolverValor(numero);
|
|
9931
10067
|
const valorCasas = interpretador.resolverValor(casasDecimais);
|
|
9932
10068
|
if (numero == undefined || numero == null) {
|
|
9933
|
-
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null,
|
|
10069
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, 'Erro: arredondar() deve receber um número.', interpretador.linhaDeclaracaoAtual));
|
|
9934
10070
|
}
|
|
9935
|
-
if (typeof numero !==
|
|
10071
|
+
if (typeof numero !== 'number') {
|
|
9936
10072
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `Erro de Tipo: arredondar() espera um número, mas recebeu '${typeof valorNumero}'.`, interpretador.linhaDeclaracaoAtual));
|
|
9937
10073
|
}
|
|
9938
10074
|
const fator = Math.pow(10, valorCasas);
|
|
9939
10075
|
const resultado = Math.round(valorNumero * fator) / fator;
|
|
9940
10076
|
return Promise.resolve(resultado);
|
|
9941
10077
|
}
|
|
9942
|
-
;
|
|
9943
10078
|
/**
|
|
9944
10079
|
* Clona profundamente uma variável ou constante em Delégua.
|
|
9945
10080
|
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
@@ -10328,8 +10463,10 @@ async function intervalo(interpretador, valorInicial, valorFinal, valorPasso) {
|
|
|
10328
10463
|
}
|
|
10329
10464
|
// intervalo(inicio, parada) ou intervalo(inicio, parada, passo)
|
|
10330
10465
|
else {
|
|
10331
|
-
if (typeof primeiroParam !== 'number' ||
|
|
10332
|
-
|
|
10466
|
+
if (typeof primeiroParam !== 'number' ||
|
|
10467
|
+
isNaN(primeiroParam) ||
|
|
10468
|
+
typeof segundoParam !== 'number' ||
|
|
10469
|
+
isNaN(segundoParam)) {
|
|
10333
10470
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10334
10471
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
10335
10472
|
linha: interpretador.linhaDeclaracaoAtual,
|
|
@@ -10712,14 +10849,18 @@ async function tamanho(interpretador, objeto) {
|
|
|
10712
10849
|
const metodos = valorObjeto.metodos;
|
|
10713
10850
|
let tamanho = 0;
|
|
10714
10851
|
const metodoInicializacao = metodos.inicializacao;
|
|
10715
|
-
if (metodoInicializacao &&
|
|
10852
|
+
if (metodoInicializacao &&
|
|
10853
|
+
!Array.isArray(metodoInicializacao) &&
|
|
10854
|
+
metodoInicializacao.eInicializador) {
|
|
10716
10855
|
tamanho = metodoInicializacao.declaracao.parametros.length;
|
|
10717
10856
|
}
|
|
10718
10857
|
else if (Array.isArray(metodoInicializacao)) {
|
|
10719
10858
|
// Em caso de construtores sobrecarregados, `metodos.inicializacao` pode ser um array.
|
|
10720
10859
|
// Usamos o maior número de parâmetros entre as sobrecargas que são inicializadores.
|
|
10721
10860
|
for (const inicializador of metodoInicializacao) {
|
|
10722
|
-
if (inicializador &&
|
|
10861
|
+
if (inicializador &&
|
|
10862
|
+
inicializador.eInicializador &&
|
|
10863
|
+
((_a = inicializador.declaracao) === null || _a === void 0 ? void 0 : _a.parametros)) {
|
|
10723
10864
|
const aridade = inicializador.declaracao.parametros.length;
|
|
10724
10865
|
if (aridade > tamanho) {
|
|
10725
10866
|
tamanho = aridade;
|
|
@@ -10789,8 +10930,7 @@ async function todosEmCondicao(interpretador, iteravel, funcaoCondicional) {
|
|
|
10789
10930
|
}, 'Parâmetro inválido. O primeiro parâmetro deve ser um iterável.'));
|
|
10790
10931
|
}
|
|
10791
10932
|
const valorFuncao = interpretador.resolverValor(funcaoCondicional);
|
|
10792
|
-
const ehFuncaoValida = valorFuncao instanceof estruturas_1.DeleguaFuncao ||
|
|
10793
|
-
valorFuncao instanceof funcao_padrao_1.FuncaoPadrao;
|
|
10933
|
+
const ehFuncaoValida = valorFuncao instanceof estruturas_1.DeleguaFuncao || valorFuncao instanceof funcao_padrao_1.FuncaoPadrao;
|
|
10794
10934
|
if (!ehFuncaoValida) {
|
|
10795
10935
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10796
10936
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
@@ -10815,7 +10955,7 @@ async function todosEmCondicao(interpretador, iteravel, funcaoCondicional) {
|
|
|
10815
10955
|
*/
|
|
10816
10956
|
async function tupla(interpretador, vetor) {
|
|
10817
10957
|
const valorVetor = interpretador.resolverValor(vetor);
|
|
10818
|
-
const elementos = valorVetor.map(item => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, interpretador.resolverValor(item)));
|
|
10958
|
+
const elementos = valorVetor.map((item) => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, interpretador.resolverValor(item)));
|
|
10819
10959
|
return new construtos_1.TuplaN(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, elementos);
|
|
10820
10960
|
}
|
|
10821
10961
|
async function vetor(interpretador, tupla) {
|
|
@@ -10834,9 +10974,10 @@ async function vetor(interpretador, tupla) {
|
|
|
10834
10974
|
const nomeClasse = objetoTupla.constructor.name;
|
|
10835
10975
|
const props = mapaPropriedadesTuplas[nomeClasse];
|
|
10836
10976
|
if (props) {
|
|
10837
|
-
resultado = props.map(prop => objetoTupla[prop]);
|
|
10977
|
+
resultado = props.map((prop) => objetoTupla[prop]);
|
|
10838
10978
|
}
|
|
10839
|
-
else if (objetoTupla.elementos &&
|
|
10979
|
+
else if (objetoTupla.elementos &&
|
|
10980
|
+
Array.isArray(objetoTupla.elementos)) {
|
|
10840
10981
|
resultado = objetoTupla.elementos;
|
|
10841
10982
|
}
|
|
10842
10983
|
}
|
|
@@ -10862,14 +11003,13 @@ exports.default = {
|
|
|
10862
11003
|
if (!(objetoTupla instanceof construtos_1.TuplaN)) {
|
|
10863
11004
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "paraVetor" só pode ser chamada em tuplas.`, interpretador.linhaDeclaracaoAtual));
|
|
10864
11005
|
}
|
|
10865
|
-
const valoresPuros = objetoTupla.elementos.map(elemento => interpretador.resolverValor(elemento));
|
|
11006
|
+
const valoresPuros = objetoTupla.elementos.map((elemento) => interpretador.resolverValor(elemento));
|
|
10866
11007
|
return Promise.resolve(valoresPuros);
|
|
10867
11008
|
},
|
|
10868
11009
|
assinaturaFormato: 'tupla.paraVetor()',
|
|
10869
|
-
documentacao: '# `tupla.paraVetor()` \n \n' +
|
|
10870
|
-
'Converte a tupla atual em um array.',
|
|
11010
|
+
documentacao: '# `tupla.paraVetor()` \n \n' + 'Converte a tupla atual em um array.',
|
|
10871
11011
|
exemploCodigo: 'tupla.paraVetor()',
|
|
10872
|
-
}
|
|
11012
|
+
},
|
|
10873
11013
|
};
|
|
10874
11014
|
|
|
10875
11015
|
},{"../../../construtos":62,"../../../excecoes":131}],29:[function(require,module,exports){
|
|
@@ -10951,7 +11091,7 @@ exports.default = {
|
|
|
10951
11091
|
implementacao: (interpretador, valor) => {
|
|
10952
11092
|
return Promise.resolve(Object.values(valor));
|
|
10953
11093
|
},
|
|
10954
|
-
}
|
|
11094
|
+
},
|
|
10955
11095
|
};
|
|
10956
11096
|
|
|
10957
11097
|
},{"../construtos":62,"../informacao-elemento-sintatico":138}],30:[function(require,module,exports){
|
|
@@ -11072,7 +11212,7 @@ const implementacaoParticao = (interpretador, texto, separador, ...args) => {
|
|
|
11072
11212
|
const depois = texto.substring(indice + separador.length);
|
|
11073
11213
|
partes = [antes, separador, depois];
|
|
11074
11214
|
}
|
|
11075
|
-
const elementos = partes.map(p => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, p, 'texto'));
|
|
11215
|
+
const elementos = partes.map((p) => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, p, 'texto'));
|
|
11076
11216
|
const tupla = new construtos_1.TuplaN(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, elementos);
|
|
11077
11217
|
return Promise.resolve(tupla);
|
|
11078
11218
|
};
|
|
@@ -11454,7 +11594,7 @@ const mapaConstrutoresTupla = {
|
|
|
11454
11594
|
7: construtos_1.Septeto,
|
|
11455
11595
|
8: construtos_1.Octeto,
|
|
11456
11596
|
9: construtos_1.Noneto,
|
|
11457
|
-
10: construtos_1.Deceto
|
|
11597
|
+
10: construtos_1.Deceto,
|
|
11458
11598
|
};
|
|
11459
11599
|
exports.default = {
|
|
11460
11600
|
adicionar: {
|
|
@@ -12085,7 +12225,7 @@ class AjudaComoConstruto {
|
|
|
12085
12225
|
return retorno;
|
|
12086
12226
|
}
|
|
12087
12227
|
paraTextoSaida() {
|
|
12088
|
-
throw new Error(
|
|
12228
|
+
throw new Error('Method not implemented.');
|
|
12089
12229
|
}
|
|
12090
12230
|
}
|
|
12091
12231
|
exports.AjudaComoConstruto = AjudaComoConstruto;
|
|
@@ -12191,9 +12331,12 @@ class Atribuir {
|
|
|
12191
12331
|
const alvoComoVariavel = alvo;
|
|
12192
12332
|
const tipoAlvo = alvoComoVariavel === null || alvoComoVariavel === void 0 ? void 0 : alvoComoVariavel.tipo;
|
|
12193
12333
|
const alvoSuportaIndice = alvo instanceof variavel_1.Variavel &&
|
|
12194
|
-
(tipoAlvo === 'vetor' ||
|
|
12334
|
+
(tipoAlvo === 'vetor' ||
|
|
12335
|
+
tipoAlvo === 'dicionário' ||
|
|
12336
|
+
tipoAlvo === 'qualquer' ||
|
|
12337
|
+
(tipoAlvo === null || tipoAlvo === void 0 ? void 0 : tipoAlvo.endsWith('[]')));
|
|
12195
12338
|
if (!alvoSuportaIndice) {
|
|
12196
|
-
throw new Error(
|
|
12339
|
+
throw new Error('`indice` só pode ser informado quando o alvo for uma variável de vetor ou dicionário.');
|
|
12197
12340
|
}
|
|
12198
12341
|
this.indice = indice;
|
|
12199
12342
|
}
|
|
@@ -12262,8 +12405,7 @@ class Binario {
|
|
|
12262
12405
|
['logico', 'lógico'].includes(this.direita.tipo)) {
|
|
12263
12406
|
return 'lógico';
|
|
12264
12407
|
}
|
|
12265
|
-
if (this.esquerda.tipo === 'texto' ||
|
|
12266
|
-
this.direita.tipo === 'texto') {
|
|
12408
|
+
if (this.esquerda.tipo === 'texto' || this.direita.tipo === 'texto') {
|
|
12267
12409
|
return 'texto';
|
|
12268
12410
|
}
|
|
12269
12411
|
if (['numero', 'número'].includes(this.esquerda.tipo) ||
|
|
@@ -12429,7 +12571,9 @@ class Decorador {
|
|
|
12429
12571
|
continue;
|
|
12430
12572
|
}
|
|
12431
12573
|
const valor = this.atributos[chave];
|
|
12432
|
-
const valorTexto = valor && typeof valor === 'object' && typeof valor.paraTexto === 'function'
|
|
12574
|
+
const valorTexto = valor && typeof valor === 'object' && typeof valor.paraTexto === 'function'
|
|
12575
|
+
? valor.paraTexto()
|
|
12576
|
+
: valor;
|
|
12433
12577
|
atributos += `${chave}=${valorTexto} `;
|
|
12434
12578
|
}
|
|
12435
12579
|
if (atributos.length > 0) {
|
|
@@ -13130,11 +13274,13 @@ class TuplaN extends tupla_1.Tupla {
|
|
|
13130
13274
|
return await visitante.visitarExpressaoTuplaN(this);
|
|
13131
13275
|
}
|
|
13132
13276
|
paraTexto() {
|
|
13133
|
-
const elementosTexto = this.elementos.map(elemento => elemento.paraTexto()).join(', ');
|
|
13277
|
+
const elementosTexto = this.elementos.map((elemento) => elemento.paraTexto()).join(', ');
|
|
13134
13278
|
return `(${elementosTexto})`;
|
|
13135
13279
|
}
|
|
13136
13280
|
paraTextoSaida() {
|
|
13137
|
-
const elementosTexto = this.elementos
|
|
13281
|
+
const elementosTexto = this.elementos
|
|
13282
|
+
.map((elemento) => elemento.paraTextoSaida())
|
|
13283
|
+
.join(', ');
|
|
13138
13284
|
return `(${elementosTexto})`;
|
|
13139
13285
|
}
|
|
13140
13286
|
}
|
|
@@ -14024,7 +14170,7 @@ const geracao_identificadores_1 = require("../geracao-identificadores");
|
|
|
14024
14170
|
* Uma declaração de função.
|
|
14025
14171
|
*/
|
|
14026
14172
|
class FuncaoDeclaracao extends declaracao_1.Declaracao {
|
|
14027
|
-
constructor(simbolo, funcao, tipoRetorno = 'qualquer', decoradores = [], acesso = 'publico', estatico = false, abstrato = false, eObtenedor = false, eDefinidor = false) {
|
|
14173
|
+
constructor(simbolo, funcao, tipoRetorno = 'qualquer', decoradores = [], acesso = 'publico', estatico = false, abstrato = false, eObtenedor = false, eDefinidor = false, eFuncaoDeDecorador = false) {
|
|
14028
14174
|
super(Number(simbolo.linha), simbolo.hashArquivo);
|
|
14029
14175
|
this.id = (0, geracao_identificadores_1.uuidv4)();
|
|
14030
14176
|
this.simbolo = simbolo;
|
|
@@ -14036,6 +14182,7 @@ class FuncaoDeclaracao extends declaracao_1.Declaracao {
|
|
|
14036
14182
|
this.abstrato = abstrato;
|
|
14037
14183
|
this.eObtenedor = eObtenedor;
|
|
14038
14184
|
this.eDefinidor = eDefinidor;
|
|
14185
|
+
this.eFuncaoDeDecorador = eFuncaoDeDecorador;
|
|
14039
14186
|
}
|
|
14040
14187
|
async aceitar(visitante) {
|
|
14041
14188
|
return await visitante.visitarDeclaracaoDefinicaoFuncao(this);
|
|
@@ -14675,7 +14822,11 @@ class EstilizadorDelegua {
|
|
|
14675
14822
|
* Verifica se um objeto é uma Declaração.
|
|
14676
14823
|
*/
|
|
14677
14824
|
ehDeclaracao(obj) {
|
|
14678
|
-
return obj &&
|
|
14825
|
+
return (obj &&
|
|
14826
|
+
typeof obj === 'object' &&
|
|
14827
|
+
'paraTexto' in obj &&
|
|
14828
|
+
'linha' in obj &&
|
|
14829
|
+
'hashArquivo' in obj);
|
|
14679
14830
|
}
|
|
14680
14831
|
/**
|
|
14681
14832
|
* Verifica se um objeto é um Construto.
|
|
@@ -15902,24 +16053,60 @@ class FormatadorPitugues {
|
|
|
15902
16053
|
this.nívelIndentação -= this.tamanhoIndentação;
|
|
15903
16054
|
}
|
|
15904
16055
|
// Métodos obrigatórios da interface, não usados no Pituguês.
|
|
15905
|
-
visitarDeclaracaoCabecalhoPrograma() {
|
|
15906
|
-
|
|
15907
|
-
|
|
15908
|
-
|
|
15909
|
-
|
|
15910
|
-
|
|
15911
|
-
|
|
15912
|
-
|
|
15913
|
-
|
|
15914
|
-
|
|
15915
|
-
|
|
15916
|
-
|
|
15917
|
-
|
|
15918
|
-
|
|
15919
|
-
|
|
15920
|
-
|
|
15921
|
-
|
|
15922
|
-
|
|
16056
|
+
visitarDeclaracaoCabecalhoPrograma() {
|
|
16057
|
+
return Promise.resolve();
|
|
16058
|
+
}
|
|
16059
|
+
visitarDeclaracaoConstMultiplo() {
|
|
16060
|
+
return Promise.resolve();
|
|
16061
|
+
}
|
|
16062
|
+
visitarDeclaracaoEscrevaMesmaLinha() {
|
|
16063
|
+
return Promise.resolve();
|
|
16064
|
+
}
|
|
16065
|
+
visitarDeclaracaoInicioAlgoritmo() {
|
|
16066
|
+
return Promise.resolve();
|
|
16067
|
+
}
|
|
16068
|
+
visitarDeclaracaoTendoComo() {
|
|
16069
|
+
return Promise.resolve();
|
|
16070
|
+
}
|
|
16071
|
+
visitarDeclaracaoVarMultiplo() {
|
|
16072
|
+
return Promise.resolve();
|
|
16073
|
+
}
|
|
16074
|
+
visitarExpressaoAcessoElementoMatriz() {
|
|
16075
|
+
return Promise.resolve();
|
|
16076
|
+
}
|
|
16077
|
+
visitarExpressaoAcessoMetodo() {
|
|
16078
|
+
return Promise.resolve();
|
|
16079
|
+
}
|
|
16080
|
+
visitarExpressaoAcessoPropriedade() {
|
|
16081
|
+
return Promise.resolve();
|
|
16082
|
+
}
|
|
16083
|
+
visitarExpressaoArgumentoReferenciaFuncao() {
|
|
16084
|
+
return Promise.resolve();
|
|
16085
|
+
}
|
|
16086
|
+
visitarExpressaoAtribuicaoPorIndicesMatriz() {
|
|
16087
|
+
return Promise.resolve();
|
|
16088
|
+
}
|
|
16089
|
+
visitarExpressaoComentario() {
|
|
16090
|
+
return Promise.resolve();
|
|
16091
|
+
}
|
|
16092
|
+
visitarExpressaoExpressaoRegular() {
|
|
16093
|
+
return Promise.resolve();
|
|
16094
|
+
}
|
|
16095
|
+
visitarExpressaoFimPara() {
|
|
16096
|
+
return Promise.resolve();
|
|
16097
|
+
}
|
|
16098
|
+
visitarExpressaoFormatacaoEscrita() {
|
|
16099
|
+
return Promise.resolve();
|
|
16100
|
+
}
|
|
16101
|
+
visitarExpressaoReferenciaFuncao() {
|
|
16102
|
+
return Promise.resolve();
|
|
16103
|
+
}
|
|
16104
|
+
visitarExpressaoSeparador() {
|
|
16105
|
+
return Promise.resolve();
|
|
16106
|
+
}
|
|
16107
|
+
visitarExpressaoTupla() {
|
|
16108
|
+
return Promise.resolve();
|
|
16109
|
+
}
|
|
15923
16110
|
async visitarExpressaoTuplaN(expressao) {
|
|
15924
16111
|
this.códigoFormatado += '(';
|
|
15925
16112
|
for (let i = 0; i < expressao.elementos.length; i++) {
|
|
@@ -15933,7 +16120,7 @@ class FormatadorPitugues {
|
|
|
15933
16120
|
}
|
|
15934
16121
|
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
15935
16122
|
this.códigoFormatado += this.indentar();
|
|
15936
|
-
this.códigoFormatado += await declaracao.expressao.aceitar(this) + `\n`;
|
|
16123
|
+
this.códigoFormatado += (await declaracao.expressao.aceitar(this)) + `\n`;
|
|
15937
16124
|
}
|
|
15938
16125
|
async visitarDeclaracaoClasse(declaração) {
|
|
15939
16126
|
this.adicionarLinha(`classe ${declaração.simbolo.lexema}:`);
|
|
@@ -16088,7 +16275,9 @@ class FormatadorPitugues {
|
|
|
16088
16275
|
if (declaração.caminhoPegue) {
|
|
16089
16276
|
this.adicionarLinha('pegue como erro:');
|
|
16090
16277
|
this.aumentarIndentação();
|
|
16091
|
-
const declaracoes = declaração.caminhoPegue instanceof construtos_1.FuncaoConstruto
|
|
16278
|
+
const declaracoes = declaração.caminhoPegue instanceof construtos_1.FuncaoConstruto
|
|
16279
|
+
? declaração.caminhoPegue.corpo
|
|
16280
|
+
: declaração.caminhoPegue;
|
|
16092
16281
|
for (const instrução of declaracoes) {
|
|
16093
16282
|
await instrução.aceitar(this);
|
|
16094
16283
|
}
|
|
@@ -16103,7 +16292,9 @@ class FormatadorPitugues {
|
|
|
16103
16292
|
}
|
|
16104
16293
|
}
|
|
16105
16294
|
async visitarDeclaracaoEscreva(declaração) {
|
|
16106
|
-
this.códigoFormatado +=
|
|
16295
|
+
this.códigoFormatado +=
|
|
16296
|
+
this.indentar() +
|
|
16297
|
+
`${declaração.simboloEscreva ? declaração.simboloEscreva.lexema : 'imprima'}(`;
|
|
16107
16298
|
for (let i = 0; i < declaração.argumentos.length; i++) {
|
|
16108
16299
|
this.códigoFormatado += await declaração.argumentos[i].aceitar(this);
|
|
16109
16300
|
if (i < declaração.argumentos.length - 1)
|
|
@@ -16178,8 +16369,10 @@ class FormatadorPitugues {
|
|
|
16178
16369
|
return `(${await expressão.expressao.aceitar(this)})`;
|
|
16179
16370
|
}
|
|
16180
16371
|
async visitarExpressaoUnaria(expressão) {
|
|
16181
|
-
const operador = expressão.operador.tipo === pitugues_1.default.SUBTRACAO
|
|
16182
|
-
|
|
16372
|
+
const operador = expressão.operador.tipo === pitugues_1.default.SUBTRACAO
|
|
16373
|
+
? '-'
|
|
16374
|
+
: expressão.operador.tipo === pitugues_1.default.NEGACAO
|
|
16375
|
+
? 'não '
|
|
16183
16376
|
: '';
|
|
16184
16377
|
const operando = await expressão.operando.aceitar(this);
|
|
16185
16378
|
return expressão.incidenciaOperador === 'ANTES'
|
|
@@ -16188,7 +16381,7 @@ class FormatadorPitugues {
|
|
|
16188
16381
|
}
|
|
16189
16382
|
async visitarExpressaoDeChamada(expressão) {
|
|
16190
16383
|
const função = await expressão.entidadeChamada.aceitar(this);
|
|
16191
|
-
const argumentos = await Promise.all(expressão.argumentos.map(a => a.aceitar(this)));
|
|
16384
|
+
const argumentos = await Promise.all(expressão.argumentos.map((a) => a.aceitar(this)));
|
|
16192
16385
|
return `${função}(${argumentos.join(', ')})`;
|
|
16193
16386
|
}
|
|
16194
16387
|
visitarExpressaoIsto() {
|
|
@@ -16198,7 +16391,7 @@ class FormatadorPitugues {
|
|
|
16198
16391
|
return 'super()';
|
|
16199
16392
|
}
|
|
16200
16393
|
async visitarExpressaoVetor(expressão) {
|
|
16201
|
-
const valores = await Promise.all(expressão.valores.map(v => v.aceitar(this)));
|
|
16394
|
+
const valores = await Promise.all(expressão.valores.map((v) => v.aceitar(this)));
|
|
16202
16395
|
return `[${valores.join(', ')}]`;
|
|
16203
16396
|
}
|
|
16204
16397
|
async visitarExpressaoDicionario(expressão) {
|
|
@@ -16236,15 +16429,18 @@ class FormatadorPitugues {
|
|
|
16236
16429
|
return `${objeto}.${expressão.nome.lexema} = ${valor}`;
|
|
16237
16430
|
}
|
|
16238
16431
|
async visitarExpressaoFuncaoConstruto(expressão) {
|
|
16239
|
-
const parâmetros = expressão.parametros
|
|
16432
|
+
const parâmetros = expressão.parametros
|
|
16433
|
+
.map((p) => {
|
|
16240
16434
|
const tipo = p.tipoDado ? `: ${p.tipoDado}` : '';
|
|
16241
16435
|
return p.nome.lexema + tipo;
|
|
16242
|
-
})
|
|
16436
|
+
})
|
|
16437
|
+
.join(', ');
|
|
16243
16438
|
let funçãoStr = `função(${parâmetros || ''}):\n`;
|
|
16244
16439
|
this.aumentarIndentação();
|
|
16245
16440
|
for (const instrução of expressão.corpo) {
|
|
16246
16441
|
const linha = await instrução.aceitar(this);
|
|
16247
|
-
if (linha) {
|
|
16442
|
+
if (linha) {
|
|
16443
|
+
// Only add if it returns something
|
|
16248
16444
|
funçãoStr += this.indentar() + linha;
|
|
16249
16445
|
if (!linha.endsWith('\n'))
|
|
16250
16446
|
funçãoStr += '\n';
|
|
@@ -16254,7 +16450,7 @@ class FormatadorPitugues {
|
|
|
16254
16450
|
return funçãoStr.trimEnd();
|
|
16255
16451
|
}
|
|
16256
16452
|
async visitarExpressaoLeia(expressão) {
|
|
16257
|
-
const argumentos = await Promise.all(expressão.argumentos.map(a => a.aceitar(this)));
|
|
16453
|
+
const argumentos = await Promise.all(expressão.argumentos.map((a) => a.aceitar(this)));
|
|
16258
16454
|
return argumentos.length > 0 ? `input(${argumentos.join(', ')})` : 'input()';
|
|
16259
16455
|
}
|
|
16260
16456
|
async visitarExpressaoTipoDe(expressão) {
|
|
@@ -16340,12 +16536,12 @@ function uuidv4() {
|
|
|
16340
16536
|
let r = Math.random() * 16; // random number between 0 and 16
|
|
16341
16537
|
if (d > 0) {
|
|
16342
16538
|
// Use timestamp until depleted
|
|
16343
|
-
r = (d + r) % 16 | 0;
|
|
16539
|
+
r = ((d + r) % 16) | 0;
|
|
16344
16540
|
d = Math.floor(d / 16);
|
|
16345
16541
|
}
|
|
16346
16542
|
else {
|
|
16347
16543
|
// Use microseconds since page-load if supported
|
|
16348
|
-
r = (d2 + r) % 16 | 0;
|
|
16544
|
+
r = ((d2 + r) % 16) | 0;
|
|
16349
16545
|
d2 = Math.floor(d2 / 16);
|
|
16350
16546
|
}
|
|
16351
16547
|
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
|
|
@@ -16817,23 +17013,23 @@ function carregarBibliotecasGlobais(pilhaEscoposExecucao) {
|
|
|
16817
17013
|
}
|
|
16818
17014
|
function pontoEntradaAjuda(funcao, topico) {
|
|
16819
17015
|
if (!funcao) {
|
|
16820
|
-
return
|
|
17016
|
+
return 'Para usar a ajuda, use como uma função: ajuda(objeto).';
|
|
16821
17017
|
}
|
|
16822
17018
|
if (!topico) {
|
|
16823
|
-
return
|
|
16824
|
-
|
|
16825
|
-
"Use ajuda('tópico') para obter informações sobre um tópico específico.\n\n";
|
|
17019
|
+
return ('Te damos as boas-vindas ao utilitário de ajuda de Delégua!\n\n' +
|
|
17020
|
+
'Use ajuda(objeto) para obter informações sobre um objeto, função, classe ou módulo.\n' +
|
|
17021
|
+
"Use ajuda('tópico') para obter informações sobre um tópico específico.\n\n");
|
|
16826
17022
|
}
|
|
16827
17023
|
return obterTopicoAjuda(topico);
|
|
16828
17024
|
}
|
|
16829
17025
|
function obterTopicoAjuda(topico) {
|
|
16830
17026
|
switch (topico.constructor) {
|
|
16831
17027
|
case construtos_1.Leia:
|
|
16832
|
-
return `A instrução 'leia' permite capturar a entrada do usuário durante a execução do programa. ` +
|
|
17028
|
+
return (`A instrução 'leia' permite capturar a entrada do usuário durante a execução do programa. ` +
|
|
16833
17029
|
`Você pode usar 'leia()' para ler uma linha de entrada do usuário e armazená-la em uma variável. ` +
|
|
16834
17030
|
`Exemplo de uso:\n\n` +
|
|
16835
17031
|
`\tvar minhaVariavel = leia()\n\n` +
|
|
16836
|
-
`Isto irá ler a entrada do usuário e atribuí-la à variável 'minhaVariavel'
|
|
17032
|
+
`Isto irá ler a entrada do usuário e atribuí-la à variável 'minhaVariavel'.`);
|
|
16837
17033
|
case funcao_padrao_1.FuncaoPadrao:
|
|
16838
17034
|
return obterAjudaFuncaoPadrao(topico);
|
|
16839
17035
|
case delegua_funcao_1.DeleguaFuncao:
|
|
@@ -16888,21 +17084,21 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16888
17084
|
const aridade = funcaoPadrao.valorAridade;
|
|
16889
17085
|
const implementacao = funcaoPadrao.funcao;
|
|
16890
17086
|
// Mapeamento de funções por nome
|
|
16891
|
-
const nomeFuncao = Object.keys(bibliotecaGlobal).find(key => bibliotecaGlobal[key] === implementacao);
|
|
17087
|
+
const nomeFuncao = Object.keys(bibliotecaGlobal).find((key) => bibliotecaGlobal[key] === implementacao);
|
|
16892
17088
|
if (!nomeFuncao) {
|
|
16893
17089
|
return 'Função não identificada. Não há documentação disponível.';
|
|
16894
17090
|
}
|
|
16895
17091
|
switch (nomeFuncao) {
|
|
16896
17092
|
case 'aleatorio':
|
|
16897
|
-
return `# aleatorio()\n\n` +
|
|
17093
|
+
return (`# aleatorio()\n\n` +
|
|
16898
17094
|
`Retorna um número aleatório entre 0 e 1.\n\n` +
|
|
16899
17095
|
`**Sintaxe:** aleatorio()\n\n` +
|
|
16900
17096
|
`**Retorno:** Número real entre 0 (inclusivo) e 1 (exclusivo).\n\n` +
|
|
16901
17097
|
`**Exemplo:**\n` +
|
|
16902
17098
|
`\tvar numeroSorteado = aleatorio()\n` +
|
|
16903
|
-
`\tescreva(numeroSorteado) // Pode retornar algo como 0.4829374657\n
|
|
17099
|
+
`\tescreva(numeroSorteado) // Pode retornar algo como 0.4829374657\n`);
|
|
16904
17100
|
case 'aleatorioEntre':
|
|
16905
|
-
return `# aleatorioEntre(minimo, maximo)\n\n` +
|
|
17101
|
+
return (`# aleatorioEntre(minimo, maximo)\n\n` +
|
|
16906
17102
|
`Retorna um número aleatório inteiro de acordo com os parâmetros passados.\n` +
|
|
16907
17103
|
`Mínimo (inclusivo) - Máximo (exclusivo).\n\n` +
|
|
16908
17104
|
`**Sintaxe:** aleatorioEntre(minimo: número, maximo: número)\n\n` +
|
|
@@ -16912,9 +17108,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16912
17108
|
`**Retorno:** Número inteiro entre minimo e maximo-1.\n\n` +
|
|
16913
17109
|
`**Exemplo:**\n` +
|
|
16914
17110
|
`\tvar dado = aleatorioEntre(1, 7)\n` +
|
|
16915
|
-
`\tescreva(dado) // Retorna um número entre 1 e 6\n
|
|
17111
|
+
`\tescreva(dado) // Retorna um número entre 1 e 6\n`);
|
|
16916
17112
|
case 'algum':
|
|
16917
|
-
return `# algum(vetor, funcaoPesquisa)\n\n` +
|
|
17113
|
+
return (`# algum(vetor, funcaoPesquisa)\n\n` +
|
|
16918
17114
|
`Verifica se algum dos elementos do vetor satisfaz a condição definida pela função de pesquisa.\n\n` +
|
|
16919
17115
|
`**Sintaxe:** algum(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16920
17116
|
`**Parâmetros:**\n` +
|
|
@@ -16924,9 +17120,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16924
17120
|
`**Exemplo:**\n` +
|
|
16925
17121
|
`\tvar numeros = [1, 2, 3, 4, 5]\n` +
|
|
16926
17122
|
`\tvar temPar = algum(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16927
|
-
`\tescreva(temPar) // verdadeiro\n
|
|
17123
|
+
`\tescreva(temPar) // verdadeiro\n`);
|
|
16928
17124
|
case 'clonar':
|
|
16929
|
-
return `# clonar(valor)\n\n` +
|
|
17125
|
+
return (`# clonar(valor)\n\n` +
|
|
16930
17126
|
`Clona profundamente uma variável ou constante em Delégua, criando uma cópia independente.\n\n` +
|
|
16931
17127
|
`**Sintaxe:** clonar(valor: qualquer)\n\n` +
|
|
16932
17128
|
`**Parâmetros:**\n` +
|
|
@@ -16937,9 +17133,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16937
17133
|
`\tvar copia = clonar(original)\n` +
|
|
16938
17134
|
`\tcopia[2][0] = 99\n` +
|
|
16939
17135
|
`\tescreva(original[2][0]) // 3 (não foi modificado)\n` +
|
|
16940
|
-
`\tescreva(copia[2][0]) // 99\n
|
|
17136
|
+
`\tescreva(copia[2][0]) // 99\n`);
|
|
16941
17137
|
case 'encontrar':
|
|
16942
|
-
return `# encontrar(vetor, funcaoPesquisa)\n\n` +
|
|
17138
|
+
return (`# encontrar(vetor, funcaoPesquisa)\n\n` +
|
|
16943
17139
|
`Encontra o primeiro elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16944
17140
|
`**Sintaxe:** encontrar(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16945
17141
|
`**Parâmetros:**\n` +
|
|
@@ -16949,9 +17145,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16949
17145
|
`**Exemplo:**\n` +
|
|
16950
17146
|
`\tvar numeros = [1, 3, 5, 8, 10]\n` +
|
|
16951
17147
|
`\tvar primeiroPar = encontrar(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16952
|
-
`\tescreva(primeiroPar) // 8\n
|
|
17148
|
+
`\tescreva(primeiroPar) // 8\n`);
|
|
16953
17149
|
case 'encontrarIndice':
|
|
16954
|
-
return `# encontrarIndice(vetor, funcaoPesquisa)\n\n` +
|
|
17150
|
+
return (`# encontrarIndice(vetor, funcaoPesquisa)\n\n` +
|
|
16955
17151
|
`Encontra o índice do primeiro elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16956
17152
|
`**Sintaxe:** encontrarIndice(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16957
17153
|
`**Parâmetros:**\n` +
|
|
@@ -16961,9 +17157,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16961
17157
|
`**Exemplo:**\n` +
|
|
16962
17158
|
`\tvar frutas = ["maçã", "banana", "laranja"]\n` +
|
|
16963
17159
|
`\tvar indice = encontrarIndice(frutas, funcao(f) { retorna f == "banana" })\n` +
|
|
16964
|
-
`\tescreva(indice) // 1\n
|
|
17160
|
+
`\tescreva(indice) // 1\n`);
|
|
16965
17161
|
case 'encontrarUltimo':
|
|
16966
|
-
return `# encontrarUltimo(vetor, funcaoPesquisa)\n\n` +
|
|
17162
|
+
return (`# encontrarUltimo(vetor, funcaoPesquisa)\n\n` +
|
|
16967
17163
|
`Encontra o último elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16968
17164
|
`**Sintaxe:** encontrarUltimo(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16969
17165
|
`**Parâmetros:**\n` +
|
|
@@ -16973,9 +17169,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16973
17169
|
`**Exemplo:**\n` +
|
|
16974
17170
|
`\tvar numeros = [2, 4, 6, 7, 9]\n` +
|
|
16975
17171
|
`\tvar ultimoPar = encontrarUltimo(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16976
|
-
`\tescreva(ultimoPar) // 6\n
|
|
17172
|
+
`\tescreva(ultimoPar) // 6\n`);
|
|
16977
17173
|
case 'encontrarUltimoIndice':
|
|
16978
|
-
return `# encontrarUltimoIndice(vetor, funcaoPesquisa)\n\n` +
|
|
17174
|
+
return (`# encontrarUltimoIndice(vetor, funcaoPesquisa)\n\n` +
|
|
16979
17175
|
`Encontra o índice do último elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16980
17176
|
`**Sintaxe:** encontrarUltimoIndice(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16981
17177
|
`**Parâmetros:**\n` +
|
|
@@ -16985,9 +17181,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16985
17181
|
`**Exemplo:**\n` +
|
|
16986
17182
|
`\tvar numeros = [2, 4, 6, 7, 9]\n` +
|
|
16987
17183
|
`\tvar indiceUltimoPar = encontrarUltimoIndice(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16988
|
-
`\tescreva(indiceUltimoPar) // 2\n
|
|
17184
|
+
`\tescreva(indiceUltimoPar) // 2\n`);
|
|
16989
17185
|
case 'filtrarPor':
|
|
16990
|
-
return `# filtrarPor(vetor, funcaoFiltragem)\n\n` +
|
|
17186
|
+
return (`# filtrarPor(vetor, funcaoFiltragem)\n\n` +
|
|
16991
17187
|
`Cria um novo vetor com todos os elementos que passam no teste implementado pela função de filtragem.\n\n` +
|
|
16992
17188
|
`**Sintaxe:** filtrarPor(vetor: qualquer[], funcaoFiltragem: função)\n\n` +
|
|
16993
17189
|
`**Parâmetros:**\n` +
|
|
@@ -16997,9 +17193,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16997
17193
|
`**Exemplo:**\n` +
|
|
16998
17194
|
`\tvar numeros = [1, 2, 3, 4, 5, 6]\n` +
|
|
16999
17195
|
`\tvar pares = filtrarPor(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
17000
|
-
`\tescreva(pares) // [2, 4, 6]\n
|
|
17196
|
+
`\tescreva(pares) // [2, 4, 6]\n`);
|
|
17001
17197
|
case 'incluido':
|
|
17002
|
-
return `# incluido(vetor, valor)\n\n` +
|
|
17198
|
+
return (`# incluido(vetor, valor)\n\n` +
|
|
17003
17199
|
`Verifica se um valor está incluído em um vetor.\n\n` +
|
|
17004
17200
|
`**Sintaxe:** incluido(vetor: qualquer[], valor: qualquer)\n\n` +
|
|
17005
17201
|
`**Parâmetros:**\n` +
|
|
@@ -17009,9 +17205,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17009
17205
|
`**Exemplo:**\n` +
|
|
17010
17206
|
`\tvar frutas = ["maçã", "banana", "laranja"]\n` +
|
|
17011
17207
|
`\tescreva(incluido(frutas, "banana")) // verdadeiro\n` +
|
|
17012
|
-
`\tescreva(incluido(frutas, "uva")) // falso\n
|
|
17208
|
+
`\tescreva(incluido(frutas, "uva")) // falso\n`);
|
|
17013
17209
|
case 'inteiro':
|
|
17014
|
-
return `# inteiro(valor)\n\n` +
|
|
17210
|
+
return (`# inteiro(valor)\n\n` +
|
|
17015
17211
|
`Converte um valor em um número inteiro.\n\n` +
|
|
17016
17212
|
`**Sintaxe:** inteiro(valor: número | texto)\n\n` +
|
|
17017
17213
|
`**Parâmetros:**\n` +
|
|
@@ -17020,9 +17216,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17020
17216
|
`**Exemplo:**\n` +
|
|
17021
17217
|
`\tescreva(inteiro(3.14)) // 3\n` +
|
|
17022
17218
|
`\tescreva(inteiro("42")) // 42\n` +
|
|
17023
|
-
`\tescreva(inteiro("3.99")) // 3\n
|
|
17219
|
+
`\tescreva(inteiro("3.99")) // 3\n`);
|
|
17024
17220
|
case 'intervalo':
|
|
17025
|
-
return `# intervalo(valorInicial, valorFinal)\n\n` +
|
|
17221
|
+
return (`# intervalo(valorInicial, valorFinal)\n\n` +
|
|
17026
17222
|
`Cria um vetor com números inteiros no intervalo especificado.\n` +
|
|
17027
17223
|
`O valor inicial é inclusivo e o valor final é exclusivo.\n\n` +
|
|
17028
17224
|
`**Sintaxe:** intervalo(valorInicial: número, valorFinal: número)\n\n` +
|
|
@@ -17032,9 +17228,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17032
17228
|
`**Retorno:** Vetor com os números no intervalo especificado.\n\n` +
|
|
17033
17229
|
`**Exemplo:**\n` +
|
|
17034
17230
|
`\tvar numeros = intervalo(1, 6)\n` +
|
|
17035
|
-
`\tescreva(numeros) // [1, 2, 3, 4, 5]\n
|
|
17231
|
+
`\tescreva(numeros) // [1, 2, 3, 4, 5]\n`);
|
|
17036
17232
|
case 'mapear':
|
|
17037
|
-
return `# mapear(vetor, funcaoMapeamento)\n\n` +
|
|
17233
|
+
return (`# mapear(vetor, funcaoMapeamento)\n\n` +
|
|
17038
17234
|
`Cria um novo vetor com os resultados da aplicação de uma função a cada elemento do vetor original.\n\n` +
|
|
17039
17235
|
`**Sintaxe:** mapear(vetor: qualquer[], funcaoMapeamento: função)\n\n` +
|
|
17040
17236
|
`**Parâmetros:**\n` +
|
|
@@ -17044,13 +17240,13 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17044
17240
|
`**Exemplo:**\n` +
|
|
17045
17241
|
`\tvar numeros = [1, 2, 3, 4]\n` +
|
|
17046
17242
|
`\tvar quadrados = mapear(numeros, funcao(n) { retorna n * n })\n` +
|
|
17047
|
-
`\tescreva(quadrados) // [1, 4, 9, 16]\n
|
|
17243
|
+
`\tescreva(quadrados) // [1, 4, 9, 16]\n`);
|
|
17048
17244
|
case 'maximo':
|
|
17049
17245
|
return `# maximo(vetor)\n\nRetorna o maior valor encontrado em um vetor de números.`;
|
|
17050
17246
|
case 'minimo':
|
|
17051
17247
|
return `# minimo(vetor)\n\nRetorna o menor valor encontrado em um vetor de números.`;
|
|
17052
17248
|
case 'numero':
|
|
17053
|
-
return `# numero(valor)\n\n` +
|
|
17249
|
+
return (`# numero(valor)\n\n` +
|
|
17054
17250
|
`Converte um valor em um número (pode ter parte decimal).\n\n` +
|
|
17055
17251
|
`**Sintaxe:** numero(valor: número | texto)\n\n` +
|
|
17056
17252
|
`**Parâmetros:**\n` +
|
|
@@ -17059,9 +17255,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17059
17255
|
`**Exemplo:**\n` +
|
|
17060
17256
|
`\tescreva(numero("3.14")) // 3.14\n` +
|
|
17061
17257
|
`\tescreva(numero("42")) // 42\n` +
|
|
17062
|
-
`\tescreva(numero(5)) // 5\n
|
|
17258
|
+
`\tescreva(numero(5)) // 5\n`);
|
|
17063
17259
|
case 'ordenar':
|
|
17064
|
-
return `# ordenar(vetor)\n\n` +
|
|
17260
|
+
return (`# ordenar(vetor)\n\n` +
|
|
17065
17261
|
`Ordena os elementos de um vetor em ordem crescente (números) ou alfabética (textos).\n\n` +
|
|
17066
17262
|
`**Sintaxe:** ordenar(vetor: qualquer[])\n\n` +
|
|
17067
17263
|
`**Parâmetros:**\n` +
|
|
@@ -17070,9 +17266,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17070
17266
|
`**Exemplo:**\n` +
|
|
17071
17267
|
`\tvar numeros = [5, 2, 8, 1, 9]\n` +
|
|
17072
17268
|
`\tordenar(numeros)\n` +
|
|
17073
|
-
`\tescreva(numeros) // [1, 2, 5, 8, 9]\n
|
|
17269
|
+
`\tescreva(numeros) // [1, 2, 5, 8, 9]\n`);
|
|
17074
17270
|
case 'paraCada':
|
|
17075
|
-
return `# paraCada(vetor, funcao)\n\n` +
|
|
17271
|
+
return (`# paraCada(vetor, funcao)\n\n` +
|
|
17076
17272
|
`Executa uma função para cada elemento do vetor.\n\n` +
|
|
17077
17273
|
`**Sintaxe:** paraCada(vetor: qualquer[], funcao: função)\n\n` +
|
|
17078
17274
|
`**Parâmetros:**\n` +
|
|
@@ -17083,9 +17279,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17083
17279
|
`\tvar nomes = ["Ana", "Bruno", "Carlos"]\n` +
|
|
17084
17280
|
`\tparaCada(nomes, funcao(nome) {\n` +
|
|
17085
17281
|
`\t\tescreva("Olá, " + nome)\n` +
|
|
17086
|
-
`\t})\n
|
|
17282
|
+
`\t})\n`);
|
|
17087
17283
|
case 'primeiroEmCondicao':
|
|
17088
|
-
return `# primeiroEmCondicao(vetor, funcaoFiltragem)\n\n` +
|
|
17284
|
+
return (`# primeiroEmCondicao(vetor, funcaoFiltragem)\n\n` +
|
|
17089
17285
|
`Retorna o primeiro elemento que satisfaz a condição especificada pela função de filtragem.\n\n` +
|
|
17090
17286
|
`**Sintaxe:** primeiroEmCondicao(vetor: qualquer[], funcaoFiltragem: função)\n\n` +
|
|
17091
17287
|
`**Parâmetros:**\n` +
|
|
@@ -17095,9 +17291,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17095
17291
|
`**Exemplo:**\n` +
|
|
17096
17292
|
`\tvar numeros = [1, 3, 5, 8, 10]\n` +
|
|
17097
17293
|
`\tvar resultado = primeiroEmCondicao(numeros, funcao(n) { retorna n > 5 })\n` +
|
|
17098
|
-
`\tescreva(resultado) // 8\n
|
|
17294
|
+
`\tescreva(resultado) // 8\n`);
|
|
17099
17295
|
case 'real':
|
|
17100
|
-
return `# real(valor)\n\n` +
|
|
17296
|
+
return (`# real(valor)\n\n` +
|
|
17101
17297
|
`Converte um valor em um número real (ponto flutuante).\n\n` +
|
|
17102
17298
|
`**Sintaxe:** real(valor: número | texto)\n\n` +
|
|
17103
17299
|
`**Parâmetros:**\n` +
|
|
@@ -17105,9 +17301,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17105
17301
|
`**Retorno:** Número real correspondente ao valor fornecido.\n\n` +
|
|
17106
17302
|
`**Exemplo:**\n` +
|
|
17107
17303
|
`\tescreva(real("3.14")) // 3.14\n` +
|
|
17108
|
-
`\tescreva(real(42)) // 42.0\n
|
|
17304
|
+
`\tescreva(real(42)) // 42.0\n`);
|
|
17109
17305
|
case 'reduzir':
|
|
17110
|
-
return `# reduzir(vetor, funcaoReducao, valorInicial)\n\n` +
|
|
17306
|
+
return (`# reduzir(vetor, funcaoReducao, valorInicial)\n\n` +
|
|
17111
17307
|
`Aplica uma função a um acumulador e cada elemento do vetor para reduzi-lo a um único valor.\n\n` +
|
|
17112
17308
|
`**Sintaxe:** reduzir(vetor: qualquer[], funcaoReducao: função, valorInicial?: qualquer)\n\n` +
|
|
17113
17309
|
`**Parâmetros:**\n` +
|
|
@@ -17118,11 +17314,11 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17118
17314
|
`**Exemplo:**\n` +
|
|
17119
17315
|
`\tvar numeros = [1, 2, 3, 4]\n` +
|
|
17120
17316
|
`\tvar soma = reduzir(numeros, funcao(acc, n) { retorna acc + n }, 0)\n` +
|
|
17121
|
-
`\tescreva(soma) // 10\n
|
|
17317
|
+
`\tescreva(soma) // 10\n`);
|
|
17122
17318
|
case 'somar':
|
|
17123
17319
|
return `# somar(vetor)\n\nRetorna a soma de todos os elementos de um vetor numérico.`;
|
|
17124
17320
|
case 'tamanho':
|
|
17125
|
-
return `# tamanho(objeto)\n\n` +
|
|
17321
|
+
return (`# tamanho(objeto)\n\n` +
|
|
17126
17322
|
`Retorna o tamanho de um objeto (vetor, texto, função, etc.).\n\n` +
|
|
17127
17323
|
`**Sintaxe:** tamanho(objeto: qualquer)\n\n` +
|
|
17128
17324
|
`**Parâmetros:**\n` +
|
|
@@ -17131,9 +17327,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17131
17327
|
`Para funções, retorna o número de parâmetros.\n\n` +
|
|
17132
17328
|
`**Exemplo:**\n` +
|
|
17133
17329
|
`\tescreva(tamanho([1, 2, 3])) // 3\n` +
|
|
17134
|
-
`\tescreva(tamanho("Delégua")) // 7\n
|
|
17330
|
+
`\tescreva(tamanho("Delégua")) // 7\n`);
|
|
17135
17331
|
case 'texto':
|
|
17136
|
-
return `# texto(valor)\n\n` +
|
|
17332
|
+
return (`# texto(valor)\n\n` +
|
|
17137
17333
|
`Transforma o valor ou variável em texto.\n\n` +
|
|
17138
17334
|
`**Sintaxe:** texto(valor: qualquer)\n\n` +
|
|
17139
17335
|
`**Parâmetros:**\n` +
|
|
@@ -17142,9 +17338,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17142
17338
|
`**Exemplo:**\n` +
|
|
17143
17339
|
`\tescreva(texto(42)) // "42"\n` +
|
|
17144
17340
|
`\tescreva(texto(verdadeiro)) // "verdadeiro"\n` +
|
|
17145
|
-
`\tescreva(texto([1, 2, 3])) // "[1, 2, 3]"\n
|
|
17341
|
+
`\tescreva(texto([1, 2, 3])) // "[1, 2, 3]"\n`);
|
|
17146
17342
|
case 'todosEmCondicao':
|
|
17147
|
-
return `# todosEmCondicao(vetor, funcaoCondicional)\n\n` +
|
|
17343
|
+
return (`# todosEmCondicao(vetor, funcaoCondicional)\n\n` +
|
|
17148
17344
|
`Retorna verdadeiro se todos os elementos do vetor satisfazem a condição especificada pela função.\n\n` +
|
|
17149
17345
|
`**Sintaxe:** todosEmCondicao(vetor: qualquer[], funcaoCondicional: função)\n\n` +
|
|
17150
17346
|
`**Parâmetros:**\n` +
|
|
@@ -17154,9 +17350,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17154
17350
|
`**Exemplo:**\n` +
|
|
17155
17351
|
`\tvar numeros = [2, 4, 6, 8]\n` +
|
|
17156
17352
|
`\tvar todosPares = todosEmCondicao(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
17157
|
-
`\tescreva(todosPares) // verdadeiro\n
|
|
17353
|
+
`\tescreva(todosPares) // verdadeiro\n`);
|
|
17158
17354
|
case 'tupla':
|
|
17159
|
-
return `# tupla(vetor)\n\n` +
|
|
17355
|
+
return (`# tupla(vetor)\n\n` +
|
|
17160
17356
|
`Transforma um vetor de elementos em uma tupla de N elementos, sendo N a largura do vetor.\n` +
|
|
17161
17357
|
`Tuplas são estruturas imutáveis de tamanho fixo.\n\n` +
|
|
17162
17358
|
`**Sintaxe:** tupla(vetor: qualquer[])\n\n` +
|
|
@@ -17166,10 +17362,10 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17166
17362
|
`**Exemplo:**\n` +
|
|
17167
17363
|
`\tvar coordenadas = tupla([10, 20])\n` +
|
|
17168
17364
|
`\tescreva(coordenadas.primeiro) // 10\n` +
|
|
17169
|
-
`\tescreva(coordenadas.segundo) // 20\n
|
|
17365
|
+
`\tescreva(coordenadas.segundo) // 20\n`);
|
|
17170
17366
|
default:
|
|
17171
|
-
return `Função global identificada, mas documentação específica não disponível.\n` +
|
|
17172
|
-
`Aridade: ${aridade} parâmetro(s)
|
|
17367
|
+
return (`Função global identificada, mas documentação específica não disponível.\n` +
|
|
17368
|
+
`Aridade: ${aridade} parâmetro(s).`);
|
|
17173
17369
|
}
|
|
17174
17370
|
}
|
|
17175
17371
|
|
|
@@ -17426,7 +17622,9 @@ class DeleguaFuncao extends chamavel_1.Chamavel {
|
|
|
17426
17622
|
if (this.instancia !== undefined) {
|
|
17427
17623
|
ambiente.valores['isto'] = {
|
|
17428
17624
|
valor: this.instancia,
|
|
17429
|
-
tipo: this.instancia instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse
|
|
17625
|
+
tipo: this.instancia instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse
|
|
17626
|
+
? 'objeto'
|
|
17627
|
+
: tipoDeDados(this.instancia),
|
|
17430
17628
|
imutavel: false,
|
|
17431
17629
|
};
|
|
17432
17630
|
}
|
|
@@ -17509,11 +17707,11 @@ const chamavel_1 = require("./chamavel");
|
|
|
17509
17707
|
const metodo_polimorfico_1 = require("./metodo-polimorfico");
|
|
17510
17708
|
const objeto_delegua_classe_1 = require("./objeto-delegua-classe");
|
|
17511
17709
|
const mapaDeNormalizacao = {
|
|
17512
|
-
|
|
17513
|
-
|
|
17514
|
-
|
|
17515
|
-
|
|
17516
|
-
|
|
17710
|
+
numero: 'número',
|
|
17711
|
+
logico: 'lógico',
|
|
17712
|
+
funcao: 'função',
|
|
17713
|
+
dicionario: 'dicionário',
|
|
17714
|
+
modulo: 'módulo',
|
|
17517
17715
|
};
|
|
17518
17716
|
function normalizarTipo(tipo) {
|
|
17519
17717
|
if (!tipo || tipo === 'qualquer')
|
|
@@ -17764,7 +17962,7 @@ class DescritorTipoClasse extends chamavel_1.Chamavel {
|
|
|
17764
17962
|
var _a, _b;
|
|
17765
17963
|
const nome = (_b = (_a = this.simboloOriginal) === null || _a === void 0 ? void 0 : _a.lexema) !== null && _b !== void 0 ? _b : 'Objeto';
|
|
17766
17964
|
const nomesMetodos = Object.keys(this.metodos).join(', ');
|
|
17767
|
-
const nomesPropriedades = this.propriedades.map(p => p.nome.lexema).join(', ');
|
|
17965
|
+
const nomesPropriedades = this.propriedades.map((p) => p.nome.lexema).join(', ');
|
|
17768
17966
|
return `<[ ${nome} estático métodos=[${nomesMetodos}] propriedades=[${nomesPropriedades}] ]>`;
|
|
17769
17967
|
}
|
|
17770
17968
|
/**
|
|
@@ -17893,11 +18091,11 @@ const excecoes_1 = require("../../excecoes");
|
|
|
17893
18091
|
const chamavel_1 = require("./chamavel");
|
|
17894
18092
|
const tiposNumericos = ['inteiro', 'número', 'real', 'longo'];
|
|
17895
18093
|
const mapaDeNormalizacao = {
|
|
17896
|
-
|
|
17897
|
-
|
|
17898
|
-
|
|
17899
|
-
|
|
17900
|
-
|
|
18094
|
+
numero: 'número',
|
|
18095
|
+
logico: 'lógico',
|
|
18096
|
+
funcao: 'função',
|
|
18097
|
+
dicionario: 'dicionário',
|
|
18098
|
+
modulo: 'módulo',
|
|
17901
18099
|
};
|
|
17902
18100
|
function normalizarTipo(tipo) {
|
|
17903
18101
|
if (!tipo || tipo === 'qualquer')
|
|
@@ -17987,8 +18185,10 @@ class MetodoPolimorfico extends chamavel_1.Chamavel {
|
|
|
17987
18185
|
? argumentos[i].valor
|
|
17988
18186
|
: argumentos[i];
|
|
17989
18187
|
// Se o valor é uma VariavelInterface, extrair o valor real
|
|
17990
|
-
if (valorArgumento &&
|
|
17991
|
-
|
|
18188
|
+
if (valorArgumento &&
|
|
18189
|
+
typeof valorArgumento === 'object' &&
|
|
18190
|
+
valorArgumento.hasOwnProperty('valor') &&
|
|
18191
|
+
valorArgumento.hasOwnProperty('tipo')) {
|
|
17992
18192
|
valorArgumento = valorArgumento.valor;
|
|
17993
18193
|
}
|
|
17994
18194
|
const tipoArgumento = (0, inferenciador_1.inferirTipoVariavel)(valorArgumento);
|
|
@@ -18009,8 +18209,10 @@ class MetodoPolimorfico extends chamavel_1.Chamavel {
|
|
|
18009
18209
|
if (!melhorSobrecarga) {
|
|
18010
18210
|
const tiposArgs = argumentos.map((a) => {
|
|
18011
18211
|
let val = a && a.hasOwnProperty('valor') ? a.valor : a;
|
|
18012
|
-
if (val &&
|
|
18013
|
-
|
|
18212
|
+
if (val &&
|
|
18213
|
+
typeof val === 'object' &&
|
|
18214
|
+
val.hasOwnProperty('valor') &&
|
|
18215
|
+
val.hasOwnProperty('tipo')) {
|
|
18014
18216
|
val = val.valor;
|
|
18015
18217
|
}
|
|
18016
18218
|
return normalizarTipo((0, inferenciador_1.inferirTipoVariavel)(val));
|
|
@@ -18224,10 +18426,14 @@ const excecoes_1 = require("../../excecoes");
|
|
|
18224
18426
|
class ObjetoDeleguaClasse {
|
|
18225
18427
|
valorPadraoParaTipo(tipo) {
|
|
18226
18428
|
switch (tipo) {
|
|
18227
|
-
case 'numero':
|
|
18228
|
-
|
|
18229
|
-
case '
|
|
18230
|
-
|
|
18429
|
+
case 'numero':
|
|
18430
|
+
return 0;
|
|
18431
|
+
case 'texto':
|
|
18432
|
+
return '';
|
|
18433
|
+
case 'logico':
|
|
18434
|
+
return false;
|
|
18435
|
+
default:
|
|
18436
|
+
return undefined;
|
|
18231
18437
|
}
|
|
18232
18438
|
}
|
|
18233
18439
|
constructor(classe) {
|
|
@@ -18298,7 +18504,7 @@ class ObjetoDeleguaClasse {
|
|
|
18298
18504
|
return await metodoObtenedor.chamar(visitante, []);
|
|
18299
18505
|
}
|
|
18300
18506
|
// Auto-property: acessa o campo de armazenamento interno '_nome'
|
|
18301
|
-
const propAuto = this.classe.propriedades.find(p => p.nome.lexema === simbolo.lexema);
|
|
18507
|
+
const propAuto = this.classe.propriedades.find((p) => p.nome.lexema === simbolo.lexema);
|
|
18302
18508
|
if (propAuto === null || propAuto === void 0 ? void 0 : propAuto.autoObter) {
|
|
18303
18509
|
this.verificarAcessoLeitura(simbolo.lexema, simbolo, visitante);
|
|
18304
18510
|
return this.propriedades['_' + simbolo.lexema];
|
|
@@ -18343,7 +18549,7 @@ class ObjetoDeleguaClasse {
|
|
|
18343
18549
|
return;
|
|
18344
18550
|
}
|
|
18345
18551
|
// Auto-property: armazena no campo interno '_nome'
|
|
18346
|
-
const propAuto = this.classe.propriedades.find(p => p.nome.lexema === simbolo.lexema);
|
|
18552
|
+
const propAuto = this.classe.propriedades.find((p) => p.nome.lexema === simbolo.lexema);
|
|
18347
18553
|
if (propAuto === null || propAuto === void 0 ? void 0 : propAuto.autoDefinir) {
|
|
18348
18554
|
this.verificarAcessoLeitura(simbolo.lexema, simbolo, visitante);
|
|
18349
18555
|
this.propriedades['_' + simbolo.lexema] = valor;
|
|
@@ -18640,7 +18846,7 @@ class InterpretadorBase {
|
|
|
18640
18846
|
}
|
|
18641
18847
|
// Se é array, resolve recursivamente todos os elementos
|
|
18642
18848
|
if (Array.isArray(objeto)) {
|
|
18643
|
-
return objeto.map(elemento => this.resolverValorRecursivo(elemento));
|
|
18849
|
+
return objeto.map((elemento) => this.resolverValorRecursivo(elemento));
|
|
18644
18850
|
}
|
|
18645
18851
|
// Se é objeto plano, resolve recursivamente todas as propriedades
|
|
18646
18852
|
if (objeto && objeto.constructor && objeto.constructor === Object) {
|
|
@@ -18683,8 +18889,18 @@ class InterpretadorBase {
|
|
|
18683
18889
|
async visitarExpressaoTupla(expressao) {
|
|
18684
18890
|
// Lista de propriedades válidas para tuplas (ignorar propriedades de controle)
|
|
18685
18891
|
const propriedadesValidas = [
|
|
18686
|
-
'primeiro',
|
|
18687
|
-
'
|
|
18892
|
+
'primeiro',
|
|
18893
|
+
'segundo',
|
|
18894
|
+
'terceiro',
|
|
18895
|
+
'quarto',
|
|
18896
|
+
'quinto',
|
|
18897
|
+
'sexto',
|
|
18898
|
+
'sétimo',
|
|
18899
|
+
'setimo',
|
|
18900
|
+
'oitavo',
|
|
18901
|
+
'nono',
|
|
18902
|
+
'décimo',
|
|
18903
|
+
'decimo',
|
|
18688
18904
|
];
|
|
18689
18905
|
const valores = [];
|
|
18690
18906
|
for (let propriedade of propriedadesValidas) {
|
|
@@ -18701,7 +18917,7 @@ class InterpretadorBase {
|
|
|
18701
18917
|
const res = await this.avaliar(expressao.elementos[i]);
|
|
18702
18918
|
elementos.push(this.resolverValor(res));
|
|
18703
18919
|
}
|
|
18704
|
-
const elementosComoConstrutos = elementos.map(valor => new construtos_1.Literal(expressao.hashArquivo, expressao.linha, valor));
|
|
18920
|
+
const elementosComoConstrutos = elementos.map((valor) => new construtos_1.Literal(expressao.hashArquivo, expressao.linha, valor));
|
|
18705
18921
|
return new construtos_1.TuplaN(expressao.hashArquivo, expressao.linha, elementosComoConstrutos);
|
|
18706
18922
|
}
|
|
18707
18923
|
async visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) {
|
|
@@ -19043,8 +19259,12 @@ class InterpretadorBase {
|
|
|
19043
19259
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19044
19260
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19045
19261
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19046
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19047
|
-
|
|
19262
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19263
|
+
? valorEsquerdo
|
|
19264
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19265
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19266
|
+
? valorDireito
|
|
19267
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19048
19268
|
return esq ** dir;
|
|
19049
19269
|
}
|
|
19050
19270
|
const resultadoExponenciacao = Math.pow(valorEsquerdo, valorDireito);
|
|
@@ -19072,8 +19292,12 @@ class InterpretadorBase {
|
|
|
19072
19292
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19073
19293
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19074
19294
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19075
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19076
|
-
|
|
19295
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19296
|
+
? valorEsquerdo
|
|
19297
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19298
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19299
|
+
? valorDireito
|
|
19300
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19077
19301
|
return esq - dir;
|
|
19078
19302
|
}
|
|
19079
19303
|
return Number(valorEsquerdo) - Number(valorDireito);
|
|
@@ -19085,8 +19309,12 @@ class InterpretadorBase {
|
|
|
19085
19309
|
}
|
|
19086
19310
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19087
19311
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19088
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19089
|
-
|
|
19312
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19313
|
+
? valorEsquerdo
|
|
19314
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19315
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19316
|
+
? valorDireito
|
|
19317
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19090
19318
|
return esq + dir;
|
|
19091
19319
|
}
|
|
19092
19320
|
if (this.tiposNumericos.includes(tipoEsquerdo) &&
|
|
@@ -19116,8 +19344,12 @@ class InterpretadorBase {
|
|
|
19116
19344
|
}
|
|
19117
19345
|
// Retorna BigInt se qualquer operando for BigInt
|
|
19118
19346
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19119
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19120
|
-
|
|
19347
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19348
|
+
? valorEsquerdo
|
|
19349
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19350
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19351
|
+
? valorDireito
|
|
19352
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19121
19353
|
return esq / dir; // Trunca automaticamente
|
|
19122
19354
|
}
|
|
19123
19355
|
return Math.floor(Number(valorEsquerdo) / Number(valorDireito));
|
|
@@ -19127,8 +19359,12 @@ class InterpretadorBase {
|
|
|
19127
19359
|
if ((typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') &&
|
|
19128
19360
|
tipoEsquerdo !== delegua_2.default.TEXTO &&
|
|
19129
19361
|
tipoDireito !== delegua_2.default.TEXTO) {
|
|
19130
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19131
|
-
|
|
19362
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19363
|
+
? valorEsquerdo
|
|
19364
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19365
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19366
|
+
? valorDireito
|
|
19367
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19132
19368
|
return esq * dir;
|
|
19133
19369
|
}
|
|
19134
19370
|
if (tipoEsquerdo === delegua_2.default.TEXTO ||
|
|
@@ -19161,7 +19397,8 @@ class InterpretadorBase {
|
|
|
19161
19397
|
case delegua_1.default.MODULO:
|
|
19162
19398
|
case delegua_1.default.MODULO_IGUAL:
|
|
19163
19399
|
// Se o operando esquerdo é uma string, usar formatação de string
|
|
19164
|
-
if (tipoEsquerdo === delegua_2.default.TEXTO ||
|
|
19400
|
+
if (tipoEsquerdo === delegua_2.default.TEXTO ||
|
|
19401
|
+
typeof valorEsquerdo === 'string') {
|
|
19165
19402
|
return this.formatarStringComOperadorPorcentagem(String(valorEsquerdo), direita, // Passar 'direita' ao invés de 'valorDireito' para preservar arrays de tuplas
|
|
19166
19403
|
expressao.operador);
|
|
19167
19404
|
}
|
|
@@ -19175,8 +19412,12 @@ class InterpretadorBase {
|
|
|
19175
19412
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19176
19413
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19177
19414
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19178
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19179
|
-
|
|
19415
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19416
|
+
? valorEsquerdo
|
|
19417
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19418
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19419
|
+
? valorDireito
|
|
19420
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19180
19421
|
return esq & dir;
|
|
19181
19422
|
}
|
|
19182
19423
|
return Number(valorEsquerdo) & Number(valorDireito);
|
|
@@ -19187,8 +19428,12 @@ class InterpretadorBase {
|
|
|
19187
19428
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19188
19429
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19189
19430
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19190
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19191
|
-
|
|
19431
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19432
|
+
? valorEsquerdo
|
|
19433
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19434
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19435
|
+
? valorDireito
|
|
19436
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19192
19437
|
return esq ^ dir;
|
|
19193
19438
|
}
|
|
19194
19439
|
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
@@ -19199,8 +19444,12 @@ class InterpretadorBase {
|
|
|
19199
19444
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19200
19445
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19201
19446
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19202
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19203
|
-
|
|
19447
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19448
|
+
? valorEsquerdo
|
|
19449
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19450
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19451
|
+
? valorDireito
|
|
19452
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19204
19453
|
return esq | dir;
|
|
19205
19454
|
}
|
|
19206
19455
|
return Number(valorEsquerdo) | Number(valorDireito);
|
|
@@ -19208,9 +19457,15 @@ class InterpretadorBase {
|
|
|
19208
19457
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19209
19458
|
// Auto-promove para BigInt (interno para longo) se qualquer operando for BigInt ou se deslocamento >= 32
|
|
19210
19459
|
const tamanhoDeslocamentoEsquerda = Number(valorDireito);
|
|
19211
|
-
if (typeof valorEsquerdo === 'bigint' ||
|
|
19212
|
-
|
|
19213
|
-
|
|
19460
|
+
if (typeof valorEsquerdo === 'bigint' ||
|
|
19461
|
+
typeof valorDireito === 'bigint' ||
|
|
19462
|
+
tamanhoDeslocamentoEsquerda >= 32) {
|
|
19463
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19464
|
+
? valorEsquerdo
|
|
19465
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19466
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19467
|
+
? valorDireito
|
|
19468
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19214
19469
|
return esq << dir;
|
|
19215
19470
|
}
|
|
19216
19471
|
return Number(valorEsquerdo) << Number(valorDireito);
|
|
@@ -19218,9 +19473,15 @@ class InterpretadorBase {
|
|
|
19218
19473
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19219
19474
|
// Auto-promove para BigInt (interno para longo) se qualquer operando for BigInt ou se deslocamento >= 32
|
|
19220
19475
|
const tamanhoDeslocamentoDireita = Number(valorDireito);
|
|
19221
|
-
if (typeof valorEsquerdo === 'bigint' ||
|
|
19222
|
-
|
|
19223
|
-
|
|
19476
|
+
if (typeof valorEsquerdo === 'bigint' ||
|
|
19477
|
+
typeof valorDireito === 'bigint' ||
|
|
19478
|
+
tamanhoDeslocamentoDireita >= 32) {
|
|
19479
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19480
|
+
? valorEsquerdo
|
|
19481
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19482
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19483
|
+
? valorDireito
|
|
19484
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19224
19485
|
return esq >> dir;
|
|
19225
19486
|
}
|
|
19226
19487
|
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
@@ -19341,7 +19602,8 @@ class InterpretadorBase {
|
|
|
19341
19602
|
// Casos que passam aqui: chamadas a métodos de bibliotecas de Delégua.
|
|
19342
19603
|
if (typeof entidadeChamada === primitivos_1.default.FUNCAO) {
|
|
19343
19604
|
let objeto = null;
|
|
19344
|
-
if (expressao.entidadeChamada.objeto) {
|
|
19605
|
+
if (expressao.entidadeChamada.objeto) {
|
|
19606
|
+
// TODO: Qual o tipo certo aqui?
|
|
19345
19607
|
objeto = await this.avaliar(expressao.entidadeChamada.objeto);
|
|
19346
19608
|
}
|
|
19347
19609
|
return entidadeChamada.apply(this.resolverValor(objeto), argumentos);
|
|
@@ -19400,7 +19662,8 @@ class InterpretadorBase {
|
|
|
19400
19662
|
}
|
|
19401
19663
|
logicaContemOuEm(esquerda, direita, expressao) {
|
|
19402
19664
|
const valorDireitoResolvido = this.resolverValor(direita);
|
|
19403
|
-
if (Array.isArray(valorDireitoResolvido) ||
|
|
19665
|
+
if (Array.isArray(valorDireitoResolvido) ||
|
|
19666
|
+
typeof valorDireitoResolvido === primitivos_1.default.TEXTO) {
|
|
19404
19667
|
const avaliacao = valorDireitoResolvido.includes(esquerda);
|
|
19405
19668
|
return expressao.negado ? !avaliacao : avaliacao;
|
|
19406
19669
|
}
|
|
@@ -19432,13 +19695,19 @@ class InterpretadorBase {
|
|
|
19432
19695
|
const valorDireito = this.resolverValor(direita);
|
|
19433
19696
|
if (typeof valorDireito === 'number' || typeof valorDireito === 'bigint') {
|
|
19434
19697
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19435
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19436
|
-
|
|
19437
|
-
|
|
19698
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19699
|
+
? valorEsquerdo
|
|
19700
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19701
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19702
|
+
? valorDireito
|
|
19703
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19704
|
+
return expressao.operador.tipo === delegua_1.default.E
|
|
19705
|
+
? esq & dir
|
|
19706
|
+
: esq | dir;
|
|
19438
19707
|
}
|
|
19439
19708
|
return expressao.operador.tipo === delegua_1.default.E
|
|
19440
|
-
?
|
|
19441
|
-
:
|
|
19709
|
+
? Number(valorEsquerdo) & Number(valorDireito)
|
|
19710
|
+
: Number(valorEsquerdo) | Number(valorDireito);
|
|
19442
19711
|
}
|
|
19443
19712
|
// Demais casos sem diferença de tipos
|
|
19444
19713
|
if (expressao.operador.tipo === delegua_1.default.OU) {
|
|
@@ -19532,7 +19801,7 @@ class InterpretadorBase {
|
|
|
19532
19801
|
const valorComoDupla = valorVetorResolvido[declaracao.posicaoAtual];
|
|
19533
19802
|
const promises = await Promise.all([
|
|
19534
19803
|
this.avaliar(declaracao.variavelIteracao.primeiro),
|
|
19535
|
-
this.avaliar(declaracao.variavelIteracao.segundo)
|
|
19804
|
+
this.avaliar(declaracao.variavelIteracao.segundo),
|
|
19536
19805
|
]);
|
|
19537
19806
|
// TODO: O que fazer quando não forem literais?
|
|
19538
19807
|
this.pilhaEscoposExecucao.definirVariavel(String(promises[0].valor), valorComoDupla.primeiro);
|
|
@@ -19712,7 +19981,9 @@ class InterpretadorBase {
|
|
|
19712
19981
|
let formatoTexto = '';
|
|
19713
19982
|
for (const argumento of argumentos) {
|
|
19714
19983
|
let resultadoAvaliacao = await this.avaliar(argumento);
|
|
19715
|
-
if (resultadoAvaliacao &&
|
|
19984
|
+
if (resultadoAvaliacao &&
|
|
19985
|
+
resultadoAvaliacao.hasOwnProperty &&
|
|
19986
|
+
resultadoAvaliacao.hasOwnProperty('valorRetornado')) {
|
|
19716
19987
|
resultadoAvaliacao = resultadoAvaliacao.valorRetornado;
|
|
19717
19988
|
}
|
|
19718
19989
|
let valor = this.resolverValor(resultadoAvaliacao);
|
|
@@ -19953,12 +20224,12 @@ class InterpretadorBase {
|
|
|
19953
20224
|
}, 'Somente listas, dicionários, classes e objetos podem ter seus valores indexados.', expressao.linha));
|
|
19954
20225
|
}
|
|
19955
20226
|
/**
|
|
19956
|
-
|
|
19957
|
-
|
|
19958
|
-
|
|
19959
|
-
|
|
20227
|
+
* Método base para acesso a intervalo.
|
|
20228
|
+
* Por padrão lança erro, pois a maioria dos dialetos (como Delégua padrão)
|
|
20229
|
+
* ainda não suporta isso nativamente, apenas Pituguês.
|
|
20230
|
+
*/
|
|
19960
20231
|
visitarExpressaoAcessoIntervaloVariavel(expressao) {
|
|
19961
|
-
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento,
|
|
20232
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Acesso por intervalo não implementado para este dialeto.', expressao.linha));
|
|
19962
20233
|
}
|
|
19963
20234
|
async visitarExpressaoDefinirValor(expressao) {
|
|
19964
20235
|
const variavelObjeto = await this.avaliar(expressao.objeto);
|
|
@@ -19975,14 +20246,12 @@ class InterpretadorBase {
|
|
|
19975
20246
|
objeto[expressao.nome.lexema] = valor;
|
|
19976
20247
|
}
|
|
19977
20248
|
}
|
|
19978
|
-
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
20249
|
+
async visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
19979
20250
|
const funcao = new estruturas_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
19980
20251
|
funcao.documentacao = declaracao.documentacao;
|
|
19981
20252
|
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
19982
20253
|
this.pilhaEscoposExecucao.registrarReferenciaFuncao(declaracao.id, funcao);
|
|
19983
|
-
return
|
|
19984
|
-
declaracao: funcao,
|
|
19985
|
-
});
|
|
20254
|
+
return { declaracao: funcao };
|
|
19986
20255
|
}
|
|
19987
20256
|
/**
|
|
19988
20257
|
* Executa uma declaração de classe.
|
|
@@ -20042,9 +20311,7 @@ class InterpretadorBase {
|
|
|
20042
20311
|
const funcao = new estruturas_1.DeleguaFuncao(nomeMetodo, metodoAtual.funcao, undefined, eInicializador);
|
|
20043
20312
|
funcao.documentacao = metodoAtual.documentacao;
|
|
20044
20313
|
// Numa classe estática, todos os métodos (exceto construtor) são estáticos.
|
|
20045
|
-
const ehEstatico = declaracao.classeEstatica
|
|
20046
|
-
? !eInicializador
|
|
20047
|
-
: metodoAtual.estatico;
|
|
20314
|
+
const ehEstatico = declaracao.classeEstatica ? !eInicializador : metodoAtual.estatico;
|
|
20048
20315
|
if (metodoAtual.eObtenedor) {
|
|
20049
20316
|
if (ehEstatico) {
|
|
20050
20317
|
obtenedoresEstaticos[nomeMetodo] = funcao;
|
|
@@ -20100,7 +20367,9 @@ class InterpretadorBase {
|
|
|
20100
20367
|
// Toda classe sem superclasse explícita herda implicitamente de `Objeto`.
|
|
20101
20368
|
// Isso só deve acontecer quando OBJETO_BASE já estiver inicializado e a classe
|
|
20102
20369
|
// atual não for o próprio OBJETO_BASE, para evitar cadeias de herança recursivas.
|
|
20103
|
-
if (descritorTipoClasse.superClasses.length === 0 &&
|
|
20370
|
+
if (descritorTipoClasse.superClasses.length === 0 &&
|
|
20371
|
+
estruturas_1.OBJETO_BASE &&
|
|
20372
|
+
descritorTipoClasse !== estruturas_1.OBJETO_BASE) {
|
|
20104
20373
|
descritorTipoClasse.superClasses = [estruturas_1.OBJETO_BASE];
|
|
20105
20374
|
}
|
|
20106
20375
|
// Calcular o OReM (linearização C3) após os pais estarem definidos.
|
|
@@ -20363,21 +20632,25 @@ class InterpretadorBase {
|
|
|
20363
20632
|
let valoresArray;
|
|
20364
20633
|
// Verificar se é uma TuplaN (verifica instanceof OU propriedade elementos/tipo para maior compatibilidade)
|
|
20365
20634
|
if (valores instanceof construtos_1.TuplaN ||
|
|
20366
|
-
(valores &&
|
|
20635
|
+
(valores &&
|
|
20636
|
+
valores.tipo === 'tupla' &&
|
|
20637
|
+
valores.elementos &&
|
|
20638
|
+
Array.isArray(valores.elementos))) {
|
|
20367
20639
|
valoresArray = valores.elementos.map((elem) => {
|
|
20368
|
-
if (elem instanceof construtos_1.Literal ||
|
|
20640
|
+
if (elem instanceof construtos_1.Literal ||
|
|
20641
|
+
(elem && typeof elem === 'object' && elem.hasOwnProperty('valor'))) {
|
|
20369
20642
|
return this.resolverValor(elem.valor);
|
|
20370
20643
|
}
|
|
20371
20644
|
return this.resolverValor(elem);
|
|
20372
20645
|
});
|
|
20373
20646
|
}
|
|
20374
20647
|
else if (Array.isArray(valores)) {
|
|
20375
|
-
valoresArray = valores.map(v => this.resolverValor(v));
|
|
20648
|
+
valoresArray = valores.map((v) => this.resolverValor(v));
|
|
20376
20649
|
}
|
|
20377
20650
|
else {
|
|
20378
20651
|
const valorResolvido = this.resolverValor(valores);
|
|
20379
20652
|
if (Array.isArray(valorResolvido)) {
|
|
20380
|
-
valoresArray = valorResolvido.map(v => this.resolverValor(v));
|
|
20653
|
+
valoresArray = valorResolvido.map((v) => this.resolverValor(v));
|
|
20381
20654
|
}
|
|
20382
20655
|
else {
|
|
20383
20656
|
valoresArray = [valorResolvido];
|
|
@@ -20499,7 +20772,9 @@ class InterpretadorBase {
|
|
|
20499
20772
|
return objeto.valor.paraTexto();
|
|
20500
20773
|
if (objeto instanceof construtos_1.Literal)
|
|
20501
20774
|
return this.paraTexto(objeto.valor);
|
|
20502
|
-
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
20775
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
20776
|
+
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
20777
|
+
objeto instanceof estruturas_1.DescritorTipoClasse)
|
|
20503
20778
|
return objeto.paraTexto();
|
|
20504
20779
|
if (objeto instanceof quebras_1.RetornoQuebra) {
|
|
20505
20780
|
if (typeof objeto.valor === 'boolean')
|
|
@@ -20764,10 +21039,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
20764
21039
|
return objeto;
|
|
20765
21040
|
}
|
|
20766
21041
|
serializarSemEspacos(objeto) {
|
|
20767
|
-
return JSON
|
|
20768
|
-
.stringify(objeto)
|
|
20769
|
-
.replace(/,\s+/g, ',')
|
|
20770
|
-
.replace(/:\s+/g, ':');
|
|
21042
|
+
return JSON.stringify(objeto).replace(/,\s+/g, ',').replace(/:\s+/g, ':');
|
|
20771
21043
|
}
|
|
20772
21044
|
paraTexto(objeto) {
|
|
20773
21045
|
if (objeto === null || objeto === undefined)
|
|
@@ -20782,7 +21054,9 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
20782
21054
|
return objeto.valor.paraTexto();
|
|
20783
21055
|
if (objeto instanceof construtos_1.Literal || objeto instanceof construtos_1.Tupla)
|
|
20784
21056
|
return objeto.paraTextoSaida();
|
|
20785
|
-
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
21057
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
21058
|
+
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
21059
|
+
objeto instanceof estruturas_1.DescritorTipoClasse)
|
|
20786
21060
|
return objeto.paraTexto();
|
|
20787
21061
|
if (objeto instanceof quebras_1.RetornoQuebra) {
|
|
20788
21062
|
if (typeof objeto.valor === 'boolean')
|
|
@@ -20883,15 +21157,25 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
20883
21157
|
async visitarDeclaracaoAjuda(declaracao) {
|
|
20884
21158
|
return Promise.resolve((0, comum_1.pontoEntradaAjuda)(declaracao.funcao, declaracao.elemento));
|
|
20885
21159
|
}
|
|
20886
|
-
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
20887
|
-
|
|
21160
|
+
async visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
21161
|
+
var _a, _b;
|
|
21162
|
+
let funcao = new estruturas_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
20888
21163
|
funcao.documentacao = declaracao.documentacao;
|
|
21164
|
+
if (declaracao.decoradores && declaracao.decoradores.length > 0) {
|
|
21165
|
+
for (const decorador of [...declaracao.decoradores].reverse()) {
|
|
21166
|
+
const nomeDecorador = decorador.nome.slice(1);
|
|
21167
|
+
const variavelDecoradora = this.pilhaEscoposExecucao.obterVariavelPorNome(nomeDecorador);
|
|
21168
|
+
const funcaoDecoradora = variavelDecoradora.valor;
|
|
21169
|
+
const resultado = await funcaoDecoradora.chamar(this, [{ nome: null, valor: funcao }]);
|
|
21170
|
+
funcao = this.resolverValorRecursivo(resultado);
|
|
21171
|
+
}
|
|
21172
|
+
}
|
|
20889
21173
|
// TODO: Depreciar essa abordagem a favor do uso por referências?
|
|
20890
21174
|
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
20891
21175
|
this.pilhaEscoposExecucao.registrarReferenciaFuncao(declaracao.id, funcao);
|
|
20892
21176
|
return Promise.resolve({
|
|
20893
|
-
tipo: `função<${funcao.declaracao.tipo || 'qualquer'}>`,
|
|
20894
|
-
tipoExplicito: funcao.declaracao.tipoExplicito,
|
|
21177
|
+
tipo: `função<${((_a = funcao.declaracao) === null || _a === void 0 ? void 0 : _a.tipo) || 'qualquer'}>`,
|
|
21178
|
+
tipoExplicito: (_b = funcao.declaracao) === null || _b === void 0 ? void 0 : _b.tipoExplicito,
|
|
20895
21179
|
declaracao: funcao,
|
|
20896
21180
|
});
|
|
20897
21181
|
}
|
|
@@ -21058,11 +21342,11 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21058
21342
|
const valorComoDupla = valorVetorOuDicionarioResolvido[paraCada.posicaoAtual];
|
|
21059
21343
|
const nomesVariaveis = await Promise.all([
|
|
21060
21344
|
this.avaliar(paraCada.variavelIteracao.primeiro),
|
|
21061
|
-
this.avaliar(paraCada.variavelIteracao.segundo)
|
|
21345
|
+
this.avaliar(paraCada.variavelIteracao.segundo),
|
|
21062
21346
|
]);
|
|
21063
21347
|
const valoresDupla = await Promise.all([
|
|
21064
21348
|
this.avaliar(valorComoDupla.primeiro),
|
|
21065
|
-
this.avaliar(valorComoDupla.segundo)
|
|
21349
|
+
this.avaliar(valorComoDupla.segundo),
|
|
21066
21350
|
]);
|
|
21067
21351
|
// nomesVariaveis são strings (nomes das variáveis)
|
|
21068
21352
|
this.pilhaEscoposExecucao.definirVariavel(String(nomesVariaveis[0]), valoresDupla[0]);
|
|
@@ -21808,18 +22092,20 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21808
22092
|
// Tratamento especial para expressões unárias aplicadas a chamadas de método em literais numéricos.
|
|
21809
22093
|
// Por exemplo: -5.absoluto() deve ser avaliado como (-5).absoluto(), não como -(5.absoluto())
|
|
21810
22094
|
// Isso garante que o operador unário seja aplicado ao literal antes de chamar o método.
|
|
21811
|
-
if ((expressao.operador.tipo === delegua_2.default.SUBTRACAO ||
|
|
22095
|
+
if ((expressao.operador.tipo === delegua_2.default.SUBTRACAO ||
|
|
22096
|
+
expressao.operador.tipo === delegua_2.default.ADICAO) &&
|
|
21812
22097
|
expressao.operando instanceof construtos_1.Chamada) {
|
|
21813
22098
|
const entidadeChamada = expressao.operando.entidadeChamada;
|
|
21814
22099
|
// Verifica se é AcessoMetodo ou AcessoMetodoOuPropriedade
|
|
21815
|
-
if (entidadeChamada instanceof construtos_1.AcessoMetodo ||
|
|
22100
|
+
if (entidadeChamada instanceof construtos_1.AcessoMetodo ||
|
|
22101
|
+
entidadeChamada instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
21816
22102
|
const objetoAcesso = entidadeChamada.objeto;
|
|
21817
22103
|
// Verifica se o objeto do método é um literal numérico
|
|
21818
22104
|
if (objetoAcesso instanceof construtos_1.Literal && typeof objetoAcesso.valor === 'number') {
|
|
21819
22105
|
// Cria um novo literal com o sinal aplicado
|
|
21820
|
-
const novoLiteral = new construtos_1.Literal(objetoAcesso.hashArquivo, objetoAcesso.linha, expressao.operador.tipo === delegua_2.default.SUBTRACAO
|
|
21821
|
-
-objetoAcesso.valor
|
|
21822
|
-
+objetoAcesso.valor);
|
|
22106
|
+
const novoLiteral = new construtos_1.Literal(objetoAcesso.hashArquivo, objetoAcesso.linha, expressao.operador.tipo === delegua_2.default.SUBTRACAO
|
|
22107
|
+
? -objetoAcesso.valor
|
|
22108
|
+
: +objetoAcesso.valor);
|
|
21823
22109
|
// Cria um novo acesso com o literal modificado
|
|
21824
22110
|
let novoAcesso;
|
|
21825
22111
|
if (entidadeChamada instanceof construtos_1.AcessoMetodo) {
|
|
@@ -21841,7 +22127,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21841
22127
|
async visitarExpressaoVetor(expressao) {
|
|
21842
22128
|
// Delega ao interpretador base para processar o vetor
|
|
21843
22129
|
const vetor = await super.visitarExpressaoVetor(expressao);
|
|
21844
|
-
// Adiciona referência no montão (comportamento específico deste interpretador)
|
|
22130
|
+
// Adiciona referência no montão (comportamento específico deste interpretador)
|
|
21845
22131
|
const enderecoVetorMontao = this.montao.adicionarReferencia(vetor);
|
|
21846
22132
|
this.pilhaEscoposExecucao.registrarReferenciaMontao(enderecoVetorMontao);
|
|
21847
22133
|
return new estruturas_1.ReferenciaMontao(enderecoVetorMontao);
|
|
@@ -23175,7 +23461,9 @@ class LexadorPitugues {
|
|
|
23175
23461
|
}
|
|
23176
23462
|
const deslocamento = ehFString ? 2 : 1;
|
|
23177
23463
|
const textoCompleto = this.codigo[this.linha].substring(this.inicioSimbolo + deslocamento, this.atual);
|
|
23178
|
-
if (textoCompleto.length === 0 &&
|
|
23464
|
+
if (textoCompleto.length === 0 &&
|
|
23465
|
+
!this.eFinalDoCodigo() &&
|
|
23466
|
+
this.codigo[this.linha].charAt(this.atual + 1) === delimitador) {
|
|
23179
23467
|
this.avancar(); // Avança para o próximo delimitador
|
|
23180
23468
|
this.analisarTextoMultilinha(delimitador);
|
|
23181
23469
|
return;
|
|
@@ -23184,25 +23472,26 @@ class LexadorPitugues {
|
|
|
23184
23472
|
this.simbolos.push(new simbolo_1.Simbolo(tipoSimbolo, textoCompleto, valor, linhaPrimeiroCaracter + 1, this.hashArquivo));
|
|
23185
23473
|
}
|
|
23186
23474
|
analisarNumero() {
|
|
23187
|
-
const
|
|
23188
|
-
while (this.
|
|
23475
|
+
const linhaInicial = this.linha;
|
|
23476
|
+
while (this.linha === linhaInicial &&
|
|
23477
|
+
this.eDigito(this.simboloAtual()))
|
|
23189
23478
|
this.avancar();
|
|
23190
|
-
|
|
23191
|
-
|
|
23479
|
+
const temPonto = this.simboloAtual() === '.';
|
|
23480
|
+
const proximoEhDigito = this.eDigito(this.proximoSimbolo());
|
|
23481
|
+
if (this.linha === linhaInicial && temPonto && proximoEhDigito) {
|
|
23192
23482
|
this.avancar();
|
|
23193
|
-
while (this.
|
|
23483
|
+
while (this.linha === linhaInicial &&
|
|
23484
|
+
this.eDigito(this.simboloAtual()))
|
|
23194
23485
|
this.avancar();
|
|
23195
|
-
}
|
|
23196
23486
|
}
|
|
23197
23487
|
let numeroCompleto;
|
|
23198
|
-
if (
|
|
23199
|
-
|
|
23200
|
-
numeroCompleto = linhaNumero.substring(this.inicioSimbolo, linhaNumero.length);
|
|
23488
|
+
if (linhaInicial < this.linha) {
|
|
23489
|
+
numeroCompleto = this.codigo[linhaInicial].substring(this.inicioSimbolo, this.codigo[linhaInicial].length);
|
|
23201
23490
|
}
|
|
23202
23491
|
else {
|
|
23203
23492
|
numeroCompleto = this.codigo[this.linha].substring(this.inicioSimbolo, this.atual);
|
|
23204
23493
|
}
|
|
23205
|
-
this.simbolos.push(new simbolo_1.Simbolo(pitugues_2.default.NUMERO, numeroCompleto, parseFloat(numeroCompleto),
|
|
23494
|
+
this.simbolos.push(new simbolo_1.Simbolo(pitugues_2.default.NUMERO, numeroCompleto, parseFloat(numeroCompleto), linhaInicial + 1, this.hashArquivo));
|
|
23206
23495
|
}
|
|
23207
23496
|
identificarPalavraChave() {
|
|
23208
23497
|
const linhaPrimeiroCaracter = this.linha;
|
|
@@ -23306,8 +23595,13 @@ class LexadorPitugues {
|
|
|
23306
23595
|
this.avancar();
|
|
23307
23596
|
break;
|
|
23308
23597
|
case '.':
|
|
23309
|
-
this.
|
|
23310
|
-
|
|
23598
|
+
if (this.eDigito(this.proximoSimbolo())) {
|
|
23599
|
+
this.analisarNumero();
|
|
23600
|
+
}
|
|
23601
|
+
else {
|
|
23602
|
+
this.adicionarSimbolo(pitugues_2.default.PONTO);
|
|
23603
|
+
this.avancar();
|
|
23604
|
+
}
|
|
23311
23605
|
break;
|
|
23312
23606
|
case '-':
|
|
23313
23607
|
this.avancar();
|
|
@@ -23786,9 +24080,31 @@ class LexadorPrisma {
|
|
|
23786
24080
|
}
|
|
23787
24081
|
eAlfabeto(caractere) {
|
|
23788
24082
|
const acentuacoes = [
|
|
23789
|
-
'á',
|
|
23790
|
-
'
|
|
23791
|
-
'
|
|
24083
|
+
'á',
|
|
24084
|
+
'Á',
|
|
24085
|
+
'ã',
|
|
24086
|
+
'Ã',
|
|
24087
|
+
'â',
|
|
24088
|
+
'Â',
|
|
24089
|
+
'à',
|
|
24090
|
+
'À',
|
|
24091
|
+
'é',
|
|
24092
|
+
'É',
|
|
24093
|
+
'ê',
|
|
24094
|
+
'Ê',
|
|
24095
|
+
'í',
|
|
24096
|
+
'Í',
|
|
24097
|
+
'ó',
|
|
24098
|
+
'Ó',
|
|
24099
|
+
'õ',
|
|
24100
|
+
'Õ',
|
|
24101
|
+
'ô',
|
|
24102
|
+
'Ô',
|
|
24103
|
+
'ú',
|
|
24104
|
+
'Ú',
|
|
24105
|
+
'ç',
|
|
24106
|
+
'Ç',
|
|
24107
|
+
'_',
|
|
23792
24108
|
];
|
|
23793
24109
|
return ((caractere >= 'a' && caractere <= 'z') ||
|
|
23794
24110
|
(caractere >= 'A' && caractere <= 'Z') ||
|
|
@@ -26308,7 +26624,7 @@ exports.palavrasReservadasDelegua = {
|
|
|
26308
26624
|
falso: delegua_1.default.FALSO,
|
|
26309
26625
|
faca: delegua_1.default.FAZER,
|
|
26310
26626
|
fazer: delegua_1.default.FAZER,
|
|
26311
|
-
|
|
26627
|
+
faça: delegua_1.default.FAZER,
|
|
26312
26628
|
finalmente: delegua_1.default.FINALMENTE,
|
|
26313
26629
|
fixo: delegua_1.default.CONSTANTE,
|
|
26314
26630
|
funcao: delegua_1.default.FUNCAO,
|
|
@@ -26354,7 +26670,7 @@ exports.palavrasReservadasDelegua = {
|
|
|
26354
26670
|
var: delegua_1.default.VARIAVEL,
|
|
26355
26671
|
variavel: delegua_1.default.VARIAVEL,
|
|
26356
26672
|
variável: delegua_1.default.VARIAVEL,
|
|
26357
|
-
verdadeiro: delegua_1.default.VERDADEIRO
|
|
26673
|
+
verdadeiro: delegua_1.default.VERDADEIRO,
|
|
26358
26674
|
};
|
|
26359
26675
|
exports.palavrasReservadasMicroGramatica = {
|
|
26360
26676
|
e: delegua_1.default.E,
|
|
@@ -39840,10 +40156,10 @@ class TradutorAssemblyARM {
|
|
|
39840
40156
|
// Para android: ainda é um binário standalone, mas com rótulo Delegua_main
|
|
39841
40157
|
// para deixar claro que não é o _start do CRT padrão.
|
|
39842
40158
|
const entryLabel = this.alvo === 'android' ? 'Delegua_main' : '_start';
|
|
39843
|
-
this.text = `
|
|
39844
|
-
.text
|
|
39845
|
-
.global ${entryLabel}
|
|
39846
|
-
|
|
40159
|
+
this.text = `
|
|
40160
|
+
.text
|
|
40161
|
+
.global ${entryLabel}
|
|
40162
|
+
|
|
39847
40163
|
${entryLabel}:`;
|
|
39848
40164
|
}
|
|
39849
40165
|
gerarDigitoAleatorio() {
|
|
@@ -39885,11 +40201,11 @@ ${entryLabel}:`;
|
|
|
39885
40201
|
}
|
|
39886
40202
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
39887
40203
|
const reg = this.obterRegistrador();
|
|
39888
|
-
this.text += `
|
|
39889
|
-
ldr ${reg}, =${nomeVar}
|
|
39890
|
-
ldr r0, =${indice}
|
|
39891
|
-
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
39892
|
-
add ${reg}, ${reg}, r0
|
|
40204
|
+
this.text += `
|
|
40205
|
+
ldr ${reg}, =${nomeVar}
|
|
40206
|
+
ldr r0, =${indice}
|
|
40207
|
+
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
40208
|
+
add ${reg}, ${reg}, r0
|
|
39893
40209
|
ldr r0, [${reg}]`;
|
|
39894
40210
|
this.liberarRegistrador(reg);
|
|
39895
40211
|
return 'r0';
|
|
@@ -39913,12 +40229,12 @@ ${entryLabel}:`;
|
|
|
39913
40229
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
39914
40230
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
39915
40231
|
const reg = this.obterRegistrador();
|
|
39916
|
-
this.text += `
|
|
39917
|
-
ldr ${reg}, =${nomeVar}
|
|
39918
|
-
ldr r1, =${indice}
|
|
39919
|
-
lsl r1, r1, #2 @ multiply by 4
|
|
39920
|
-
add ${reg}, ${reg}, r1
|
|
39921
|
-
ldr r1, =${valor}
|
|
40232
|
+
this.text += `
|
|
40233
|
+
ldr ${reg}, =${nomeVar}
|
|
40234
|
+
ldr r1, =${indice}
|
|
40235
|
+
lsl r1, r1, #2 @ multiply by 4
|
|
40236
|
+
add ${reg}, ${reg}, r1
|
|
40237
|
+
ldr r1, =${valor}
|
|
39922
40238
|
str r1, [${reg}]`;
|
|
39923
40239
|
this.liberarRegistrador(reg);
|
|
39924
40240
|
}
|
|
@@ -39937,9 +40253,9 @@ ${entryLabel}:`;
|
|
|
39937
40253
|
this.bss += ` ${varLabel}: .space 4\n`;
|
|
39938
40254
|
this.variaveis.set(nomeVar, varLabel);
|
|
39939
40255
|
}
|
|
39940
|
-
this.text += `
|
|
39941
|
-
ldr r0, =${valor}
|
|
39942
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
40256
|
+
this.text += `
|
|
40257
|
+
ldr r0, =${valor}
|
|
40258
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
39943
40259
|
str r0, [r1]`;
|
|
39944
40260
|
}
|
|
39945
40261
|
traduzirConstrutoBinario(construto) {
|
|
@@ -39949,75 +40265,75 @@ ${entryLabel}:`;
|
|
|
39949
40265
|
const reg = this.obterRegistrador();
|
|
39950
40266
|
// Load left operand into r0
|
|
39951
40267
|
if (esquerda !== 'r0') {
|
|
39952
|
-
this.text += `
|
|
40268
|
+
this.text += `
|
|
39953
40269
|
ldr r0, =${esquerda}`;
|
|
39954
40270
|
}
|
|
39955
40271
|
// Load right operand into reg
|
|
39956
|
-
this.text += `
|
|
40272
|
+
this.text += `
|
|
39957
40273
|
ldr ${reg}, =${direita}`;
|
|
39958
40274
|
switch (operador) {
|
|
39959
40275
|
case '+':
|
|
39960
|
-
this.text += `
|
|
40276
|
+
this.text += `
|
|
39961
40277
|
add r0, r0, ${reg}`;
|
|
39962
40278
|
break;
|
|
39963
40279
|
case '-':
|
|
39964
|
-
this.text += `
|
|
40280
|
+
this.text += `
|
|
39965
40281
|
sub r0, r0, ${reg}`;
|
|
39966
40282
|
break;
|
|
39967
40283
|
case '*':
|
|
39968
|
-
this.text += `
|
|
40284
|
+
this.text += `
|
|
39969
40285
|
mul r0, r0, ${reg}`;
|
|
39970
40286
|
break;
|
|
39971
40287
|
case '/':
|
|
39972
|
-
this.text += `
|
|
40288
|
+
this.text += `
|
|
39973
40289
|
sdiv r0, r0, ${reg}`;
|
|
39974
40290
|
break;
|
|
39975
40291
|
case '%':
|
|
39976
|
-
this.text += `
|
|
39977
|
-
sdiv r1, r0, ${reg}
|
|
39978
|
-
mul r1, r1, ${reg}
|
|
40292
|
+
this.text += `
|
|
40293
|
+
sdiv r1, r0, ${reg}
|
|
40294
|
+
mul r1, r1, ${reg}
|
|
39979
40295
|
sub r0, r0, r1 @ r0 = r0 - (r0/reg)*reg`;
|
|
39980
40296
|
break;
|
|
39981
40297
|
case '<':
|
|
39982
|
-
this.text += `
|
|
39983
|
-
cmp r0, ${reg}
|
|
39984
|
-
movlt r0, #1
|
|
40298
|
+
this.text += `
|
|
40299
|
+
cmp r0, ${reg}
|
|
40300
|
+
movlt r0, #1
|
|
39985
40301
|
movge r0, #0`;
|
|
39986
40302
|
break;
|
|
39987
40303
|
case '>':
|
|
39988
|
-
this.text += `
|
|
39989
|
-
cmp r0, ${reg}
|
|
39990
|
-
movgt r0, #1
|
|
40304
|
+
this.text += `
|
|
40305
|
+
cmp r0, ${reg}
|
|
40306
|
+
movgt r0, #1
|
|
39991
40307
|
movle r0, #0`;
|
|
39992
40308
|
break;
|
|
39993
40309
|
case '<=':
|
|
39994
|
-
this.text += `
|
|
39995
|
-
cmp r0, ${reg}
|
|
39996
|
-
movle r0, #1
|
|
40310
|
+
this.text += `
|
|
40311
|
+
cmp r0, ${reg}
|
|
40312
|
+
movle r0, #1
|
|
39997
40313
|
movgt r0, #0`;
|
|
39998
40314
|
break;
|
|
39999
40315
|
case '>=':
|
|
40000
|
-
this.text += `
|
|
40001
|
-
cmp r0, ${reg}
|
|
40002
|
-
movge r0, #1
|
|
40316
|
+
this.text += `
|
|
40317
|
+
cmp r0, ${reg}
|
|
40318
|
+
movge r0, #1
|
|
40003
40319
|
movlt r0, #0`;
|
|
40004
40320
|
break;
|
|
40005
40321
|
case '==':
|
|
40006
40322
|
case '===':
|
|
40007
|
-
this.text += `
|
|
40008
|
-
cmp r0, ${reg}
|
|
40009
|
-
moveq r0, #1
|
|
40323
|
+
this.text += `
|
|
40324
|
+
cmp r0, ${reg}
|
|
40325
|
+
moveq r0, #1
|
|
40010
40326
|
movne r0, #0`;
|
|
40011
40327
|
break;
|
|
40012
40328
|
case '!=':
|
|
40013
40329
|
case '!==':
|
|
40014
|
-
this.text += `
|
|
40015
|
-
cmp r0, ${reg}
|
|
40016
|
-
movne r0, #1
|
|
40330
|
+
this.text += `
|
|
40331
|
+
cmp r0, ${reg}
|
|
40332
|
+
movne r0, #1
|
|
40017
40333
|
moveq r0, #0`;
|
|
40018
40334
|
break;
|
|
40019
40335
|
default:
|
|
40020
|
-
this.text += `
|
|
40336
|
+
this.text += `
|
|
40021
40337
|
@ Operador ${operador} não implementado`;
|
|
40022
40338
|
}
|
|
40023
40339
|
this.liberarRegistrador(reg);
|
|
@@ -40035,35 +40351,35 @@ ${entryLabel}:`;
|
|
|
40035
40351
|
if (index < registrosArgs.length) {
|
|
40036
40352
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
40037
40353
|
if (valorArg !== registrosArgs[index]) {
|
|
40038
|
-
this.text += `
|
|
40354
|
+
this.text += `
|
|
40039
40355
|
ldr ${registrosArgs[index]}, =${valorArg}`;
|
|
40040
40356
|
}
|
|
40041
40357
|
}
|
|
40042
40358
|
else {
|
|
40043
40359
|
// Push extra args on stack
|
|
40044
40360
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
40045
|
-
this.text += `
|
|
40046
|
-
ldr r0, =${valorArg}
|
|
40361
|
+
this.text += `
|
|
40362
|
+
ldr r0, =${valorArg}
|
|
40047
40363
|
push {r0}`;
|
|
40048
40364
|
}
|
|
40049
40365
|
});
|
|
40050
|
-
this.text += `
|
|
40366
|
+
this.text += `
|
|
40051
40367
|
bl ${nomeFuncao}`;
|
|
40052
40368
|
}
|
|
40053
40369
|
traduzirConstrutoDefinirValor(construto) {
|
|
40054
40370
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
40055
40371
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
40056
|
-
this.text += `
|
|
40057
|
-
ldr r0, =${valor}
|
|
40058
|
-
ldr r1, =${objeto}
|
|
40372
|
+
this.text += `
|
|
40373
|
+
ldr r0, =${valor}
|
|
40374
|
+
ldr r1, =${objeto}
|
|
40059
40375
|
str r0, [r1]`;
|
|
40060
40376
|
}
|
|
40061
40377
|
traduzirFuncaoConstruto(construto) {
|
|
40062
40378
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
40063
|
-
this.text += `
|
|
40064
|
-
|
|
40065
|
-
${labelFuncao}:
|
|
40066
|
-
push {fp, lr}
|
|
40379
|
+
this.text += `
|
|
40380
|
+
|
|
40381
|
+
${labelFuncao}:
|
|
40382
|
+
push {fp, lr}
|
|
40067
40383
|
mov fp, sp`;
|
|
40068
40384
|
// Traduzir corpo da função
|
|
40069
40385
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -40073,8 +40389,8 @@ ${labelFuncao}:
|
|
|
40073
40389
|
}
|
|
40074
40390
|
});
|
|
40075
40391
|
}
|
|
40076
|
-
this.text += `
|
|
40077
|
-
mov sp, fp
|
|
40392
|
+
this.text += `
|
|
40393
|
+
mov sp, fp
|
|
40078
40394
|
pop {fp, pc}`;
|
|
40079
40395
|
}
|
|
40080
40396
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -40089,29 +40405,29 @@ ${labelFuncao}:
|
|
|
40089
40405
|
const operador = construto.operador.lexema;
|
|
40090
40406
|
const labelVerdadeiro = this.gerarLabel();
|
|
40091
40407
|
const labelFim = this.gerarLabel();
|
|
40092
|
-
this.text += `
|
|
40093
|
-
ldr r0, =${esquerda}
|
|
40408
|
+
this.text += `
|
|
40409
|
+
ldr r0, =${esquerda}
|
|
40094
40410
|
cmp r0, #0`;
|
|
40095
40411
|
if (operador === 'e' || operador === '&&') {
|
|
40096
|
-
this.text += `
|
|
40097
|
-
beq ${labelFim}
|
|
40098
|
-
ldr r0, =${direita}
|
|
40099
|
-
cmp r0, #0
|
|
40100
|
-
beq ${labelFim}
|
|
40101
|
-
${labelVerdadeiro}:
|
|
40102
|
-
mov r0, #1
|
|
40412
|
+
this.text += `
|
|
40413
|
+
beq ${labelFim}
|
|
40414
|
+
ldr r0, =${direita}
|
|
40415
|
+
cmp r0, #0
|
|
40416
|
+
beq ${labelFim}
|
|
40417
|
+
${labelVerdadeiro}:
|
|
40418
|
+
mov r0, #1
|
|
40103
40419
|
${labelFim}:`;
|
|
40104
40420
|
}
|
|
40105
40421
|
else if (operador === 'ou' || operador === '||') {
|
|
40106
|
-
this.text += `
|
|
40107
|
-
bne ${labelVerdadeiro}
|
|
40108
|
-
ldr r0, =${direita}
|
|
40109
|
-
cmp r0, #0
|
|
40110
|
-
bne ${labelVerdadeiro}
|
|
40111
|
-
mov r0, #0
|
|
40112
|
-
b ${labelFim}
|
|
40113
|
-
${labelVerdadeiro}:
|
|
40114
|
-
mov r0, #1
|
|
40422
|
+
this.text += `
|
|
40423
|
+
bne ${labelVerdadeiro}
|
|
40424
|
+
ldr r0, =${direita}
|
|
40425
|
+
cmp r0, #0
|
|
40426
|
+
bne ${labelVerdadeiro}
|
|
40427
|
+
mov r0, #0
|
|
40428
|
+
b ${labelFim}
|
|
40429
|
+
${labelVerdadeiro}:
|
|
40430
|
+
mov r0, #1
|
|
40115
40431
|
${labelFim}:`;
|
|
40116
40432
|
}
|
|
40117
40433
|
return 'r0';
|
|
@@ -40123,16 +40439,16 @@ ${labelFim}:`;
|
|
|
40123
40439
|
traduzirConstrutoUnario(construto) {
|
|
40124
40440
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
40125
40441
|
const operador = construto.operador.lexema;
|
|
40126
|
-
this.text += `
|
|
40442
|
+
this.text += `
|
|
40127
40443
|
ldr r0, =${operando}`;
|
|
40128
40444
|
if (operador === '-') {
|
|
40129
|
-
this.text += `
|
|
40445
|
+
this.text += `
|
|
40130
40446
|
neg r0, r0`;
|
|
40131
40447
|
}
|
|
40132
40448
|
else if (operador === '!' || operador === 'nao') {
|
|
40133
|
-
this.text += `
|
|
40134
|
-
cmp r0, #0
|
|
40135
|
-
moveq r0, #1
|
|
40449
|
+
this.text += `
|
|
40450
|
+
cmp r0, #0
|
|
40451
|
+
moveq r0, #1
|
|
40136
40452
|
movne r0, #0`;
|
|
40137
40453
|
}
|
|
40138
40454
|
return 'r0';
|
|
@@ -40142,8 +40458,8 @@ ${labelFim}:`;
|
|
|
40142
40458
|
const nomeVar = (_a = construto.simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
40143
40459
|
if (nomeVar && this.variaveis.has(nomeVar)) {
|
|
40144
40460
|
const varLabel = this.variaveis.get(nomeVar);
|
|
40145
|
-
this.text += `
|
|
40146
|
-
ldr r0, =${varLabel}
|
|
40461
|
+
this.text += `
|
|
40462
|
+
ldr r0, =${varLabel}
|
|
40147
40463
|
ldr r0, [r0]`;
|
|
40148
40464
|
return 'r0';
|
|
40149
40465
|
}
|
|
@@ -40158,9 +40474,9 @@ ${labelFim}:`;
|
|
|
40158
40474
|
construto.valores.forEach((valor, index) => {
|
|
40159
40475
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
40160
40476
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
40161
|
-
this.text += `
|
|
40162
|
-
ldr r0, =${valorTraduzido}
|
|
40163
|
-
ldr r1, =${labelVetor}
|
|
40477
|
+
this.text += `
|
|
40478
|
+
ldr r0, =${valorTraduzido}
|
|
40479
|
+
ldr r1, =${labelVetor}
|
|
40164
40480
|
str r0, [r1, #${index * 4}]`;
|
|
40165
40481
|
}
|
|
40166
40482
|
});
|
|
@@ -40180,17 +40496,17 @@ ${labelFim}:`;
|
|
|
40180
40496
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
40181
40497
|
const labelInicio = this.gerarLabel();
|
|
40182
40498
|
const labelFim = this.gerarLabel();
|
|
40183
|
-
this.text += `
|
|
40499
|
+
this.text += `
|
|
40184
40500
|
${labelInicio}:`;
|
|
40185
40501
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40186
|
-
this.text += `
|
|
40187
|
-
cmp ${condicao}, #0
|
|
40502
|
+
this.text += `
|
|
40503
|
+
cmp ${condicao}, #0
|
|
40188
40504
|
beq ${labelFim}`;
|
|
40189
40505
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
40190
40506
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
40191
40507
|
}
|
|
40192
|
-
this.text += `
|
|
40193
|
-
b ${labelInicio}
|
|
40508
|
+
this.text += `
|
|
40509
|
+
b ${labelInicio}
|
|
40194
40510
|
${labelFim}:`;
|
|
40195
40511
|
}
|
|
40196
40512
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -40201,10 +40517,10 @@ ${labelFim}:`;
|
|
|
40201
40517
|
const labelProximo = this.gerarLabel();
|
|
40202
40518
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
40203
40519
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
40204
|
-
this.text += `
|
|
40205
|
-
ldr r0, =${valorEscolha}
|
|
40206
|
-
ldr r1, =${valorCaso}
|
|
40207
|
-
cmp r0, r1
|
|
40520
|
+
this.text += `
|
|
40521
|
+
ldr r0, =${valorEscolha}
|
|
40522
|
+
ldr r1, =${valorCaso}
|
|
40523
|
+
cmp r0, r1
|
|
40208
40524
|
bne ${labelProximo}`;
|
|
40209
40525
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
40210
40526
|
caminho.declaracoes.forEach((decl) => {
|
|
@@ -40213,23 +40529,24 @@ ${labelFim}:`;
|
|
|
40213
40529
|
}
|
|
40214
40530
|
});
|
|
40215
40531
|
}
|
|
40216
|
-
this.text += `
|
|
40217
|
-
b ${labelFim}
|
|
40532
|
+
this.text += `
|
|
40533
|
+
b ${labelFim}
|
|
40218
40534
|
${labelProximo}:`;
|
|
40219
40535
|
}
|
|
40220
40536
|
});
|
|
40221
40537
|
}
|
|
40222
|
-
this.text += `
|
|
40538
|
+
this.text += `
|
|
40223
40539
|
${labelFim}:`;
|
|
40224
40540
|
}
|
|
40225
40541
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
40226
|
-
if (declaracao.expressao &&
|
|
40542
|
+
if (declaracao.expressao &&
|
|
40543
|
+
this.dicionarioConstrutos[declaracao.expressao.constructor.name]) {
|
|
40227
40544
|
this.dicionarioConstrutos[declaracao.expressao.constructor.name](declaracao.expressao);
|
|
40228
40545
|
}
|
|
40229
40546
|
}
|
|
40230
40547
|
traduzirDeclaracaoFazer(declaracao) {
|
|
40231
40548
|
const labelInicio = this.gerarLabel();
|
|
40232
|
-
this.text += `
|
|
40549
|
+
this.text += `
|
|
40233
40550
|
${labelInicio}:`;
|
|
40234
40551
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
40235
40552
|
declaracao.caminhoFazer.declaracoes.forEach((decl) => {
|
|
@@ -40240,52 +40557,58 @@ ${labelInicio}:`;
|
|
|
40240
40557
|
}
|
|
40241
40558
|
if (declaracao.condicaoEnquanto) {
|
|
40242
40559
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
40243
|
-
this.text += `
|
|
40244
|
-
cmp ${condicao}, #0
|
|
40560
|
+
this.text += `
|
|
40561
|
+
cmp ${condicao}, #0
|
|
40245
40562
|
bne ${labelInicio}`;
|
|
40246
40563
|
}
|
|
40247
40564
|
}
|
|
40248
40565
|
traduzirDeclaracaoFalhar(declaracao) {
|
|
40249
40566
|
let mensagem = '"Erro"';
|
|
40250
|
-
if (declaracao.explicacao &&
|
|
40567
|
+
if (declaracao.explicacao &&
|
|
40568
|
+
typeof declaracao.explicacao === 'object' &&
|
|
40569
|
+
'constructor' in declaracao.explicacao) {
|
|
40251
40570
|
const explicacao = declaracao.explicacao;
|
|
40252
40571
|
if (explicacao.constructor && this.dicionarioConstrutos[explicacao.constructor.name]) {
|
|
40253
40572
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
40254
40573
|
}
|
|
40255
40574
|
}
|
|
40256
|
-
this.text += `
|
|
40257
|
-
@ Falhar com mensagem: ${mensagem}
|
|
40258
|
-
mov r0, #1
|
|
40259
|
-
mov r7, #1 @ sys_exit
|
|
40575
|
+
this.text += `
|
|
40576
|
+
@ Falhar com mensagem: ${mensagem}
|
|
40577
|
+
mov r0, #1
|
|
40578
|
+
mov r7, #1 @ sys_exit
|
|
40260
40579
|
swi 0`;
|
|
40261
40580
|
}
|
|
40262
40581
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
40263
40582
|
var _a;
|
|
40264
40583
|
const nomeFuncao = ((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'funcao';
|
|
40265
|
-
this.text += `
|
|
40266
|
-
|
|
40267
|
-
${nomeFuncao}:
|
|
40268
|
-
push {fp, lr}
|
|
40584
|
+
this.text += `
|
|
40585
|
+
|
|
40586
|
+
${nomeFuncao}:
|
|
40587
|
+
push {fp, lr}
|
|
40269
40588
|
mov fp, sp`;
|
|
40270
|
-
if (declaracao.funcao &&
|
|
40589
|
+
if (declaracao.funcao &&
|
|
40590
|
+
declaracao.funcao.corpo &&
|
|
40591
|
+
Array.isArray(declaracao.funcao.corpo)) {
|
|
40271
40592
|
declaracao.funcao.corpo.forEach((decl) => {
|
|
40272
40593
|
if (this.dicionarioDeclaracoes[decl.constructor.name]) {
|
|
40273
40594
|
this.dicionarioDeclaracoes[decl.constructor.name](decl);
|
|
40274
40595
|
}
|
|
40275
40596
|
});
|
|
40276
40597
|
}
|
|
40277
|
-
this.text += `
|
|
40278
|
-
mov sp, fp
|
|
40598
|
+
this.text += `
|
|
40599
|
+
mov sp, fp
|
|
40279
40600
|
pop {fp, pc}`;
|
|
40280
40601
|
}
|
|
40281
40602
|
traduzirDeclaracaoImportar(declaracao) {
|
|
40282
|
-
this.text += `
|
|
40603
|
+
this.text += `
|
|
40283
40604
|
@ Importar: ${declaracao.caminho || 'unknown'}`;
|
|
40284
40605
|
}
|
|
40285
40606
|
traduzirDeclaracaoLeia(declaracao) {
|
|
40286
40607
|
var _a;
|
|
40287
40608
|
let nomeVar;
|
|
40288
|
-
if (declaracao.argumentos &&
|
|
40609
|
+
if (declaracao.argumentos &&
|
|
40610
|
+
declaracao.argumentos[0] &&
|
|
40611
|
+
declaracao.argumentos[0] instanceof construtos_1.Variavel) {
|
|
40289
40612
|
nomeVar = (_a = declaracao.argumentos[0].simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
40290
40613
|
}
|
|
40291
40614
|
if (!nomeVar)
|
|
@@ -40295,11 +40618,11 @@ ${nomeFuncao}:
|
|
|
40295
40618
|
this.bss += ` ${varLabel}: .space 256\n`;
|
|
40296
40619
|
this.variaveis.set(nomeVar, varLabel);
|
|
40297
40620
|
}
|
|
40298
|
-
this.text += `
|
|
40299
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
40300
|
-
mov r2, #256
|
|
40301
|
-
mov r0, #0 @ stdin
|
|
40302
|
-
mov r7, #3 @ sys_read
|
|
40621
|
+
this.text += `
|
|
40622
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
40623
|
+
mov r2, #256
|
|
40624
|
+
mov r0, #0 @ stdin
|
|
40625
|
+
mov r7, #3 @ sys_read
|
|
40303
40626
|
swi 0`;
|
|
40304
40627
|
}
|
|
40305
40628
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -40314,12 +40637,12 @@ ${nomeFuncao}:
|
|
|
40314
40637
|
this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
40315
40638
|
}
|
|
40316
40639
|
}
|
|
40317
|
-
this.text += `
|
|
40640
|
+
this.text += `
|
|
40318
40641
|
${labelInicio}:`;
|
|
40319
40642
|
if (declaracao.condicao) {
|
|
40320
40643
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40321
|
-
this.text += `
|
|
40322
|
-
cmp ${condicao}, #0
|
|
40644
|
+
this.text += `
|
|
40645
|
+
cmp ${condicao}, #0
|
|
40323
40646
|
beq ${labelFim}`;
|
|
40324
40647
|
}
|
|
40325
40648
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -40330,8 +40653,8 @@ ${labelInicio}:`;
|
|
|
40330
40653
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
40331
40654
|
}
|
|
40332
40655
|
}
|
|
40333
|
-
this.text += `
|
|
40334
|
-
b ${labelInicio}
|
|
40656
|
+
this.text += `
|
|
40657
|
+
b ${labelInicio}
|
|
40335
40658
|
${labelFim}:`;
|
|
40336
40659
|
}
|
|
40337
40660
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -40347,55 +40670,56 @@ ${labelFim}:`;
|
|
|
40347
40670
|
if (vetor instanceof construtos_1.Vetor) {
|
|
40348
40671
|
tamanhoVetor = vetor.tamanho || 0;
|
|
40349
40672
|
}
|
|
40350
|
-
this.text += `
|
|
40351
|
-
mov r4, #0 @ counter
|
|
40352
|
-
${labelInicio}:
|
|
40353
|
-
cmp r4, #${tamanhoVetor}
|
|
40673
|
+
this.text += `
|
|
40674
|
+
mov r4, #0 @ counter
|
|
40675
|
+
${labelInicio}:
|
|
40676
|
+
cmp r4, #${tamanhoVetor}
|
|
40354
40677
|
bge ${labelFim}`;
|
|
40355
40678
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
40356
40679
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
40357
40680
|
}
|
|
40358
|
-
this.text += `
|
|
40359
|
-
add r4, r4, #1
|
|
40360
|
-
b ${labelInicio}
|
|
40681
|
+
this.text += `
|
|
40682
|
+
add r4, r4, #1
|
|
40683
|
+
b ${labelInicio}
|
|
40361
40684
|
${labelFim}:`;
|
|
40362
40685
|
}
|
|
40363
40686
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
40364
40687
|
if (declaracao.valor) {
|
|
40365
40688
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
40366
|
-
this.text += `
|
|
40689
|
+
this.text += `
|
|
40367
40690
|
ldr r0, =${valor}`;
|
|
40368
40691
|
}
|
|
40369
|
-
this.text += `
|
|
40370
|
-
mov sp, fp
|
|
40692
|
+
this.text += `
|
|
40693
|
+
mov sp, fp
|
|
40371
40694
|
pop {fp, pc}`;
|
|
40372
40695
|
}
|
|
40373
40696
|
traduzirDeclaracaoSe(declaracao) {
|
|
40374
40697
|
const labelSenao = this.gerarLabel();
|
|
40375
40698
|
const labelFim = this.gerarLabel();
|
|
40376
40699
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40377
|
-
this.text += `
|
|
40378
|
-
cmp ${condicao}, #0
|
|
40700
|
+
this.text += `
|
|
40701
|
+
cmp ${condicao}, #0
|
|
40379
40702
|
beq ${labelSenao}`;
|
|
40380
40703
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
40381
40704
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
40382
40705
|
}
|
|
40383
|
-
this.text += `
|
|
40384
|
-
b ${labelFim}
|
|
40706
|
+
this.text += `
|
|
40707
|
+
b ${labelFim}
|
|
40385
40708
|
${labelSenao}:`;
|
|
40386
|
-
if (declaracao.caminhoSenao &&
|
|
40709
|
+
if (declaracao.caminhoSenao &&
|
|
40710
|
+
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
40387
40711
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
40388
40712
|
}
|
|
40389
|
-
this.text += `
|
|
40713
|
+
this.text += `
|
|
40390
40714
|
${labelFim}:`;
|
|
40391
40715
|
}
|
|
40392
40716
|
traduzirDeclaracaoClasse(declaracao) {
|
|
40393
40717
|
var _a;
|
|
40394
|
-
this.text += `
|
|
40718
|
+
this.text += `
|
|
40395
40719
|
@ Classe: ${((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'unknown'}`;
|
|
40396
40720
|
}
|
|
40397
40721
|
traduzirDeclaracaoTente(declaracao) {
|
|
40398
|
-
this.text += `
|
|
40722
|
+
this.text += `
|
|
40399
40723
|
@ Tente-pegue`;
|
|
40400
40724
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
40401
40725
|
declaracao.caminhoTente.forEach((decl) => {
|
|
@@ -40434,9 +40758,9 @@ ${labelFim}:`;
|
|
|
40434
40758
|
}
|
|
40435
40759
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
40436
40760
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
40437
|
-
this.text += `
|
|
40438
|
-
ldr r0, =${valor}
|
|
40439
|
-
ldr r1, =${varLabel}
|
|
40761
|
+
this.text += `
|
|
40762
|
+
ldr r0, =${valor}
|
|
40763
|
+
ldr r1, =${varLabel}
|
|
40440
40764
|
str r0, [r1]`;
|
|
40441
40765
|
}
|
|
40442
40766
|
}
|
|
@@ -40463,20 +40787,20 @@ ${labelFim}:`;
|
|
|
40463
40787
|
// Para ambos linux-arm e android, continuamos usando a convenção
|
|
40464
40788
|
// de syscall Linux ARM (write). Em Android típico, esse binário
|
|
40465
40789
|
// seria executado via adb/Termux, onde essa convenção ainda é válida.
|
|
40466
|
-
this.text += `
|
|
40467
|
-
ldr r1, =${nome_string_literal}
|
|
40468
|
-
mov r2, #${tam_string_literal}
|
|
40469
|
-
mov r0, #1 @ fd stdout
|
|
40470
|
-
mov r7, #4 @ sys_write
|
|
40790
|
+
this.text += `
|
|
40791
|
+
ldr r1, =${nome_string_literal}
|
|
40792
|
+
mov r2, #${tam_string_literal}
|
|
40793
|
+
mov r0, #1 @ fd stdout
|
|
40794
|
+
mov r7, #4 @ sys_write
|
|
40471
40795
|
swi 0`;
|
|
40472
40796
|
}
|
|
40473
40797
|
saidaSistema() {
|
|
40474
40798
|
// Mesmo comentário da função Escreva: usamos sys_exit Linux.
|
|
40475
40799
|
// Em um futuro modo Android "NDK/JNI", esta função deveria
|
|
40476
40800
|
// apenas retornar ao chamador em vez de fazer syscall direta.
|
|
40477
|
-
this.text += `
|
|
40478
|
-
mov r0, #1 @ exit status
|
|
40479
|
-
mov r7, #1 @ sys_exit
|
|
40801
|
+
this.text += `
|
|
40802
|
+
mov r0, #1 @ exit status
|
|
40803
|
+
mov r7, #1 @ sys_exit
|
|
40480
40804
|
swi 0`;
|
|
40481
40805
|
}
|
|
40482
40806
|
traduzir(declaracoes) {
|
|
@@ -40551,13 +40875,14 @@ class TradutorAssemblyX64 {
|
|
|
40551
40875
|
Escreva: this.traduzirDeclaracaoEscreva.bind(this),
|
|
40552
40876
|
};
|
|
40553
40877
|
this.indentacao = 0;
|
|
40554
|
-
this.text = `
|
|
40555
|
-
section .text
|
|
40556
|
-
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
40878
|
+
this.text = `
|
|
40879
|
+
section .text
|
|
40880
|
+
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
40557
40881
|
${this.alvo === 'linux' ? '_start:' : 'main:'}`;
|
|
40558
40882
|
if (this.alvo === 'windows') {
|
|
40559
|
-
this.text =
|
|
40560
|
-
|
|
40883
|
+
this.text =
|
|
40884
|
+
`
|
|
40885
|
+
extern printf
|
|
40561
40886
|
` + this.text;
|
|
40562
40887
|
}
|
|
40563
40888
|
}
|
|
@@ -40619,8 +40944,8 @@ extern printf
|
|
|
40619
40944
|
}
|
|
40620
40945
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
40621
40946
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
40622
|
-
this.text += `
|
|
40623
|
-
mov rax, ${valor}
|
|
40947
|
+
this.text += `
|
|
40948
|
+
mov rax, ${valor}
|
|
40624
40949
|
mov [${nomeVar} + ${indice} * 8], rax`;
|
|
40625
40950
|
}
|
|
40626
40951
|
traduzirConstrutoAtribuir(construto) {
|
|
@@ -40639,8 +40964,8 @@ extern printf
|
|
|
40639
40964
|
this.bss += ` ${varLabel} resq 1\n`;
|
|
40640
40965
|
this.variaveis.set(nomeVar, varLabel);
|
|
40641
40966
|
}
|
|
40642
|
-
this.text += `
|
|
40643
|
-
mov rax, ${valor}
|
|
40967
|
+
this.text += `
|
|
40968
|
+
mov rax, ${valor}
|
|
40644
40969
|
mov [${this.variaveis.get(nomeVar)}], rax`;
|
|
40645
40970
|
}
|
|
40646
40971
|
traduzirConstrutoBinario(construto) {
|
|
@@ -40648,35 +40973,35 @@ extern printf
|
|
|
40648
40973
|
const direita = this.dicionarioConstrutos[construto.direita.constructor.name](construto.direita);
|
|
40649
40974
|
const operador = construto.operador.lexema;
|
|
40650
40975
|
const reg = this.obterRegistrador();
|
|
40651
|
-
this.text += `
|
|
40652
|
-
mov rax, ${esquerda}
|
|
40976
|
+
this.text += `
|
|
40977
|
+
mov rax, ${esquerda}
|
|
40653
40978
|
mov ${reg}, ${direita}`;
|
|
40654
40979
|
switch (operador) {
|
|
40655
40980
|
case '+':
|
|
40656
|
-
this.text += `
|
|
40981
|
+
this.text += `
|
|
40657
40982
|
add rax, ${reg}`;
|
|
40658
40983
|
break;
|
|
40659
40984
|
case '-':
|
|
40660
|
-
this.text += `
|
|
40985
|
+
this.text += `
|
|
40661
40986
|
sub rax, ${reg}`;
|
|
40662
40987
|
break;
|
|
40663
40988
|
case '*':
|
|
40664
|
-
this.text += `
|
|
40989
|
+
this.text += `
|
|
40665
40990
|
imul rax, ${reg}`;
|
|
40666
40991
|
break;
|
|
40667
40992
|
case '/':
|
|
40668
|
-
this.text += `
|
|
40669
|
-
xor rdx, rdx
|
|
40993
|
+
this.text += `
|
|
40994
|
+
xor rdx, rdx
|
|
40670
40995
|
idiv ${reg}`;
|
|
40671
40996
|
break;
|
|
40672
40997
|
case '%':
|
|
40673
|
-
this.text += `
|
|
40674
|
-
xor rdx, rdx
|
|
40675
|
-
idiv ${reg}
|
|
40998
|
+
this.text += `
|
|
40999
|
+
xor rdx, rdx
|
|
41000
|
+
idiv ${reg}
|
|
40676
41001
|
mov rax, rdx`;
|
|
40677
41002
|
break;
|
|
40678
41003
|
default:
|
|
40679
|
-
this.text += `
|
|
41004
|
+
this.text += `
|
|
40680
41005
|
; Operador ${operador} não implementado`;
|
|
40681
41006
|
}
|
|
40682
41007
|
this.liberarRegistrador(reg);
|
|
@@ -40695,28 +41020,28 @@ extern printf
|
|
|
40695
41020
|
construto.argumentos.forEach((arg, index) => {
|
|
40696
41021
|
if (index < registrosArgs.length) {
|
|
40697
41022
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
40698
|
-
this.text += `
|
|
41023
|
+
this.text += `
|
|
40699
41024
|
mov ${registrosArgs[index]}, ${valorArg}`;
|
|
40700
41025
|
}
|
|
40701
41026
|
else {
|
|
40702
41027
|
// TODO: push extra args on stack according to target ABI
|
|
40703
41028
|
}
|
|
40704
41029
|
});
|
|
40705
|
-
this.text += `
|
|
41030
|
+
this.text += `
|
|
40706
41031
|
call ${nomeFuncao}`;
|
|
40707
41032
|
}
|
|
40708
41033
|
traduzirConstrutoDefinirValor(construto) {
|
|
40709
41034
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
40710
41035
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
40711
|
-
this.text += `
|
|
40712
|
-
mov rax, ${valor}
|
|
41036
|
+
this.text += `
|
|
41037
|
+
mov rax, ${valor}
|
|
40713
41038
|
mov [${objeto}], rax`;
|
|
40714
41039
|
}
|
|
40715
41040
|
traduzirFuncaoConstruto(construto) {
|
|
40716
41041
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
40717
|
-
this.text += `
|
|
40718
|
-
${labelFuncao}:
|
|
40719
|
-
push rbp
|
|
41042
|
+
this.text += `
|
|
41043
|
+
${labelFuncao}:
|
|
41044
|
+
push rbp
|
|
40720
41045
|
mov rbp, rsp`;
|
|
40721
41046
|
// Traduzir corpo da função
|
|
40722
41047
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -40726,8 +41051,8 @@ ${labelFuncao}:
|
|
|
40726
41051
|
}
|
|
40727
41052
|
});
|
|
40728
41053
|
}
|
|
40729
|
-
this.text += `
|
|
40730
|
-
pop rbp
|
|
41054
|
+
this.text += `
|
|
41055
|
+
pop rbp
|
|
40731
41056
|
ret`;
|
|
40732
41057
|
}
|
|
40733
41058
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -40742,29 +41067,29 @@ ${labelFuncao}:
|
|
|
40742
41067
|
const operador = construto.operador.lexema;
|
|
40743
41068
|
const labelVerdadeiro = this.gerarLabel();
|
|
40744
41069
|
const labelFim = this.gerarLabel();
|
|
40745
|
-
this.text += `
|
|
40746
|
-
mov rax, ${esquerda}
|
|
41070
|
+
this.text += `
|
|
41071
|
+
mov rax, ${esquerda}
|
|
40747
41072
|
cmp rax, 0`;
|
|
40748
41073
|
if (operador === 'e' || operador === '&&') {
|
|
40749
|
-
this.text += `
|
|
40750
|
-
je ${labelFim}
|
|
40751
|
-
mov rax, ${direita}
|
|
40752
|
-
cmp rax, 0
|
|
40753
|
-
je ${labelFim}
|
|
40754
|
-
${labelVerdadeiro}:
|
|
40755
|
-
mov rax, 1
|
|
41074
|
+
this.text += `
|
|
41075
|
+
je ${labelFim}
|
|
41076
|
+
mov rax, ${direita}
|
|
41077
|
+
cmp rax, 0
|
|
41078
|
+
je ${labelFim}
|
|
41079
|
+
${labelVerdadeiro}:
|
|
41080
|
+
mov rax, 1
|
|
40756
41081
|
${labelFim}:`;
|
|
40757
41082
|
}
|
|
40758
41083
|
else if (operador === 'ou' || operador === '||') {
|
|
40759
|
-
this.text += `
|
|
40760
|
-
jne ${labelVerdadeiro}
|
|
40761
|
-
mov rax, ${direita}
|
|
40762
|
-
cmp rax, 0
|
|
40763
|
-
jne ${labelVerdadeiro}
|
|
40764
|
-
mov rax, 0
|
|
40765
|
-
jmp ${labelFim}
|
|
40766
|
-
${labelVerdadeiro}:
|
|
40767
|
-
mov rax, 1
|
|
41084
|
+
this.text += `
|
|
41085
|
+
jne ${labelVerdadeiro}
|
|
41086
|
+
mov rax, ${direita}
|
|
41087
|
+
cmp rax, 0
|
|
41088
|
+
jne ${labelVerdadeiro}
|
|
41089
|
+
mov rax, 0
|
|
41090
|
+
jmp ${labelFim}
|
|
41091
|
+
${labelVerdadeiro}:
|
|
41092
|
+
mov rax, 1
|
|
40768
41093
|
${labelFim}:`;
|
|
40769
41094
|
}
|
|
40770
41095
|
return 'rax';
|
|
@@ -40777,16 +41102,16 @@ ${labelFim}:`;
|
|
|
40777
41102
|
traduzirConstrutoUnario(construto) {
|
|
40778
41103
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
40779
41104
|
const operador = construto.operador.lexema;
|
|
40780
|
-
this.text += `
|
|
41105
|
+
this.text += `
|
|
40781
41106
|
mov rax, ${operando}`;
|
|
40782
41107
|
if (operador === '-') {
|
|
40783
|
-
this.text += `
|
|
41108
|
+
this.text += `
|
|
40784
41109
|
neg rax`;
|
|
40785
41110
|
}
|
|
40786
41111
|
else if (operador === '!' || operador === 'nao') {
|
|
40787
|
-
this.text += `
|
|
40788
|
-
cmp rax, 0
|
|
40789
|
-
sete al
|
|
41112
|
+
this.text += `
|
|
41113
|
+
cmp rax, 0
|
|
41114
|
+
sete al
|
|
40790
41115
|
movzx rax, al`;
|
|
40791
41116
|
}
|
|
40792
41117
|
return 'rax';
|
|
@@ -40808,8 +41133,8 @@ ${labelFim}:`;
|
|
|
40808
41133
|
construto.valores.forEach((valor, index) => {
|
|
40809
41134
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
40810
41135
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
40811
|
-
this.text += `
|
|
40812
|
-
mov rax, ${valorTraduzido}
|
|
41136
|
+
this.text += `
|
|
41137
|
+
mov rax, ${valorTraduzido}
|
|
40813
41138
|
mov [${labelVetor} + ${index * 8}], rax`;
|
|
40814
41139
|
}
|
|
40815
41140
|
});
|
|
@@ -40829,17 +41154,17 @@ ${labelFim}:`;
|
|
|
40829
41154
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
40830
41155
|
const labelInicio = this.gerarLabel();
|
|
40831
41156
|
const labelFim = this.gerarLabel();
|
|
40832
|
-
this.text += `
|
|
41157
|
+
this.text += `
|
|
40833
41158
|
${labelInicio}:`;
|
|
40834
41159
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40835
|
-
this.text += `
|
|
40836
|
-
cmp ${condicao}, 0
|
|
41160
|
+
this.text += `
|
|
41161
|
+
cmp ${condicao}, 0
|
|
40837
41162
|
je ${labelFim}`;
|
|
40838
41163
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
40839
41164
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
40840
41165
|
}
|
|
40841
|
-
this.text += `
|
|
40842
|
-
jmp ${labelInicio}
|
|
41166
|
+
this.text += `
|
|
41167
|
+
jmp ${labelInicio}
|
|
40843
41168
|
${labelFim}:`;
|
|
40844
41169
|
}
|
|
40845
41170
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -40850,9 +41175,9 @@ ${labelFim}:`;
|
|
|
40850
41175
|
const labelProximo = this.gerarLabel();
|
|
40851
41176
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
40852
41177
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
40853
|
-
this.text += `
|
|
40854
|
-
mov rax, ${valorEscolha}
|
|
40855
|
-
cmp rax, ${valorCaso}
|
|
41178
|
+
this.text += `
|
|
41179
|
+
mov rax, ${valorEscolha}
|
|
41180
|
+
cmp rax, ${valorCaso}
|
|
40856
41181
|
jne ${labelProximo}`;
|
|
40857
41182
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
40858
41183
|
caminho.declaracoes.forEach((decl) => {
|
|
@@ -40861,23 +41186,24 @@ ${labelFim}:`;
|
|
|
40861
41186
|
}
|
|
40862
41187
|
});
|
|
40863
41188
|
}
|
|
40864
|
-
this.text += `
|
|
40865
|
-
jmp ${labelFim}
|
|
41189
|
+
this.text += `
|
|
41190
|
+
jmp ${labelFim}
|
|
40866
41191
|
${labelProximo}:`;
|
|
40867
41192
|
}
|
|
40868
41193
|
});
|
|
40869
41194
|
}
|
|
40870
|
-
this.text += `
|
|
41195
|
+
this.text += `
|
|
40871
41196
|
${labelFim}:`;
|
|
40872
41197
|
}
|
|
40873
41198
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
40874
|
-
if (declaracao.expressao &&
|
|
41199
|
+
if (declaracao.expressao &&
|
|
41200
|
+
this.dicionarioConstrutos[declaracao.expressao.constructor.name]) {
|
|
40875
41201
|
this.dicionarioConstrutos[declaracao.expressao.constructor.name](declaracao.expressao);
|
|
40876
41202
|
}
|
|
40877
41203
|
}
|
|
40878
41204
|
traduzirDeclaracaoFazer(declaracao) {
|
|
40879
41205
|
const labelInicio = this.gerarLabel();
|
|
40880
|
-
this.text += `
|
|
41206
|
+
this.text += `
|
|
40881
41207
|
${labelInicio}:`;
|
|
40882
41208
|
// Em Delégua, fazer-enquanto tem caminhoFazer que é um Bloco
|
|
40883
41209
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
@@ -40889,60 +41215,66 @@ ${labelInicio}:`;
|
|
|
40889
41215
|
}
|
|
40890
41216
|
if (declaracao.condicaoEnquanto) {
|
|
40891
41217
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
40892
|
-
this.text += `
|
|
40893
|
-
cmp ${condicao}, 0
|
|
41218
|
+
this.text += `
|
|
41219
|
+
cmp ${condicao}, 0
|
|
40894
41220
|
jne ${labelInicio}`;
|
|
40895
41221
|
}
|
|
40896
41222
|
}
|
|
40897
41223
|
traduzirDeclaracaoFalhar(declaracao) {
|
|
40898
41224
|
let mensagem = '"Erro"';
|
|
40899
|
-
if (declaracao.explicacao &&
|
|
41225
|
+
if (declaracao.explicacao &&
|
|
41226
|
+
typeof declaracao.explicacao === 'object' &&
|
|
41227
|
+
'constructor' in declaracao.explicacao) {
|
|
40900
41228
|
const explicacao = declaracao.explicacao;
|
|
40901
41229
|
if (explicacao.constructor && this.dicionarioConstrutos[explicacao.constructor.name]) {
|
|
40902
41230
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
40903
41231
|
}
|
|
40904
41232
|
}
|
|
40905
41233
|
if (this.alvo === 'linux') {
|
|
40906
|
-
this.text += `
|
|
40907
|
-
; Falhar com mensagem: ${mensagem}
|
|
40908
|
-
mov eax, 1
|
|
40909
|
-
mov ebx, 1
|
|
41234
|
+
this.text += `
|
|
41235
|
+
; Falhar com mensagem: ${mensagem}
|
|
41236
|
+
mov eax, 1
|
|
41237
|
+
mov ebx, 1
|
|
40910
41238
|
int 0x80`;
|
|
40911
41239
|
}
|
|
40912
41240
|
else {
|
|
40913
|
-
this.text += `
|
|
40914
|
-
; Falhar com mensagem: ${mensagem}
|
|
40915
|
-
mov eax, 1
|
|
41241
|
+
this.text += `
|
|
41242
|
+
; Falhar com mensagem: ${mensagem}
|
|
41243
|
+
mov eax, 1
|
|
40916
41244
|
ret`;
|
|
40917
41245
|
}
|
|
40918
41246
|
}
|
|
40919
41247
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
40920
41248
|
var _a;
|
|
40921
41249
|
const nomeFuncao = ((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'funcao';
|
|
40922
|
-
this.text += `
|
|
40923
|
-
${nomeFuncao}:
|
|
40924
|
-
push rbp
|
|
41250
|
+
this.text += `
|
|
41251
|
+
${nomeFuncao}:
|
|
41252
|
+
push rbp
|
|
40925
41253
|
mov rbp, rsp`;
|
|
40926
|
-
if (declaracao.funcao &&
|
|
41254
|
+
if (declaracao.funcao &&
|
|
41255
|
+
declaracao.funcao.corpo &&
|
|
41256
|
+
Array.isArray(declaracao.funcao.corpo)) {
|
|
40927
41257
|
declaracao.funcao.corpo.forEach((decl) => {
|
|
40928
41258
|
if (this.dicionarioDeclaracoes[decl.constructor.name]) {
|
|
40929
41259
|
this.dicionarioDeclaracoes[decl.constructor.name](decl);
|
|
40930
41260
|
}
|
|
40931
41261
|
});
|
|
40932
41262
|
}
|
|
40933
|
-
this.text += `
|
|
40934
|
-
pop rbp
|
|
41263
|
+
this.text += `
|
|
41264
|
+
pop rbp
|
|
40935
41265
|
ret`;
|
|
40936
41266
|
}
|
|
40937
41267
|
traduzirDeclaracaoImportar(declaracao) {
|
|
40938
41268
|
// Importação é tratada em tempo de linkagem
|
|
40939
|
-
this.text += `
|
|
41269
|
+
this.text += `
|
|
40940
41270
|
; Importar: ${declaracao.caminho || 'unknown'}`;
|
|
40941
41271
|
}
|
|
40942
41272
|
traduzirDeclaracaoLeia(declaracao) {
|
|
40943
41273
|
var _a;
|
|
40944
41274
|
let nomeVar;
|
|
40945
|
-
if (declaracao.argumentos &&
|
|
41275
|
+
if (declaracao.argumentos &&
|
|
41276
|
+
declaracao.argumentos[0] &&
|
|
41277
|
+
declaracao.argumentos[0] instanceof construtos_1.Variavel) {
|
|
40946
41278
|
nomeVar = (_a = declaracao.argumentos[0].simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
40947
41279
|
}
|
|
40948
41280
|
if (!nomeVar)
|
|
@@ -40952,11 +41284,11 @@ ${nomeFuncao}:
|
|
|
40952
41284
|
this.bss += ` ${varLabel} resb 256\n`;
|
|
40953
41285
|
this.variaveis.set(nomeVar, varLabel);
|
|
40954
41286
|
}
|
|
40955
|
-
this.text += `
|
|
40956
|
-
mov eax, 3
|
|
40957
|
-
mov ebx, 0
|
|
40958
|
-
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
40959
|
-
mov edx, 256
|
|
41287
|
+
this.text += `
|
|
41288
|
+
mov eax, 3
|
|
41289
|
+
mov ebx, 0
|
|
41290
|
+
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
41291
|
+
mov edx, 256
|
|
40960
41292
|
int 0x80`;
|
|
40961
41293
|
}
|
|
40962
41294
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -40972,12 +41304,12 @@ ${nomeFuncao}:
|
|
|
40972
41304
|
this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
40973
41305
|
}
|
|
40974
41306
|
}
|
|
40975
|
-
this.text += `
|
|
41307
|
+
this.text += `
|
|
40976
41308
|
${labelInicio}:`;
|
|
40977
41309
|
if (declaracao.condicao) {
|
|
40978
41310
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40979
|
-
this.text += `
|
|
40980
|
-
cmp ${condicao}, 0
|
|
41311
|
+
this.text += `
|
|
41312
|
+
cmp ${condicao}, 0
|
|
40981
41313
|
je ${labelFim}`;
|
|
40982
41314
|
}
|
|
40983
41315
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -40988,8 +41320,8 @@ ${labelInicio}:`;
|
|
|
40988
41320
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
40989
41321
|
}
|
|
40990
41322
|
}
|
|
40991
|
-
this.text += `
|
|
40992
|
-
jmp ${labelInicio}
|
|
41323
|
+
this.text += `
|
|
41324
|
+
jmp ${labelInicio}
|
|
40993
41325
|
${labelFim}:`;
|
|
40994
41326
|
}
|
|
40995
41327
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -41005,57 +41337,58 @@ ${labelFim}:`;
|
|
|
41005
41337
|
if (vetor instanceof construtos_1.Vetor) {
|
|
41006
41338
|
tamanhoVetor = vetor.tamanho || 0;
|
|
41007
41339
|
}
|
|
41008
|
-
this.text += `
|
|
41009
|
-
xor rcx, rcx
|
|
41010
|
-
${labelInicio}:
|
|
41011
|
-
cmp rcx, ${tamanhoVetor}
|
|
41340
|
+
this.text += `
|
|
41341
|
+
xor rcx, rcx
|
|
41342
|
+
${labelInicio}:
|
|
41343
|
+
cmp rcx, ${tamanhoVetor}
|
|
41012
41344
|
jge ${labelFim}`;
|
|
41013
41345
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
41014
41346
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
41015
41347
|
}
|
|
41016
|
-
this.text += `
|
|
41017
|
-
inc rcx
|
|
41018
|
-
jmp ${labelInicio}
|
|
41348
|
+
this.text += `
|
|
41349
|
+
inc rcx
|
|
41350
|
+
jmp ${labelInicio}
|
|
41019
41351
|
${labelFim}:`;
|
|
41020
41352
|
}
|
|
41021
41353
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
41022
41354
|
if (declaracao.valor) {
|
|
41023
41355
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
41024
|
-
this.text += `
|
|
41356
|
+
this.text += `
|
|
41025
41357
|
mov rax, ${valor}`;
|
|
41026
41358
|
}
|
|
41027
|
-
this.text += `
|
|
41028
|
-
pop rbp
|
|
41359
|
+
this.text += `
|
|
41360
|
+
pop rbp
|
|
41029
41361
|
ret`;
|
|
41030
41362
|
}
|
|
41031
41363
|
traduzirDeclaracaoSe(declaracao) {
|
|
41032
41364
|
const labelSenao = this.gerarLabel();
|
|
41033
41365
|
const labelFim = this.gerarLabel();
|
|
41034
41366
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
41035
|
-
this.text += `
|
|
41036
|
-
cmp ${condicao}, 0
|
|
41367
|
+
this.text += `
|
|
41368
|
+
cmp ${condicao}, 0
|
|
41037
41369
|
je ${labelSenao}`;
|
|
41038
41370
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
41039
41371
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
41040
41372
|
}
|
|
41041
|
-
this.text += `
|
|
41042
|
-
jmp ${labelFim}
|
|
41373
|
+
this.text += `
|
|
41374
|
+
jmp ${labelFim}
|
|
41043
41375
|
${labelSenao}:`;
|
|
41044
|
-
if (declaracao.caminhoSenao &&
|
|
41376
|
+
if (declaracao.caminhoSenao &&
|
|
41377
|
+
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
41045
41378
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
41046
41379
|
}
|
|
41047
|
-
this.text += `
|
|
41380
|
+
this.text += `
|
|
41048
41381
|
${labelFim}:`;
|
|
41049
41382
|
}
|
|
41050
41383
|
traduzirDeclaracaoClasse(declaracao) {
|
|
41051
41384
|
var _a;
|
|
41052
41385
|
// Classes em assembly são complexas - implementação básica
|
|
41053
|
-
this.text += `
|
|
41386
|
+
this.text += `
|
|
41054
41387
|
; Classe: ${((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'unknown'}`;
|
|
41055
41388
|
}
|
|
41056
41389
|
traduzirDeclaracaoTente(declaracao) {
|
|
41057
41390
|
// Try-catch em assembly requer handler complexo
|
|
41058
|
-
this.text += `
|
|
41391
|
+
this.text += `
|
|
41059
41392
|
; Tente-pegue`;
|
|
41060
41393
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
41061
41394
|
declaracao.caminhoTente.forEach((decl) => {
|
|
@@ -41094,8 +41427,8 @@ ${labelFim}:`;
|
|
|
41094
41427
|
}
|
|
41095
41428
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
41096
41429
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
41097
|
-
this.text += `
|
|
41098
|
-
mov rax, ${valor}
|
|
41430
|
+
this.text += `
|
|
41431
|
+
mov rax, ${valor}
|
|
41099
41432
|
mov [${varLabel}], rax`;
|
|
41100
41433
|
}
|
|
41101
41434
|
}
|
|
@@ -41118,32 +41451,32 @@ ${labelFim}:`;
|
|
|
41118
41451
|
tam_string_literal = this.criaTamanhoNaMemoriaReferenteAVar(nome_string_literal);
|
|
41119
41452
|
}
|
|
41120
41453
|
if (this.alvo === 'linux') {
|
|
41121
|
-
this.text += `
|
|
41122
|
-
mov edx, ${tam_string_literal}
|
|
41123
|
-
mov ecx, ${nome_string_literal}
|
|
41124
|
-
mov ebx, 1 ; fd stdout
|
|
41125
|
-
mov eax, 4 ; sys_write
|
|
41454
|
+
this.text += `
|
|
41455
|
+
mov edx, ${tam_string_literal}
|
|
41456
|
+
mov ecx, ${nome_string_literal}
|
|
41457
|
+
mov ebx, 1 ; fd stdout
|
|
41458
|
+
mov eax, 4 ; sys_write
|
|
41126
41459
|
int 0x80`;
|
|
41127
41460
|
}
|
|
41128
41461
|
else {
|
|
41129
41462
|
// Windows: prototype `extern printf` and follow Win64 calling convention
|
|
41130
41463
|
// RCX = format pointer; here we use the literal directly as a C string
|
|
41131
|
-
this.text += `
|
|
41132
|
-
lea rcx, [rel ${nome_string_literal}]
|
|
41464
|
+
this.text += `
|
|
41465
|
+
lea rcx, [rel ${nome_string_literal}]
|
|
41133
41466
|
call printf`;
|
|
41134
41467
|
}
|
|
41135
41468
|
}
|
|
41136
41469
|
saidaSistema() {
|
|
41137
41470
|
if (this.alvo === 'linux') {
|
|
41138
|
-
this.text += `
|
|
41139
|
-
mov eax, 1 ; sys_exit
|
|
41140
|
-
xor ebx, ebx ; status 0
|
|
41471
|
+
this.text += `
|
|
41472
|
+
mov eax, 1 ; sys_exit
|
|
41473
|
+
xor ebx, ebx ; status 0
|
|
41141
41474
|
int 0x80`;
|
|
41142
41475
|
}
|
|
41143
41476
|
else {
|
|
41144
41477
|
// Windows: return from main with 0 in EAX
|
|
41145
|
-
this.text += `
|
|
41146
|
-
xor eax, eax
|
|
41478
|
+
this.text += `
|
|
41479
|
+
xor eax, eax
|
|
41147
41480
|
ret`;
|
|
41148
41481
|
}
|
|
41149
41482
|
}
|
|
@@ -41611,7 +41944,7 @@ class TradutorAssemblyScript {
|
|
|
41611
41944
|
return resultado;
|
|
41612
41945
|
}
|
|
41613
41946
|
traduzirDeclaracaoVarMultiplo(declaracaoVarMultiplo) {
|
|
41614
|
-
const variaveis = declaracaoVarMultiplo.simbolos.map(s => s.lexema).join(', ');
|
|
41947
|
+
const variaveis = declaracaoVarMultiplo.simbolos.map((s) => s.lexema).join(', ');
|
|
41615
41948
|
let resultado = 'let ';
|
|
41616
41949
|
resultado += variaveis;
|
|
41617
41950
|
resultado += this.resolveTipoDeclaracaoVarEContante(declaracaoVarMultiplo.tipo);
|
|
@@ -41630,7 +41963,7 @@ class TradutorAssemblyScript {
|
|
|
41630
41963
|
return resultado;
|
|
41631
41964
|
}
|
|
41632
41965
|
traduzirDeclaracaoConstMultiplo(declaracaoConstMultiplo) {
|
|
41633
|
-
const constantes = declaracaoConstMultiplo.simbolos.map(s => s.lexema).join(', ');
|
|
41966
|
+
const constantes = declaracaoConstMultiplo.simbolos.map((s) => s.lexema).join(', ');
|
|
41634
41967
|
let resultado = 'const ';
|
|
41635
41968
|
resultado += constantes;
|
|
41636
41969
|
resultado += this.resolveTipoDeclaracaoVarEContante(declaracaoConstMultiplo.tipo);
|
|
@@ -41785,7 +42118,9 @@ class TradutorAssemblyScript {
|
|
|
41785
42118
|
const declaracoesCorpo = corpoBloco.declaracoes || [];
|
|
41786
42119
|
let resultadoCorpo = '{\n';
|
|
41787
42120
|
this.indentacao += 4;
|
|
41788
|
-
resultadoCorpo +=
|
|
42121
|
+
resultadoCorpo +=
|
|
42122
|
+
' '.repeat(this.indentacao) +
|
|
42123
|
+
`const ${nomeVariavel} = ${nomeVetor}[__i_${nomeVariavel}];\n`;
|
|
41789
42124
|
for (const declaracaoOuConstruto of declaracoesCorpo) {
|
|
41790
42125
|
resultadoCorpo += ' '.repeat(this.indentacao);
|
|
41791
42126
|
const nomeConstrutor = declaracaoOuConstruto.constructor.name;
|
|
@@ -42006,7 +42341,9 @@ class TradutorAssemblyScript {
|
|
|
42006
42341
|
if (typeof chave === 'string') {
|
|
42007
42342
|
chaveStr = `"${chave}"`;
|
|
42008
42343
|
}
|
|
42009
|
-
else if (chave &&
|
|
42344
|
+
else if (chave &&
|
|
42345
|
+
chave.constructor &&
|
|
42346
|
+
this.dicionarioConstrutos[chave.constructor.name]) {
|
|
42010
42347
|
// Se for um Construto, traduzi-lo
|
|
42011
42348
|
chaveStr = this.dicionarioConstrutos[chave.constructor.name](chave);
|
|
42012
42349
|
}
|
|
@@ -42101,7 +42438,7 @@ class TradutorAssemblyScript {
|
|
|
42101
42438
|
return `[${primeiro}, ${segundo}, ${terceiro}, ${quarto}, ${quinto}, ${sexto}, ${setimo}, ${oitavo}, ${nono}, ${decimo}]`;
|
|
42102
42439
|
}
|
|
42103
42440
|
traduzirConstrutoTuplaN(tuplaN) {
|
|
42104
|
-
const elementos = tuplaN.elementos.map(elemento => this.dicionarioConstrutos[elemento.constructor.name](elemento));
|
|
42441
|
+
const elementos = tuplaN.elementos.map((elemento) => this.dicionarioConstrutos[elemento.constructor.name](elemento));
|
|
42105
42442
|
return `[${elementos.join(', ')}]`;
|
|
42106
42443
|
}
|
|
42107
42444
|
traduzirConstrutoSeTernario(seTernario) {
|
|
@@ -42180,7 +42517,7 @@ class TradutorAssemblyScript {
|
|
|
42180
42517
|
// Check if this is a native library function call
|
|
42181
42518
|
if (chamada.entidadeChamada instanceof construtos_1.Variavel) {
|
|
42182
42519
|
const nomeVariavel = chamada.entidadeChamada.simbolo.lexema;
|
|
42183
|
-
const argumentosTexto = chamada.argumentos.map(arg => this.dicionarioConstrutos[arg.constructor.name](arg));
|
|
42520
|
+
const argumentosTexto = chamada.argumentos.map((arg) => this.dicionarioConstrutos[arg.constructor.name](arg));
|
|
42184
42521
|
const funcaoNativa = this.traduzirFuncaoNativaGlobal(nomeVariavel, argumentosTexto);
|
|
42185
42522
|
if (funcaoNativa) {
|
|
42186
42523
|
return funcaoNativa;
|
|
@@ -42527,7 +42864,7 @@ class TradutorElixir {
|
|
|
42527
42864
|
async extrairCamposStruct(declaracao) {
|
|
42528
42865
|
const campos = new Set();
|
|
42529
42866
|
// Procurar pelo construtor
|
|
42530
|
-
const construtor = declaracao.metodos.find(m => m.simbolo.lexema === 'construtor' || m.simbolo.lexema === 'inicializar');
|
|
42867
|
+
const construtor = declaracao.metodos.find((m) => m.simbolo.lexema === 'construtor' || m.simbolo.lexema === 'inicializar');
|
|
42531
42868
|
if (!construtor) {
|
|
42532
42869
|
return [];
|
|
42533
42870
|
}
|
|
@@ -42536,7 +42873,7 @@ class TradutorElixir {
|
|
|
42536
42873
|
this.extrairCamposDeDeclaracao(declaracaoCorpo, campos);
|
|
42537
42874
|
}
|
|
42538
42875
|
// Converter para atoms do Elixir
|
|
42539
|
-
return Array.from(campos).map(c => `:${this.converterIdentificador(c)}`);
|
|
42876
|
+
return Array.from(campos).map((c) => `:${this.converterIdentificador(c)}`);
|
|
42540
42877
|
}
|
|
42541
42878
|
/**
|
|
42542
42879
|
* Extrai campos de uma declaração recursivamente
|
|
@@ -42578,7 +42915,7 @@ class TradutorElixir {
|
|
|
42578
42915
|
// Construtor vira função new/N
|
|
42579
42916
|
if (metodo.simbolo.lexema === 'construtor' || metodo.simbolo.lexema === 'inicializar') {
|
|
42580
42917
|
resultado += `def new(`;
|
|
42581
|
-
const parametros = metodo.funcao.parametros.map(p => this.converterIdentificador(p.nome.lexema));
|
|
42918
|
+
const parametros = metodo.funcao.parametros.map((p) => this.converterIdentificador(p.nome.lexema));
|
|
42582
42919
|
resultado += parametros.join(', ');
|
|
42583
42920
|
resultado += ') do\n';
|
|
42584
42921
|
this.aumentarIndentacao();
|
|
@@ -42596,7 +42933,7 @@ class TradutorElixir {
|
|
|
42596
42933
|
resultado += `def ${nomeMetodo}(`;
|
|
42597
42934
|
const nomeParametroStruct = this.converterIdentificador(nomeModulo.toLowerCase());
|
|
42598
42935
|
this.nomeParametroStruct = nomeParametroStruct;
|
|
42599
|
-
const parametros = [nomeParametroStruct].concat(metodo.funcao.parametros.map(p => this.converterIdentificador(p.nome.lexema)));
|
|
42936
|
+
const parametros = [nomeParametroStruct].concat(metodo.funcao.parametros.map((p) => this.converterIdentificador(p.nome.lexema)));
|
|
42600
42937
|
resultado += parametros.join(', ');
|
|
42601
42938
|
resultado += ') do\n';
|
|
42602
42939
|
this.aumentarIndentacao();
|
|
@@ -42686,7 +43023,7 @@ class TradutorElixir {
|
|
|
42686
43023
|
let resultado = this.adicionarIndentacao();
|
|
42687
43024
|
resultado += `def ${nomeFuncao}(`;
|
|
42688
43025
|
// Parâmetros
|
|
42689
|
-
const parametros = declaracao.funcao.parametros.map(p => this.converterIdentificador(p.nome.lexema));
|
|
43026
|
+
const parametros = declaracao.funcao.parametros.map((p) => this.converterIdentificador(p.nome.lexema));
|
|
42690
43027
|
resultado += parametros.join(', ');
|
|
42691
43028
|
resultado += ') do\n';
|
|
42692
43029
|
// Corpo
|
|
@@ -42963,7 +43300,9 @@ class TradutorElixir {
|
|
|
42963
43300
|
case 'ordenar':
|
|
42964
43301
|
return `Enum.sort(${objeto})`;
|
|
42965
43302
|
case 'juntar':
|
|
42966
|
-
return argumentos.length > 0
|
|
43303
|
+
return argumentos.length > 0
|
|
43304
|
+
? `Enum.join(${objeto}, ${argumentos[0]})`
|
|
43305
|
+
: `Enum.join(${objeto})`;
|
|
42967
43306
|
case 'fatiar':
|
|
42968
43307
|
if (argumentos.length >= 2) {
|
|
42969
43308
|
return `Enum.slice(${objeto}, ${argumentos[0]}, ${argumentos[1]})`;
|
|
@@ -43102,7 +43441,7 @@ class TradutorElixir {
|
|
|
43102
43441
|
async visitarExpressaoFuncaoConstruto(expressao) {
|
|
43103
43442
|
let resultado = 'fn ';
|
|
43104
43443
|
// Parâmetros
|
|
43105
|
-
const parametros = expressao.parametros.map(p => this.converterIdentificador(p.nome.lexema));
|
|
43444
|
+
const parametros = expressao.parametros.map((p) => this.converterIdentificador(p.nome.lexema));
|
|
43106
43445
|
resultado += parametros.join(', ');
|
|
43107
43446
|
resultado += ' ->';
|
|
43108
43447
|
// Corpo - se for uma única expressão, inline; se for bloco, multi-linha
|
|
@@ -43868,7 +44207,8 @@ class TradutorJavaScript {
|
|
|
43868
44207
|
if (argumento instanceof construtos_1.Variavel) {
|
|
43869
44208
|
return argumento.simbolo.lexema;
|
|
43870
44209
|
}
|
|
43871
|
-
if (argumento instanceof construtos_1.ReferenciaFuncao ||
|
|
44210
|
+
if (argumento instanceof construtos_1.ReferenciaFuncao ||
|
|
44211
|
+
argumento instanceof construtos_1.ArgumentoReferenciaFuncao) {
|
|
43872
44212
|
return argumento.simboloFuncao.lexema;
|
|
43873
44213
|
}
|
|
43874
44214
|
return (_c = (_b = (_a = this.dicionarioConstrutos)[argumento.constructor.name]) === null || _b === void 0 ? void 0 : _b.call(_a, argumento)) !== null && _c !== void 0 ? _c : '';
|
|
@@ -44109,7 +44449,7 @@ class TradutorMermaidJs {
|
|
|
44109
44449
|
var _a, _b;
|
|
44110
44450
|
const nomeClasse = declaracao.simbolo.lexema;
|
|
44111
44451
|
const superClasse = declaracao.superClasse
|
|
44112
|
-
? ((
|
|
44452
|
+
? ((_a = declaracao.superClasse.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || ((_b = declaracao.superClasse.nome) === null || _b === void 0 ? void 0 : _b.lexema)
|
|
44113
44453
|
: undefined;
|
|
44114
44454
|
const linha = declaracao.linha;
|
|
44115
44455
|
// Cria arestas de entrada e saída para a classe
|
|
@@ -44370,9 +44710,7 @@ class TradutorMermaidJs {
|
|
|
44370
44710
|
// Caminho então, normalmente um `Bloco`.
|
|
44371
44711
|
const verticesEntao = await declaracao.caminhoEntao.aceitar(this);
|
|
44372
44712
|
vertices = vertices.concat(verticesEntao);
|
|
44373
|
-
const ultimaArestaEntao = verticesEntao.length > 0
|
|
44374
|
-
? verticesEntao[verticesEntao.length - 1].destino
|
|
44375
|
-
: aresta;
|
|
44713
|
+
const ultimaArestaEntao = verticesEntao.length > 0 ? verticesEntao[verticesEntao.length - 1].destino : aresta;
|
|
44376
44714
|
if (declaracao.caminhoSenao) {
|
|
44377
44715
|
this.anteriores = [];
|
|
44378
44716
|
// Verifica se é "senão se" ou apenas "senão"
|
|
@@ -44420,9 +44758,7 @@ class TradutorMermaidJs {
|
|
|
44420
44758
|
verticesTente.push(...verticesDeclaracao);
|
|
44421
44759
|
}
|
|
44422
44760
|
vertices = vertices.concat(verticesTente);
|
|
44423
|
-
const ultimaArestaTente = verticesTente.length > 0
|
|
44424
|
-
? verticesTente[verticesTente.length - 1].destino
|
|
44425
|
-
: aresta;
|
|
44761
|
+
const ultimaArestaTente = verticesTente.length > 0 ? verticesTente[verticesTente.length - 1].destino : aresta;
|
|
44426
44762
|
const anterioresAposTente = [];
|
|
44427
44763
|
// Caminho pegue (catch) - se existir
|
|
44428
44764
|
if (declaracao.caminhoPegue) {
|
|
@@ -44608,7 +44944,7 @@ class TradutorMermaidJs {
|
|
|
44608
44944
|
async visitarExpressaoFuncaoConstruto(expressao) {
|
|
44609
44945
|
let texto = 'função anônima';
|
|
44610
44946
|
if (expressao.parametros && expressao.parametros.length > 0) {
|
|
44611
|
-
const parametros = expressao.parametros.map(p => p.nome.lexema).join(', ');
|
|
44947
|
+
const parametros = expressao.parametros.map((p) => p.nome.lexema).join(', ');
|
|
44612
44948
|
texto += `(${parametros})`;
|
|
44613
44949
|
}
|
|
44614
44950
|
else {
|
|
@@ -45150,7 +45486,7 @@ class TradutorPython {
|
|
|
45150
45486
|
}
|
|
45151
45487
|
const funcao = argumento;
|
|
45152
45488
|
// Extrai os nomes dos parâmetros
|
|
45153
|
-
const parametros = funcao.parametros.map(param => param.nome.lexema).join(', ');
|
|
45489
|
+
const parametros = funcao.parametros.map((param) => param.nome.lexema).join(', ');
|
|
45154
45490
|
// Python lambdas suportam apenas uma expressão
|
|
45155
45491
|
// Assumimos que a função tem um corpo simples com uma declaração de retorno
|
|
45156
45492
|
let expressao = '';
|
|
@@ -46895,7 +47231,7 @@ class TradutorRuby {
|
|
|
46895
47231
|
}
|
|
46896
47232
|
const funcao = argumento;
|
|
46897
47233
|
// Extrai os nomes dos parâmetros
|
|
46898
|
-
const parametros = funcao.parametros.map(param => param.nome.lexema).join(', ');
|
|
47234
|
+
const parametros = funcao.parametros.map((param) => param.nome.lexema).join(', ');
|
|
46899
47235
|
// Assumimos que a função tem um corpo simples com uma declaração de retorno
|
|
46900
47236
|
let expressao = '';
|
|
46901
47237
|
if (funcao.corpo.length > 0) {
|