@designliquido/delegua 0.39.1 → 0.39.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +22 -11
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +3 -6
- package/avaliador-sintatico/avaliador-sintatico.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 +1 -2
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +1 -2
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.js +2 -3
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.js.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/atribuir.d.ts +3 -2
- package/construtos/atribuir.d.ts.map +1 -1
- package/construtos/atribuir.js +7 -4
- package/construtos/atribuir.js.map +1 -1
- package/formatadores/formatador-delegua.js +1 -1
- package/formatadores/formatador-delegua.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 +2 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts +2 -2
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js +2 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js.map +1 -1
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +19 -1
- package/interpretador/interpretador-base.js.map +1 -1
- package/lexador/lexador.js +16 -16
- package/lexador/lexador.js.map +1 -1
- package/package.json +1 -1
- package/tradutores/tradutor-assembly-x64.js +13 -13
- package/tradutores/tradutor-assemblyscript.js +1 -1
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-javascript.d.ts +8 -6
- package/tradutores/tradutor-javascript.d.ts.map +1 -1
- package/tradutores/tradutor-javascript.js +135 -63
- package/tradutores/tradutor-javascript.js.map +1 -1
- package/tradutores/tradutor-python.d.ts +11 -6
- package/tradutores/tradutor-python.d.ts.map +1 -1
- package/tradutores/tradutor-python.js +146 -87
- package/tradutores/tradutor-python.js.map +1 -1
- package/umd/delegua.js +333 -187
package/umd/delegua.js
CHANGED
|
@@ -720,18 +720,15 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
720
720
|
].includes(expressao.operador.tipo)) {
|
|
721
721
|
if (expressao.esquerda instanceof construtos_1.AcessoIndiceVariavel) {
|
|
722
722
|
const entidade = expressao.esquerda;
|
|
723
|
-
|
|
724
|
-
return new construtos_1.Atribuir(this.hashArquivo, simbolo, expressao, entidade.indice);
|
|
723
|
+
return new construtos_1.Atribuir(this.hashArquivo, entidade.entidadeChamada, expressao, entidade.indice, expressao.operador);
|
|
725
724
|
}
|
|
726
|
-
|
|
727
|
-
return new construtos_1.Atribuir(this.hashArquivo, simbolo, expressao);
|
|
725
|
+
return new construtos_1.Atribuir(this.hashArquivo, expressao.esquerda, expressao, undefined, expressao.operador);
|
|
728
726
|
}
|
|
729
727
|
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL)) {
|
|
730
728
|
const igual = this.simbolos[this.atual - 1];
|
|
731
729
|
const valor = this.expressao();
|
|
732
730
|
if (expressao instanceof construtos_1.Variavel) {
|
|
733
|
-
|
|
734
|
-
return new construtos_1.Atribuir(this.hashArquivo, simbolo, valor);
|
|
731
|
+
return new construtos_1.Atribuir(this.hashArquivo, expressao, valor);
|
|
735
732
|
}
|
|
736
733
|
if (expressao instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
737
734
|
return new construtos_1.DefinirValor(this.hashArquivo, igual.linha, expressao.objeto, expressao.simbolo, valor);
|
|
@@ -1943,8 +1940,7 @@ class AvaliadorSintaticoEguaClassico {
|
|
|
1943
1940
|
const igual = this.simboloAnterior();
|
|
1944
1941
|
const valor = this.atribuir();
|
|
1945
1942
|
if (expressao instanceof construtos_1.Variavel) {
|
|
1946
|
-
|
|
1947
|
-
return new construtos_1.Atribuir(this.hashArquivo, simbolo, valor);
|
|
1943
|
+
return new construtos_1.Atribuir(this.hashArquivo, expressao, valor);
|
|
1948
1944
|
}
|
|
1949
1945
|
else if (expressao instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
1950
1946
|
const get = expressao;
|
|
@@ -2620,8 +2616,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
2620
2616
|
const igual = this.simboloAnterior();
|
|
2621
2617
|
const valor = this.atribuir();
|
|
2622
2618
|
if (expressao instanceof construtos_1.Variavel) {
|
|
2623
|
-
|
|
2624
|
-
return new construtos_1.Atribuir(this.hashArquivo, simbolo, valor);
|
|
2619
|
+
return new construtos_1.Atribuir(this.hashArquivo, expressao, valor);
|
|
2625
2620
|
}
|
|
2626
2621
|
if (expressao instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
2627
2622
|
return new construtos_1.DefinirValor(this.hashArquivo, 0, expressao.objeto, expressao.simbolo, valor);
|
|
@@ -3091,10 +3086,9 @@ class AvaliadorSintaticoPortugolIpt extends avaliador_sintatico_base_1.Avaliador
|
|
|
3091
3086
|
const setaAtribuicao = this.simbolos[this.atual - 1];
|
|
3092
3087
|
const valor = this.atribuir();
|
|
3093
3088
|
if (expressao instanceof construtos_1.Variavel) {
|
|
3094
|
-
|
|
3095
|
-
return new construtos_1.Atribuir(this.hashArquivo, simbolo, valor);
|
|
3089
|
+
return new construtos_1.Atribuir(this.hashArquivo, expressao, valor);
|
|
3096
3090
|
}
|
|
3097
|
-
|
|
3091
|
+
if (expressao instanceof construtos_1.AcessoIndiceVariavel) {
|
|
3098
3092
|
return new construtos_1.AtribuicaoPorIndice(this.hashArquivo, expressao.linha, expressao.entidadeChamada, expressao.indice, valor);
|
|
3099
3093
|
}
|
|
3100
3094
|
throw this.erro(setaAtribuicao, 'Tarefa de atribuição inválida');
|
|
@@ -4346,7 +4340,7 @@ exports.default = {
|
|
|
4346
4340
|
implementacao: (interpretador, vetor) => Promise.resolve(vetor.reverse())
|
|
4347
4341
|
},
|
|
4348
4342
|
juntar: {
|
|
4349
|
-
tipoRetorno: '
|
|
4343
|
+
tipoRetorno: 'texto',
|
|
4350
4344
|
implementacao: (interpretador, vetor, separador) => Promise.resolve(vetor.join(separador))
|
|
4351
4345
|
},
|
|
4352
4346
|
mapear: {
|
|
@@ -4588,17 +4582,20 @@ exports.Atribuir = void 0;
|
|
|
4588
4582
|
* Construto de atribuição de um valor a um símbolo.
|
|
4589
4583
|
*/
|
|
4590
4584
|
class Atribuir {
|
|
4591
|
-
constructor(hashArquivo,
|
|
4585
|
+
constructor(hashArquivo, alvo, valor,
|
|
4592
4586
|
// indice so é usado para variaveis de vetores
|
|
4593
4587
|
// TODO: criar alguma validaçao para garantir que `indice` só seja passado para variáveis de vetores
|
|
4594
|
-
indice) {
|
|
4595
|
-
this.linha = Number(
|
|
4588
|
+
indice, simboloOperador) {
|
|
4589
|
+
this.linha = Number(alvo.linha);
|
|
4596
4590
|
this.hashArquivo = hashArquivo;
|
|
4597
|
-
this.
|
|
4591
|
+
this.alvo = alvo;
|
|
4598
4592
|
this.valor = valor;
|
|
4599
4593
|
if (indice !== undefined) {
|
|
4600
4594
|
this.indice = indice;
|
|
4601
4595
|
}
|
|
4596
|
+
if (simboloOperador !== undefined) {
|
|
4597
|
+
this.simboloOperador = simboloOperador;
|
|
4598
|
+
}
|
|
4602
4599
|
}
|
|
4603
4600
|
async aceitar(visitante) {
|
|
4604
4601
|
return await visitante.visitarExpressaoDeAtribuicao(this);
|
|
@@ -6736,7 +6733,7 @@ class FormatadorDelegua {
|
|
|
6736
6733
|
this.visitarExpressaoBinaria(expressao.valor);
|
|
6737
6734
|
}
|
|
6738
6735
|
else {
|
|
6739
|
-
this.codigoFormatado += `${expressao.
|
|
6736
|
+
this.codigoFormatado += `${this.formatarDeclaracaoOuConstruto(expressao.alvo)} = `;
|
|
6740
6737
|
this.formatarDeclaracaoOuConstruto(expressao.valor);
|
|
6741
6738
|
}
|
|
6742
6739
|
this.codigoFormatado += `${this.quebraLinha}`;
|
|
@@ -8355,7 +8352,25 @@ class InterpretadorBase {
|
|
|
8355
8352
|
if (expressao.indice) {
|
|
8356
8353
|
indice = await this.avaliar(expressao.indice);
|
|
8357
8354
|
}
|
|
8358
|
-
|
|
8355
|
+
switch (expressao.alvo.constructor.name) {
|
|
8356
|
+
case 'Variavel':
|
|
8357
|
+
const alvoVariavel = expressao.alvo;
|
|
8358
|
+
this.pilhaEscoposExecucao.atribuirVariavel(alvoVariavel.simbolo, valorResolvido, indice);
|
|
8359
|
+
break;
|
|
8360
|
+
case 'AcessoMetodoOuPropriedade':
|
|
8361
|
+
// Nunca será método aqui: apenas propriedade.
|
|
8362
|
+
const alvoPropriedade = expressao.alvo;
|
|
8363
|
+
const variavelObjeto = await this.avaliar(alvoPropriedade.objeto);
|
|
8364
|
+
const objeto = variavelObjeto.hasOwnProperty('valor') ? variavelObjeto.valor : variavelObjeto;
|
|
8365
|
+
const valor = await this.avaliar(expressao.valor);
|
|
8366
|
+
if (objeto.constructor.name === 'ObjetoDeleguaClasse') {
|
|
8367
|
+
const objetoDeleguaClasse = objeto;
|
|
8368
|
+
objetoDeleguaClasse.definir(alvoPropriedade.simbolo, valor);
|
|
8369
|
+
}
|
|
8370
|
+
break;
|
|
8371
|
+
default:
|
|
8372
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(null, `Atribuição com caso faltante: ${expressao.alvo.constructor.name}.`);
|
|
8373
|
+
}
|
|
8359
8374
|
return valorResolvido;
|
|
8360
8375
|
}
|
|
8361
8376
|
procurarVariavel(simbolo) {
|
|
@@ -11784,11 +11799,11 @@ class Lexador {
|
|
|
11784
11799
|
this.inicioSimbolo = this.atual;
|
|
11785
11800
|
this.avancar();
|
|
11786
11801
|
if (this.simboloAtual() === '=') {
|
|
11787
|
-
this.adicionarSimbolo(delegua_1.default.MENOS_IGUAL);
|
|
11802
|
+
this.adicionarSimbolo(delegua_1.default.MENOS_IGUAL, '-=');
|
|
11788
11803
|
this.avancar();
|
|
11789
11804
|
}
|
|
11790
11805
|
else if (this.simboloAtual() === '-') {
|
|
11791
|
-
this.adicionarSimbolo(delegua_1.default.DECREMENTAR);
|
|
11806
|
+
this.adicionarSimbolo(delegua_1.default.DECREMENTAR, '--');
|
|
11792
11807
|
this.avancar();
|
|
11793
11808
|
}
|
|
11794
11809
|
else {
|
|
@@ -11799,11 +11814,11 @@ class Lexador {
|
|
|
11799
11814
|
this.inicioSimbolo = this.atual;
|
|
11800
11815
|
this.avancar();
|
|
11801
11816
|
if (this.simboloAtual() === '=') {
|
|
11802
|
-
this.adicionarSimbolo(delegua_1.default.MAIS_IGUAL);
|
|
11817
|
+
this.adicionarSimbolo(delegua_1.default.MAIS_IGUAL, '+=');
|
|
11803
11818
|
this.avancar();
|
|
11804
11819
|
}
|
|
11805
11820
|
else if (this.simboloAtual() === '+') {
|
|
11806
|
-
this.adicionarSimbolo(delegua_1.default.INCREMENTAR);
|
|
11821
|
+
this.adicionarSimbolo(delegua_1.default.INCREMENTAR, '++');
|
|
11807
11822
|
this.avancar();
|
|
11808
11823
|
}
|
|
11809
11824
|
else {
|
|
@@ -11820,7 +11835,7 @@ class Lexador {
|
|
|
11820
11835
|
switch (this.simboloAtual()) {
|
|
11821
11836
|
case '=':
|
|
11822
11837
|
this.avancar();
|
|
11823
|
-
this.adicionarSimbolo(delegua_1.default.MODULO_IGUAL);
|
|
11838
|
+
this.adicionarSimbolo(delegua_1.default.MODULO_IGUAL, '%=');
|
|
11824
11839
|
break;
|
|
11825
11840
|
default:
|
|
11826
11841
|
this.adicionarSimbolo(delegua_1.default.MODULO);
|
|
@@ -11833,11 +11848,11 @@ class Lexador {
|
|
|
11833
11848
|
switch (this.simboloAtual()) {
|
|
11834
11849
|
case '*':
|
|
11835
11850
|
this.avancar();
|
|
11836
|
-
this.adicionarSimbolo(delegua_1.default.EXPONENCIACAO);
|
|
11851
|
+
this.adicionarSimbolo(delegua_1.default.EXPONENCIACAO, '**');
|
|
11837
11852
|
break;
|
|
11838
11853
|
case '=':
|
|
11839
11854
|
this.avancar();
|
|
11840
|
-
this.adicionarSimbolo(delegua_1.default.MULTIPLICACAO_IGUAL);
|
|
11855
|
+
this.adicionarSimbolo(delegua_1.default.MULTIPLICACAO_IGUAL, '*=');
|
|
11841
11856
|
break;
|
|
11842
11857
|
default:
|
|
11843
11858
|
this.adicionarSimbolo(delegua_1.default.MULTIPLICACAO);
|
|
@@ -11847,7 +11862,7 @@ class Lexador {
|
|
|
11847
11862
|
case '!':
|
|
11848
11863
|
this.avancar();
|
|
11849
11864
|
if (this.simboloAtual() === '=') {
|
|
11850
|
-
this.adicionarSimbolo(delegua_1.default.DIFERENTE);
|
|
11865
|
+
this.adicionarSimbolo(delegua_1.default.DIFERENTE, '!=');
|
|
11851
11866
|
this.avancar();
|
|
11852
11867
|
}
|
|
11853
11868
|
else {
|
|
@@ -11857,7 +11872,7 @@ class Lexador {
|
|
|
11857
11872
|
case '=':
|
|
11858
11873
|
this.avancar();
|
|
11859
11874
|
if (this.simboloAtual() === '=') {
|
|
11860
|
-
this.adicionarSimbolo(delegua_1.default.IGUAL_IGUAL);
|
|
11875
|
+
this.adicionarSimbolo(delegua_1.default.IGUAL_IGUAL, '==');
|
|
11861
11876
|
this.avancar();
|
|
11862
11877
|
}
|
|
11863
11878
|
else {
|
|
@@ -11889,11 +11904,11 @@ class Lexador {
|
|
|
11889
11904
|
case '<':
|
|
11890
11905
|
this.avancar();
|
|
11891
11906
|
if (this.simboloAtual() === '=') {
|
|
11892
|
-
this.adicionarSimbolo(delegua_1.default.MENOR_IGUAL);
|
|
11907
|
+
this.adicionarSimbolo(delegua_1.default.MENOR_IGUAL, '<=');
|
|
11893
11908
|
this.avancar();
|
|
11894
11909
|
}
|
|
11895
11910
|
else if (this.simboloAtual() === '<') {
|
|
11896
|
-
this.adicionarSimbolo(delegua_1.default.MENOR_MENOR);
|
|
11911
|
+
this.adicionarSimbolo(delegua_1.default.MENOR_MENOR, '<<');
|
|
11897
11912
|
this.avancar();
|
|
11898
11913
|
}
|
|
11899
11914
|
else {
|
|
@@ -11903,11 +11918,11 @@ class Lexador {
|
|
|
11903
11918
|
case '>':
|
|
11904
11919
|
this.avancar();
|
|
11905
11920
|
if (this.simboloAtual() === '=') {
|
|
11906
|
-
this.adicionarSimbolo(delegua_1.default.MAIOR_IGUAL);
|
|
11921
|
+
this.adicionarSimbolo(delegua_1.default.MAIOR_IGUAL, '>=');
|
|
11907
11922
|
this.avancar();
|
|
11908
11923
|
}
|
|
11909
11924
|
else if (this.simboloAtual() === '>') {
|
|
11910
|
-
this.adicionarSimbolo(delegua_1.default.MAIOR_MAIOR);
|
|
11925
|
+
this.adicionarSimbolo(delegua_1.default.MAIOR_MAIOR, '>>');
|
|
11911
11926
|
this.avancar();
|
|
11912
11927
|
}
|
|
11913
11928
|
else {
|
|
@@ -11924,7 +11939,7 @@ class Lexador {
|
|
|
11924
11939
|
this.comentarioMultilinha();
|
|
11925
11940
|
break;
|
|
11926
11941
|
case '=':
|
|
11927
|
-
this.adicionarSimbolo(delegua_1.default.DIVISAO_IGUAL);
|
|
11942
|
+
this.adicionarSimbolo(delegua_1.default.DIVISAO_IGUAL, '/=');
|
|
11928
11943
|
this.avancar();
|
|
11929
11944
|
break;
|
|
11930
11945
|
default:
|
|
@@ -11937,7 +11952,7 @@ class Lexador {
|
|
|
11937
11952
|
this.avancar();
|
|
11938
11953
|
switch (this.simboloAtual()) {
|
|
11939
11954
|
case '=':
|
|
11940
|
-
this.adicionarSimbolo(delegua_1.default.DIVISAO_INTEIRA_IGUAL);
|
|
11955
|
+
this.adicionarSimbolo(delegua_1.default.DIVISAO_INTEIRA_IGUAL, '\\=');
|
|
11941
11956
|
this.avancar();
|
|
11942
11957
|
break;
|
|
11943
11958
|
default:
|
|
@@ -11945,7 +11960,7 @@ class Lexador {
|
|
|
11945
11960
|
break;
|
|
11946
11961
|
}
|
|
11947
11962
|
break;
|
|
11948
|
-
// Esta sessão ignora espaços em branco na tokenização.
|
|
11963
|
+
// Esta sessão ignora espaços em branco (ou similares) na tokenização.
|
|
11949
11964
|
case ' ':
|
|
11950
11965
|
case '\0':
|
|
11951
11966
|
case '\r':
|
|
@@ -25784,7 +25799,7 @@ class TradutorAssemblyScript {
|
|
|
25784
25799
|
return resultado;
|
|
25785
25800
|
}
|
|
25786
25801
|
traduzirConstrutoAtribuir(atribuir) {
|
|
25787
|
-
let resultado = atribuir.
|
|
25802
|
+
let resultado = this.dicionarioConstrutos[atribuir.alvo.constructor.name](atribuir.alvo);
|
|
25788
25803
|
resultado += ' = ' + this.dicionarioConstrutos[atribuir.valor.constructor.name](atribuir.valor);
|
|
25789
25804
|
return resultado;
|
|
25790
25805
|
}
|
|
@@ -25937,47 +25952,64 @@ class TradutorJavaScript {
|
|
|
25937
25952
|
return '-';
|
|
25938
25953
|
}
|
|
25939
25954
|
}
|
|
25940
|
-
|
|
25941
|
-
|
|
25955
|
+
traduzirFuncaoOuMetodo(nomeMetodo, objetoResolvido, argumentos) {
|
|
25956
|
+
const argumentosResolvidos = [];
|
|
25957
|
+
for (const argumento of argumentos) {
|
|
25958
|
+
const argumentoResolvido = this.dicionarioConstrutos[argumento.constructor.name](argumento);
|
|
25959
|
+
argumentosResolvidos.push(argumentoResolvido);
|
|
25960
|
+
}
|
|
25961
|
+
let textoArgumentos = argumentosResolvidos.reduce((atual, proximo) => atual += proximo + ', ', "");
|
|
25962
|
+
textoArgumentos = textoArgumentos.slice(0, -2);
|
|
25963
|
+
switch (nomeMetodo) {
|
|
25942
25964
|
case 'adicionar':
|
|
25943
25965
|
case 'empilhar':
|
|
25944
|
-
return
|
|
25945
|
-
case 'concatenar':
|
|
25946
|
-
return 'concat';
|
|
25966
|
+
return `${objetoResolvido}.push(${textoArgumentos})`;
|
|
25947
25967
|
case 'fatiar':
|
|
25948
|
-
return
|
|
25968
|
+
return `${objetoResolvido}.slice(${argumentos[0]}, ${argumentos[1]})`;
|
|
25949
25969
|
case 'inclui':
|
|
25950
|
-
return
|
|
25970
|
+
return `${objetoResolvido}.includes(${argumentosResolvidos[0]})`;
|
|
25951
25971
|
case 'inverter':
|
|
25952
|
-
return
|
|
25972
|
+
return `${objetoResolvido}.toReversed()`;
|
|
25953
25973
|
case 'juntar':
|
|
25954
|
-
return
|
|
25955
|
-
case 'ordenar':
|
|
25956
|
-
return 'sort';
|
|
25957
|
-
case 'removerprimeiro':
|
|
25958
|
-
return 'shift';
|
|
25959
|
-
case 'removerultimo':
|
|
25960
|
-
return 'pop';
|
|
25961
|
-
case 'tamanho':
|
|
25962
|
-
return 'length';
|
|
25974
|
+
return `${argumentosResolvidos[0]}.join(${objetoResolvido})`;
|
|
25963
25975
|
case 'maiusculo':
|
|
25964
|
-
return
|
|
25976
|
+
return `${objetoResolvido}.toUpperCase()`;
|
|
25977
|
+
case 'mapear':
|
|
25978
|
+
return `${objetoResolvido}.map(${this.traduzirFuncaoAnonimaParaLambda(argumentos[0])})`;
|
|
25965
25979
|
case 'minusculo':
|
|
25966
|
-
return
|
|
25967
|
-
case '
|
|
25968
|
-
return
|
|
25969
|
-
case '
|
|
25970
|
-
return
|
|
25971
|
-
|
|
25972
|
-
return
|
|
25980
|
+
return `${objetoResolvido}.toLowerCase()`;
|
|
25981
|
+
case 'ordenar':
|
|
25982
|
+
return `${objetoResolvido}.sort()`;
|
|
25983
|
+
case 'remover':
|
|
25984
|
+
return `delete ${objetoResolvido}[${argumentosResolvidos[0]}]`;
|
|
25985
|
+
case 'removerPrimeiro':
|
|
25986
|
+
return `${objetoResolvido}.shift()`;
|
|
25987
|
+
case 'removerUltimo':
|
|
25988
|
+
return `${objetoResolvido}.pop()`;
|
|
25989
|
+
case 'somar':
|
|
25990
|
+
return `${objetoResolvido}.reduce((acumulador, valorAtual) => acumulador + valorAtual, 0)`;
|
|
25991
|
+
case 'tamanho':
|
|
25992
|
+
return `${objetoResolvido}.length`;
|
|
25973
25993
|
}
|
|
25994
|
+
return `${objetoResolvido}.${nomeMetodo}(${textoArgumentos}))`;
|
|
25974
25995
|
}
|
|
25975
25996
|
traduzirConstrutoAgrupamento(agrupamento) {
|
|
25976
25997
|
return this.dicionarioConstrutos[agrupamento.constructor.name](agrupamento.expressao || agrupamento);
|
|
25977
25998
|
}
|
|
25978
25999
|
traduzirConstrutoAtribuir(atribuir) {
|
|
25979
|
-
|
|
25980
|
-
resultado
|
|
26000
|
+
var _a;
|
|
26001
|
+
let resultado = this.dicionarioConstrutos[atribuir.alvo.constructor.name](atribuir.alvo);
|
|
26002
|
+
const operador = ((_a = atribuir.simboloOperador) === null || _a === void 0 ? void 0 : _a.lexema) || '=';
|
|
26003
|
+
// Em Delégua, atribuições com operações embutidas devolvem um construto `Binario` no valor
|
|
26004
|
+
// por várias razões, sendo a mais importante delas a lógica de interpretação.
|
|
26005
|
+
let valorResolvido = '';
|
|
26006
|
+
if (atribuir.simboloOperador && atribuir.valor.constructor.name === 'Binario') {
|
|
26007
|
+
valorResolvido = this.dicionarioConstrutos[atribuir.valor.direita.constructor.name](atribuir.valor.direita);
|
|
26008
|
+
}
|
|
26009
|
+
else {
|
|
26010
|
+
valorResolvido = this.dicionarioConstrutos[atribuir.valor.constructor.name](atribuir.valor);
|
|
26011
|
+
}
|
|
26012
|
+
resultado += ` ${operador} ` + valorResolvido;
|
|
25981
26013
|
return resultado;
|
|
25982
26014
|
}
|
|
25983
26015
|
traduzirConstrutoBinario(binario) {
|
|
@@ -25996,28 +26028,8 @@ class TradutorJavaScript {
|
|
|
25996
26028
|
}
|
|
25997
26029
|
traduzirConstrutoChamada(chamada) {
|
|
25998
26030
|
let resultado = '';
|
|
25999
|
-
const retorno = `${this.dicionarioConstrutos[chamada.entidadeChamada.constructor.name](chamada.entidadeChamada)}`;
|
|
26000
|
-
|
|
26001
|
-
if (instanciaClasse) {
|
|
26002
|
-
const classe = this.declaracoesDeClasses.find((declaracao) => { var _a; return ((_a = declaracao === null || declaracao === void 0 ? void 0 : declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) === retorno; });
|
|
26003
|
-
if (classe.simbolo.lexema === retorno)
|
|
26004
|
-
resultado += `new ${retorno}`;
|
|
26005
|
-
}
|
|
26006
|
-
else {
|
|
26007
|
-
resultado += retorno;
|
|
26008
|
-
}
|
|
26009
|
-
if (!retorno.endsWith('length')) {
|
|
26010
|
-
resultado += '(';
|
|
26011
|
-
}
|
|
26012
|
-
for (let parametro of chamada.argumentos) {
|
|
26013
|
-
resultado += this.dicionarioConstrutos[parametro.constructor.name](parametro) + ', ';
|
|
26014
|
-
}
|
|
26015
|
-
if (chamada.argumentos.length > 0) {
|
|
26016
|
-
resultado = resultado.slice(0, -2);
|
|
26017
|
-
}
|
|
26018
|
-
if (!retorno.endsWith('length')) {
|
|
26019
|
-
resultado += ')';
|
|
26020
|
-
}
|
|
26031
|
+
const retorno = `${this.dicionarioConstrutos[chamada.entidadeChamada.constructor.name](chamada.entidadeChamada, chamada.argumentos)}`;
|
|
26032
|
+
resultado += retorno;
|
|
26021
26033
|
return resultado;
|
|
26022
26034
|
}
|
|
26023
26035
|
traduzirConstrutoComentario(comentario) {
|
|
@@ -26067,8 +26079,28 @@ class TradutorJavaScript {
|
|
|
26067
26079
|
}
|
|
26068
26080
|
return literal.valor;
|
|
26069
26081
|
}
|
|
26070
|
-
traduzirConstrutoVariavel(variavel) {
|
|
26071
|
-
|
|
26082
|
+
traduzirConstrutoVariavel(variavel, argumentos) {
|
|
26083
|
+
const argumentosResolvidos = [];
|
|
26084
|
+
const argumentosValidados = argumentos || [];
|
|
26085
|
+
for (const argumento of argumentosValidados) {
|
|
26086
|
+
const argumentoResolvido = this.dicionarioConstrutos[argumento.constructor.name](argumento);
|
|
26087
|
+
argumentosResolvidos.push(argumentoResolvido);
|
|
26088
|
+
}
|
|
26089
|
+
let textoArgumentos = argumentosResolvidos.reduce((atual, proximo) => atual += proximo + ', ', "");
|
|
26090
|
+
textoArgumentos = textoArgumentos.slice(0, -2);
|
|
26091
|
+
switch (variavel.simbolo.lexema) {
|
|
26092
|
+
case 'texto':
|
|
26093
|
+
return `String(${textoArgumentos})`;
|
|
26094
|
+
default:
|
|
26095
|
+
const buscaClasseCorrespondente = this.declaracoesDeClasses.filter(d => d.simbolo.lexema === variavel.simbolo.lexema);
|
|
26096
|
+
if (buscaClasseCorrespondente.length === 0 && argumentosValidados.length === 0) {
|
|
26097
|
+
return `${variavel.simbolo.lexema}`;
|
|
26098
|
+
}
|
|
26099
|
+
if (buscaClasseCorrespondente.length > 0) {
|
|
26100
|
+
return `new ${variavel.simbolo.lexema}(${textoArgumentos})`;
|
|
26101
|
+
}
|
|
26102
|
+
return `${variavel.simbolo.lexema}(${textoArgumentos})`;
|
|
26103
|
+
}
|
|
26072
26104
|
}
|
|
26073
26105
|
logicaComumBlocoEscopo(declaracoes) {
|
|
26074
26106
|
let resultado = '{\n';
|
|
@@ -26335,24 +26367,72 @@ class TradutorJavaScript {
|
|
|
26335
26367
|
}
|
|
26336
26368
|
return resultado;
|
|
26337
26369
|
}
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
|
|
26341
|
-
|
|
26370
|
+
// TODO: Talvez terminar (ou remover, sei lá).
|
|
26371
|
+
traduzirFuncaoAnonimaParaLambda(argumento) {
|
|
26372
|
+
return "";
|
|
26373
|
+
}
|
|
26374
|
+
traduzirAcessoMetodoVetor(objeto, nomeMetodo, argumentos) {
|
|
26375
|
+
const objetoResolvido = this.dicionarioConstrutos[objeto.constructor.name](objeto);
|
|
26376
|
+
const argumentosResolvidos = [];
|
|
26377
|
+
for (const argumento of argumentos) {
|
|
26378
|
+
const argumentoResolvido = this.dicionarioConstrutos[argumento.constructor.name](argumento);
|
|
26379
|
+
argumentosResolvidos.push(argumentoResolvido);
|
|
26380
|
+
}
|
|
26381
|
+
switch (nomeMetodo) {
|
|
26382
|
+
case 'adicionar':
|
|
26383
|
+
case 'empilhar':
|
|
26384
|
+
let textoArgumentos = argumentosResolvidos.reduce((atual, proximo) => atual += proximo + ', ', "");
|
|
26385
|
+
textoArgumentos = textoArgumentos.slice(0, -2);
|
|
26386
|
+
return `${objetoResolvido}.push(${textoArgumentos})`;
|
|
26387
|
+
case 'fatiar':
|
|
26388
|
+
return `${objetoResolvido}[${argumentos[0]}:${argumentos[1]}]`;
|
|
26389
|
+
case 'inclui':
|
|
26390
|
+
return `${argumentos[0]} in ${objetoResolvido}`;
|
|
26391
|
+
case 'inverter':
|
|
26392
|
+
return `reversed(${objetoResolvido})`;
|
|
26393
|
+
case 'juntar':
|
|
26394
|
+
return `${argumentos[0]}.join(${objetoResolvido})`;
|
|
26395
|
+
case 'mapear':
|
|
26396
|
+
return `list(map(${this.traduzirFuncaoAnonimaParaLambda(argumentos[0])}), ${objetoResolvido})`;
|
|
26397
|
+
case 'ordenar':
|
|
26398
|
+
return `${objetoResolvido}.sort()`;
|
|
26399
|
+
case 'remover':
|
|
26400
|
+
return `del ${objetoResolvido}[${argumentos[0]}]`;
|
|
26401
|
+
case 'removerPrimeiro':
|
|
26402
|
+
return `del ${objetoResolvido}[0]`;
|
|
26403
|
+
case 'removerUltimo':
|
|
26404
|
+
return `del ${objetoResolvido}[-1]`;
|
|
26405
|
+
case 'somar':
|
|
26406
|
+
return `sum(${objetoResolvido})`;
|
|
26407
|
+
case 'tamanho':
|
|
26408
|
+
return `len(${objetoResolvido})`;
|
|
26342
26409
|
}
|
|
26343
|
-
return `this.${acessoMetodo.nomeMetodo}`;
|
|
26344
26410
|
}
|
|
26345
|
-
|
|
26411
|
+
traduzirConstrutoAcessoMetodo(acessoMetodo, argumentos) {
|
|
26412
|
+
switch (acessoMetodo.objeto.constructor.name) {
|
|
26413
|
+
case 'Isto':
|
|
26414
|
+
return `this.${acessoMetodo.nomeMetodo}`;
|
|
26415
|
+
case 'Variavel':
|
|
26416
|
+
let objetoVariavel = acessoMetodo.objeto;
|
|
26417
|
+
return this.traduzirFuncaoOuMetodo(acessoMetodo.nomeMetodo, objetoVariavel.simbolo.lexema, argumentos);
|
|
26418
|
+
case 'Vetor':
|
|
26419
|
+
return this.traduzirAcessoMetodoVetor(acessoMetodo.objeto, acessoMetodo.nomeMetodo, argumentos);
|
|
26420
|
+
default:
|
|
26421
|
+
const objetoResolvido = this.dicionarioConstrutos[acessoMetodo.objeto.constructor.name](acessoMetodo.objeto);
|
|
26422
|
+
return `${objetoResolvido}.${acessoMetodo.nomeMetodo}`;
|
|
26423
|
+
}
|
|
26424
|
+
}
|
|
26425
|
+
traduzirConstrutoAcessoMetodoOuPropriedade(acessoMetodo, argumentos) {
|
|
26346
26426
|
if (acessoMetodo.objeto instanceof construtos_1.Variavel) {
|
|
26347
26427
|
let objetoVariavel = acessoMetodo.objeto;
|
|
26348
|
-
return `${
|
|
26428
|
+
return `${this.traduzirFuncaoOuMetodo(acessoMetodo.simbolo.lexema, objetoVariavel.simbolo.lexema, argumentos)}`;
|
|
26349
26429
|
}
|
|
26350
26430
|
return `this.${acessoMetodo.simbolo.lexema}`;
|
|
26351
26431
|
}
|
|
26352
|
-
traduzirConstrutoAcessoPropriedade(acessoMetodo) {
|
|
26432
|
+
traduzirConstrutoAcessoPropriedade(acessoMetodo, argumentos) {
|
|
26353
26433
|
if (acessoMetodo.objeto instanceof construtos_1.Variavel) {
|
|
26354
26434
|
let objetoVariavel = acessoMetodo.objeto;
|
|
26355
|
-
return `${objetoVariavel.simbolo.lexema
|
|
26435
|
+
return `${this.traduzirFuncaoOuMetodo(objetoVariavel.simbolo.lexema, acessoMetodo.nomePropriedade, argumentos)}`;
|
|
26356
26436
|
}
|
|
26357
26437
|
return `this.${acessoMetodo.nomePropriedade}`;
|
|
26358
26438
|
}
|
|
@@ -26413,13 +26493,20 @@ class TradutorJavaScript {
|
|
|
26413
26493
|
traduzirConstrutoTipoDe(tipoDe) {
|
|
26414
26494
|
let resultado = 'typeof ';
|
|
26415
26495
|
if (!tipoDe.valor)
|
|
26416
|
-
resultado += tipoDe.valor;
|
|
26496
|
+
resultado += tipoDe.valor; // Qual o sentido disso?
|
|
26417
26497
|
else if (typeof tipoDe.valor === 'string')
|
|
26418
26498
|
resultado += `'${tipoDe.valor}'`;
|
|
26419
26499
|
else if (typeof tipoDe.valor === 'number')
|
|
26420
26500
|
resultado += tipoDe.valor;
|
|
26421
|
-
else
|
|
26422
|
-
|
|
26501
|
+
else {
|
|
26502
|
+
// Talvez isso seja uma péssima ideia.
|
|
26503
|
+
// Pensar em algo melhor.
|
|
26504
|
+
let alvoTipoDe = String(this.dicionarioConstrutos[tipoDe.valor.constructor.name](tipoDe.valor));
|
|
26505
|
+
if (alvoTipoDe.startsWith('new')) {
|
|
26506
|
+
alvoTipoDe = alvoTipoDe.slice(4, -2);
|
|
26507
|
+
}
|
|
26508
|
+
resultado += `${alvoTipoDe}`;
|
|
26509
|
+
}
|
|
26423
26510
|
return resultado;
|
|
26424
26511
|
}
|
|
26425
26512
|
traduzirDeclaracaoFalhar(falhar) {
|
|
@@ -26525,6 +26612,7 @@ const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
|
26525
26612
|
class TradutorPython {
|
|
26526
26613
|
constructor() {
|
|
26527
26614
|
this.indentacao = 0;
|
|
26615
|
+
this.classesConhecidas = [];
|
|
26528
26616
|
this.dicionarioConstrutos = {
|
|
26529
26617
|
AcessoMetodo: this.traduzirConstrutoAcessoMetodo.bind(this),
|
|
26530
26618
|
AcessoMetodoOuPropriedade: this.traduzirConstrutoAcessoMetodoOuPropriedade.bind(this),
|
|
@@ -26537,6 +26625,7 @@ class TradutorPython {
|
|
|
26537
26625
|
Chamada: this.traduzirConstrutoChamada.bind(this),
|
|
26538
26626
|
Comentario: this.traduzirConstrutoComentario.bind(this),
|
|
26539
26627
|
DefinirValor: this.traduzirConstrutoDefinirValor.bind(this),
|
|
26628
|
+
Dicionario: this.traduzirConstrutoDicionario.bind(this),
|
|
26540
26629
|
Literal: this.traduzirConstrutoLiteral.bind(this),
|
|
26541
26630
|
Logico: this.traduzirConstrutoLogico.bind(this),
|
|
26542
26631
|
Unario: this.traduzirConstrutoUnario.bind(this),
|
|
@@ -26605,38 +26694,46 @@ class TradutorPython {
|
|
|
26605
26694
|
return '-';
|
|
26606
26695
|
}
|
|
26607
26696
|
}
|
|
26608
|
-
|
|
26609
|
-
|
|
26697
|
+
traduzirFuncaoOuMetodo(nomeMetodo, objetoResolvido, argumentos) {
|
|
26698
|
+
const argumentosResolvidos = [];
|
|
26699
|
+
for (const argumento of argumentos) {
|
|
26700
|
+
const argumentoResolvido = this.dicionarioConstrutos[argumento.constructor.name](argumento);
|
|
26701
|
+
argumentosResolvidos.push(argumentoResolvido);
|
|
26702
|
+
}
|
|
26703
|
+
let textoArgumentos = argumentosResolvidos.reduce((atual, proximo) => atual += proximo + ', ', "");
|
|
26704
|
+
textoArgumentos = textoArgumentos.slice(0, -2);
|
|
26705
|
+
switch (nomeMetodo) {
|
|
26610
26706
|
case 'adicionar':
|
|
26611
26707
|
case 'empilhar':
|
|
26612
|
-
return
|
|
26708
|
+
return `${objetoResolvido}.append(${textoArgumentos})`;
|
|
26613
26709
|
case 'fatiar':
|
|
26614
|
-
return
|
|
26710
|
+
return `${objetoResolvido}[${argumentos[0]}:${argumentos[1]}]`;
|
|
26615
26711
|
case 'inclui':
|
|
26616
|
-
return
|
|
26712
|
+
return `${argumentosResolvidos[0]} in ${objetoResolvido}`;
|
|
26617
26713
|
case 'inverter':
|
|
26618
|
-
return
|
|
26714
|
+
return `reversed(${objetoResolvido})`;
|
|
26619
26715
|
case 'juntar':
|
|
26620
|
-
return
|
|
26621
|
-
case 'ordenar':
|
|
26622
|
-
return 'sort';
|
|
26623
|
-
case 'removerprimeiro':
|
|
26624
|
-
return 'pop(0)';
|
|
26625
|
-
case 'removerultimo':
|
|
26626
|
-
return 'pop';
|
|
26627
|
-
case 'tamanho':
|
|
26628
|
-
return 'len';
|
|
26716
|
+
return `${argumentosResolvidos[0]}.join(${objetoResolvido})`;
|
|
26629
26717
|
case 'maiusculo':
|
|
26630
|
-
return
|
|
26718
|
+
return `${objetoResolvido}.upper()`;
|
|
26719
|
+
case 'mapear':
|
|
26720
|
+
return `list(map(${this.traduzirFuncaoAnonimaParaLambda(argumentos[0])}), ${objetoResolvido})`;
|
|
26631
26721
|
case 'minusculo':
|
|
26632
|
-
return
|
|
26633
|
-
case '
|
|
26634
|
-
return
|
|
26635
|
-
case '
|
|
26636
|
-
return
|
|
26637
|
-
|
|
26638
|
-
return
|
|
26722
|
+
return `${objetoResolvido}.lower()`;
|
|
26723
|
+
case 'ordenar':
|
|
26724
|
+
return `${objetoResolvido}.sort()`;
|
|
26725
|
+
case 'remover':
|
|
26726
|
+
return `del ${objetoResolvido}[${argumentosResolvidos[0]}]`;
|
|
26727
|
+
case 'removerPrimeiro':
|
|
26728
|
+
return `${objetoResolvido}.pop(0)`;
|
|
26729
|
+
case 'removerUltimo':
|
|
26730
|
+
return `${objetoResolvido}.pop()`;
|
|
26731
|
+
case 'somar':
|
|
26732
|
+
return `sum(${objetoResolvido})`;
|
|
26733
|
+
case 'tamanho':
|
|
26734
|
+
return `len(${objetoResolvido})`;
|
|
26639
26735
|
}
|
|
26736
|
+
return `${objetoResolvido}.${nomeMetodo}(${textoArgumentos}))`;
|
|
26640
26737
|
}
|
|
26641
26738
|
logicaComumBlocoEscopo(declaracoes) {
|
|
26642
26739
|
let resultado = '';
|
|
@@ -26663,45 +26760,72 @@ class TradutorPython {
|
|
|
26663
26760
|
const indice = this.dicionarioConstrutos[acessoIndiceVariavel.indice.constructor.name](acessoIndiceVariavel.indice);
|
|
26664
26761
|
return `${entidade}[${indice}]`;
|
|
26665
26762
|
}
|
|
26666
|
-
|
|
26667
|
-
|
|
26668
|
-
|
|
26669
|
-
|
|
26670
|
-
|
|
26671
|
-
|
|
26672
|
-
|
|
26673
|
-
|
|
26674
|
-
|
|
26675
|
-
|
|
26676
|
-
|
|
26763
|
+
// TODO: Talvez terminar (ou remover, sei lá).
|
|
26764
|
+
traduzirFuncaoAnonimaParaLambda(argumento) {
|
|
26765
|
+
return "";
|
|
26766
|
+
}
|
|
26767
|
+
traduzirAcessoMetodoVetor(objeto, nomeMetodo, argumentos) {
|
|
26768
|
+
const objetoResolvido = this.dicionarioConstrutos[objeto.constructor.name](objeto);
|
|
26769
|
+
const argumentosResolvidos = [];
|
|
26770
|
+
for (const argumento of argumentos) {
|
|
26771
|
+
const argumentoResolvido = this.dicionarioConstrutos[argumento.constructor.name](argumento);
|
|
26772
|
+
argumentosResolvidos.push(argumentoResolvido);
|
|
26773
|
+
}
|
|
26774
|
+
switch (nomeMetodo) {
|
|
26775
|
+
case 'adicionar':
|
|
26776
|
+
case 'empilhar':
|
|
26777
|
+
let textoArgumentos = argumentosResolvidos.reduce((atual, proximo) => atual += proximo + ', ', "");
|
|
26778
|
+
textoArgumentos = textoArgumentos.slice(0, -2);
|
|
26779
|
+
return `${objetoResolvido}.append(${textoArgumentos})`;
|
|
26780
|
+
case 'fatiar':
|
|
26781
|
+
return `${objetoResolvido}[${argumentos[0]}:${argumentos[1]}]`;
|
|
26782
|
+
case 'inclui':
|
|
26783
|
+
return `${argumentos[0]} in ${objetoResolvido}`;
|
|
26784
|
+
case 'inverter':
|
|
26785
|
+
return `reversed(${objetoResolvido})`;
|
|
26786
|
+
case 'juntar':
|
|
26787
|
+
return `${argumentos[0]}.join(${objetoResolvido})`;
|
|
26788
|
+
case 'mapear':
|
|
26789
|
+
return `list(map(${this.traduzirFuncaoAnonimaParaLambda(argumentos[0])}), ${objetoResolvido})`;
|
|
26790
|
+
case 'ordenar':
|
|
26791
|
+
return `${objetoResolvido}.sort()`;
|
|
26792
|
+
case 'remover':
|
|
26793
|
+
return `del ${objetoResolvido}[${argumentos[0]}]`;
|
|
26794
|
+
case 'removerPrimeiro':
|
|
26795
|
+
return `del ${objetoResolvido}[0]`;
|
|
26796
|
+
case 'removerUltimo':
|
|
26797
|
+
return `del ${objetoResolvido}[-1]`;
|
|
26798
|
+
case 'somar':
|
|
26799
|
+
return `sum(${objetoResolvido})`;
|
|
26800
|
+
case 'tamanho':
|
|
26801
|
+
return `len(${objetoResolvido})`;
|
|
26802
|
+
}
|
|
26803
|
+
}
|
|
26804
|
+
traduzirConstrutoAcessoMetodo(acessoMetodo, argumentos) {
|
|
26805
|
+
switch (acessoMetodo.objeto.constructor.name) {
|
|
26806
|
+
case 'Isto':
|
|
26807
|
+
return `self.${acessoMetodo.nomeMetodo}`;
|
|
26808
|
+
case 'Variavel':
|
|
26809
|
+
let objetoVariavel = acessoMetodo.objeto;
|
|
26810
|
+
return this.traduzirFuncaoOuMetodo(acessoMetodo.nomeMetodo, objetoVariavel.simbolo.lexema, argumentos);
|
|
26811
|
+
case 'Vetor':
|
|
26812
|
+
return this.traduzirAcessoMetodoVetor(acessoMetodo.objeto, acessoMetodo.nomeMetodo, argumentos);
|
|
26813
|
+
default:
|
|
26814
|
+
const objetoResolvido = this.dicionarioConstrutos[acessoMetodo.objeto.constructor.name](acessoMetodo.objeto);
|
|
26815
|
+
return `${objetoResolvido}.${acessoMetodo.nomeMetodo}`;
|
|
26677
26816
|
}
|
|
26678
|
-
return `self.${acessoMetodo.nomeMetodo}`;
|
|
26679
26817
|
}
|
|
26680
|
-
traduzirConstrutoAcessoMetodoOuPropriedade(acessoMetodo) {
|
|
26818
|
+
traduzirConstrutoAcessoMetodoOuPropriedade(acessoMetodo, argumentos) {
|
|
26681
26819
|
if (acessoMetodo.objeto instanceof construtos_1.Variavel) {
|
|
26682
26820
|
let objetoVariavel = acessoMetodo.objeto;
|
|
26683
|
-
|
|
26684
|
-
if (funcaoTraduzida === 'in') {
|
|
26685
|
-
return `in ${objetoVariavel.simbolo.lexema}`;
|
|
26686
|
-
}
|
|
26687
|
-
else if (funcaoTraduzida === 'len') {
|
|
26688
|
-
return `len(${objetoVariavel.simbolo.lexema})`;
|
|
26689
|
-
}
|
|
26690
|
-
return `${objetoVariavel.simbolo.lexema}.${funcaoTraduzida}`;
|
|
26821
|
+
return this.traduzirFuncaoOuMetodo(acessoMetodo.simbolo.lexema, objetoVariavel.simbolo.lexema, argumentos);
|
|
26691
26822
|
}
|
|
26692
26823
|
return `self.${acessoMetodo.simbolo.lexema}`;
|
|
26693
26824
|
}
|
|
26694
|
-
traduzirConstrutoAcessoPropriedade(acessoPropriedade) {
|
|
26825
|
+
traduzirConstrutoAcessoPropriedade(acessoPropriedade, argumentos) {
|
|
26695
26826
|
if (acessoPropriedade.objeto instanceof construtos_1.Variavel) {
|
|
26696
26827
|
let objetoVariavel = acessoPropriedade.objeto;
|
|
26697
|
-
|
|
26698
|
-
if (funcaoTraduzida === 'in') {
|
|
26699
|
-
return `in ${objetoVariavel.simbolo.lexema}`;
|
|
26700
|
-
}
|
|
26701
|
-
else if (funcaoTraduzida === 'len') {
|
|
26702
|
-
return `len(${objetoVariavel.simbolo.lexema})`;
|
|
26703
|
-
}
|
|
26704
|
-
return `${objetoVariavel.simbolo.lexema}.${funcaoTraduzida}`;
|
|
26828
|
+
return this.traduzirFuncaoOuMetodo(objetoVariavel.simbolo.lexema, acessoPropriedade.nomePropriedade, argumentos);
|
|
26705
26829
|
}
|
|
26706
26830
|
return `self.${acessoPropriedade.nomePropriedade}`;
|
|
26707
26831
|
}
|
|
@@ -26715,49 +26839,39 @@ class TradutorPython {
|
|
|
26715
26839
|
return `${objeto}[${indice}] = ${valor}`;
|
|
26716
26840
|
}
|
|
26717
26841
|
traduzirConstrutoAtribuir(atribuir) {
|
|
26718
|
-
|
|
26719
|
-
resultado
|
|
26842
|
+
var _a;
|
|
26843
|
+
let resultado = this.dicionarioConstrutos[atribuir.alvo.constructor.name](atribuir.alvo);
|
|
26844
|
+
const operador = ((_a = atribuir.simboloOperador) === null || _a === void 0 ? void 0 : _a.lexema) || '=';
|
|
26845
|
+
// Em Delégua, atribuições com operações embutidas devolvem um construto `Binario` no valor
|
|
26846
|
+
// por várias razões, sendo a mais importante delas a lógica de interpretação.
|
|
26847
|
+
let valorResolvido = '';
|
|
26848
|
+
if (atribuir.simboloOperador && atribuir.valor.constructor.name === 'Binario') {
|
|
26849
|
+
valorResolvido = this.dicionarioConstrutos[atribuir.valor.direita.constructor.name](atribuir.valor.direita);
|
|
26850
|
+
}
|
|
26851
|
+
else {
|
|
26852
|
+
valorResolvido = this.dicionarioConstrutos[atribuir.valor.constructor.name](atribuir.valor);
|
|
26853
|
+
}
|
|
26854
|
+
resultado += ` ${operador} ` + valorResolvido;
|
|
26720
26855
|
return resultado;
|
|
26721
26856
|
}
|
|
26722
26857
|
traduzirConstrutoBinario(binario) {
|
|
26723
26858
|
let resultado = '';
|
|
26859
|
+
const valorEsquerdo = this.dicionarioConstrutos[binario.esquerda.constructor.name](binario.esquerda);
|
|
26724
26860
|
if (binario.esquerda.constructor.name === 'Agrupamento')
|
|
26725
|
-
resultado += '(' +
|
|
26861
|
+
resultado += '(' + valorEsquerdo + ')';
|
|
26726
26862
|
else
|
|
26727
|
-
resultado +=
|
|
26863
|
+
resultado += valorEsquerdo;
|
|
26728
26864
|
let operador = this.traduzirSimboloOperador(binario.operador);
|
|
26729
26865
|
resultado += ` ${operador} `;
|
|
26866
|
+
const valorDireito = this.dicionarioConstrutos[binario.direita.constructor.name](binario.direita);
|
|
26730
26867
|
if (binario.direita.constructor.name === 'Agrupamento')
|
|
26731
|
-
resultado += '(' +
|
|
26868
|
+
resultado += '(' + valorDireito + ')';
|
|
26732
26869
|
else
|
|
26733
|
-
resultado +=
|
|
26870
|
+
resultado += valorDireito;
|
|
26734
26871
|
return resultado;
|
|
26735
26872
|
}
|
|
26736
26873
|
traduzirConstrutoChamada(chamada) {
|
|
26737
|
-
|
|
26738
|
-
const retorno = `${this.dicionarioConstrutos[chamada.entidadeChamada.constructor.name](chamada.entidadeChamada)}`;
|
|
26739
|
-
resultado += retorno;
|
|
26740
|
-
if (!resultado.includes('in ') && !resultado.includes('len') && !resultado.includes('pop(')) {
|
|
26741
|
-
resultado += '(';
|
|
26742
|
-
}
|
|
26743
|
-
if (!resultado.includes('len(')) {
|
|
26744
|
-
for (let parametro of chamada.argumentos) {
|
|
26745
|
-
const parametroTratado = this.dicionarioConstrutos[parametro.constructor.name](parametro);
|
|
26746
|
-
if (resultado.includes('in ') || resultado.includes('len')) {
|
|
26747
|
-
resultado = `${parametroTratado} ${resultado}`;
|
|
26748
|
-
}
|
|
26749
|
-
else {
|
|
26750
|
-
resultado += parametroTratado + ', ';
|
|
26751
|
-
}
|
|
26752
|
-
}
|
|
26753
|
-
if (chamada.argumentos.length > 0 && !resultado.includes('in ') && !resultado.includes('len')) {
|
|
26754
|
-
resultado = resultado.slice(0, -2);
|
|
26755
|
-
}
|
|
26756
|
-
if (!resultado.includes(')') && !resultado.includes('in ')) {
|
|
26757
|
-
resultado += ')';
|
|
26758
|
-
}
|
|
26759
|
-
}
|
|
26760
|
-
return resultado;
|
|
26874
|
+
return `${this.dicionarioConstrutos[chamada.entidadeChamada.constructor.name](chamada.entidadeChamada, chamada.argumentos)}`;
|
|
26761
26875
|
}
|
|
26762
26876
|
traduzirConstrutoComentario(comentario) {
|
|
26763
26877
|
let resultado = '';
|
|
@@ -26781,6 +26895,18 @@ class TradutorPython {
|
|
|
26781
26895
|
resultado += definirValor.valor.simbolo.lexema;
|
|
26782
26896
|
return resultado;
|
|
26783
26897
|
}
|
|
26898
|
+
traduzirConstrutoDicionario(dicionario) {
|
|
26899
|
+
let resultado = `{${dicionario.chaves.length > 0 ? '\n' : ''}`;
|
|
26900
|
+
for (let indice = 0; indice < dicionario.chaves.length; indice++) {
|
|
26901
|
+
resultado += ' '.repeat(this.indentacao + 4);
|
|
26902
|
+
const chave = dicionario.chaves[indice];
|
|
26903
|
+
resultado += `${this.dicionarioConstrutos[chave.constructor.name](chave)}: `;
|
|
26904
|
+
const valor = dicionario.valores[indice];
|
|
26905
|
+
resultado += `${this.dicionarioConstrutos[valor.constructor.name](valor)},\n`;
|
|
26906
|
+
}
|
|
26907
|
+
resultado += '}';
|
|
26908
|
+
return resultado;
|
|
26909
|
+
}
|
|
26784
26910
|
traduzirConstrutoLiteral(literal) {
|
|
26785
26911
|
if (typeof literal.valor === 'string')
|
|
26786
26912
|
return `'${literal.valor}'`;
|
|
@@ -26810,8 +26936,24 @@ class TradutorPython {
|
|
|
26810
26936
|
return `${operando}${operador}`;
|
|
26811
26937
|
}
|
|
26812
26938
|
}
|
|
26813
|
-
traduzirConstrutoVariavel(variavel) {
|
|
26814
|
-
|
|
26939
|
+
traduzirConstrutoVariavel(variavel, argumentos) {
|
|
26940
|
+
const argumentosResolvidos = [];
|
|
26941
|
+
const argumentosValidados = argumentos || [];
|
|
26942
|
+
for (const argumento of argumentosValidados) {
|
|
26943
|
+
const argumentoResolvido = this.dicionarioConstrutos[argumento.constructor.name](argumento);
|
|
26944
|
+
argumentosResolvidos.push(argumentoResolvido);
|
|
26945
|
+
}
|
|
26946
|
+
let textoArgumentos = argumentosResolvidos.reduce((atual, proximo) => atual += proximo + ', ', "");
|
|
26947
|
+
textoArgumentos = textoArgumentos.slice(0, -2);
|
|
26948
|
+
switch (variavel.simbolo.lexema) {
|
|
26949
|
+
case 'texto':
|
|
26950
|
+
return `str(${textoArgumentos})`;
|
|
26951
|
+
default:
|
|
26952
|
+
if (argumentosValidados.length === 0 && !this.classesConhecidas.includes(variavel.simbolo.lexema)) {
|
|
26953
|
+
return `${variavel.simbolo.lexema}`;
|
|
26954
|
+
}
|
|
26955
|
+
return `${variavel.simbolo.lexema}(${textoArgumentos})`;
|
|
26956
|
+
}
|
|
26815
26957
|
}
|
|
26816
26958
|
traduzirConstrutoVetor(vetor) {
|
|
26817
26959
|
if (!vetor.valores.length) {
|
|
@@ -26861,11 +27003,14 @@ class TradutorPython {
|
|
|
26861
27003
|
resultado += `${declaracaoClasse.simbolo.lexema}(${declaracaoClasse.superClasse.simbolo.lexema}):\n`;
|
|
26862
27004
|
else
|
|
26863
27005
|
resultado += declaracaoClasse.simbolo.lexema + ':\n';
|
|
26864
|
-
if (declaracaoClasse.metodos.length === 0)
|
|
27006
|
+
if (declaracaoClasse.metodos.length === 0) {
|
|
27007
|
+
this.classesConhecidas.push(declaracaoClasse.simbolo.lexema);
|
|
26865
27008
|
return (resultado += ' pass\n');
|
|
27009
|
+
}
|
|
26866
27010
|
for (let metodo of declaracaoClasse.metodos) {
|
|
26867
27011
|
resultado += this.logicaTraducaoMetodoClasse(metodo);
|
|
26868
27012
|
}
|
|
27013
|
+
this.classesConhecidas.push(declaracaoClasse.simbolo.lexema);
|
|
26869
27014
|
return resultado;
|
|
26870
27015
|
}
|
|
26871
27016
|
traduzirDeclaracaoConst(declaracaoConst) {
|
|
@@ -27040,7 +27185,7 @@ class TradutorPython {
|
|
|
27040
27185
|
let resultado = declaracaoVar.simbolo.lexema + ' = ';
|
|
27041
27186
|
const inicializador = declaracaoVar.inicializador;
|
|
27042
27187
|
if (inicializador) {
|
|
27043
|
-
if (
|
|
27188
|
+
if (inicializador.constructor.name in this.dicionarioConstrutos) {
|
|
27044
27189
|
resultado += this.dicionarioConstrutos[declaracaoVar.inicializador.constructor.name](declaracaoVar.inicializador);
|
|
27045
27190
|
}
|
|
27046
27191
|
else {
|
|
@@ -27054,6 +27199,7 @@ class TradutorPython {
|
|
|
27054
27199
|
}
|
|
27055
27200
|
traduzir(declaracoes) {
|
|
27056
27201
|
let resultado = '';
|
|
27202
|
+
this.classesConhecidas = [];
|
|
27057
27203
|
try {
|
|
27058
27204
|
for (const declaracao of declaracoes) {
|
|
27059
27205
|
resultado += `${this.dicionarioDeclaracoes[declaracao.constructor.name](declaracao)} \n`;
|