@designliquido/delegua 0.36.1 → 0.36.2
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 +69 -69
- package/analisador-semantico/analisador-semantico-base.js +180 -180
- package/analisador-semantico/analisador-semantico.d.ts +59 -59
- package/analisador-semantico/analisador-semantico.js +442 -442
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/analisador-semantico/index.d.ts +3 -3
- package/analisador-semantico/index.js +19 -19
- package/analisador-semantico/pilha-variaveis.d.ts +20 -20
- package/analisador-semantico/pilha-variaveis.js +25 -25
- package/avaliador-sintatico/avaliador-sintatico-base.d.ts +69 -69
- package/avaliador-sintatico/avaliador-sintatico-base.js +223 -223
- package/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts +126 -126
- package/avaliador-sintatico/avaliador-sintatico.js +1093 -1093
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +73 -73
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +648 -648
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.d.ts +21 -21
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.js +149 -149
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +87 -87
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +770 -770
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.d.ts +34 -34
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.js +168 -168
- package/avaliador-sintatico/dialetos/avaliador-sintatico-portugol-ipt.js.map +1 -1
- package/avaliador-sintatico/dialetos/index.d.ts +3 -3
- package/avaliador-sintatico/dialetos/index.js +19 -19
- package/avaliador-sintatico/erro-avaliador-sintatico.d.ts +5 -5
- package/avaliador-sintatico/erro-avaliador-sintatico.js +11 -11
- package/avaliador-sintatico/index.d.ts +6 -6
- package/avaliador-sintatico/index.js +22 -22
- package/avaliador-sintatico/micro-avaliador-sintatico-base.d.ts +27 -27
- package/avaliador-sintatico/micro-avaliador-sintatico-base.js +116 -116
- package/avaliador-sintatico/micro-avaliador-sintatico-base.js.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.d.ts +33 -33
- package/avaliador-sintatico/micro-avaliador-sintatico.js +287 -287
- package/avaliador-sintatico/micro-avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/retornos/index.d.ts +3 -3
- package/avaliador-sintatico/retornos/index.js +19 -19
- package/avaliador-sintatico/retornos/retorno-declaracao.d.ts +3 -3
- package/avaliador-sintatico/retornos/retorno-declaracao.js +2 -2
- package/avaliador-sintatico/retornos/retorno-primario.d.ts +3 -3
- package/avaliador-sintatico/retornos/retorno-primario.js +2 -2
- package/avaliador-sintatico/retornos/retorno-resolver-declaracao.d.ts +2 -2
- package/avaliador-sintatico/retornos/retorno-resolver-declaracao.js +2 -2
- package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.d.ts +59 -59
- package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.js +150 -150
- package/bibliotecas/biblioteca-global.d.ts +157 -157
- package/bibliotecas/biblioteca-global.js +497 -498
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.d.ts +1 -1
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.js +236 -236
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/egua-classico/index.d.ts +2 -2
- package/bibliotecas/dialetos/egua-classico/index.js +32 -32
- package/bibliotecas/dialetos/egua-classico/index.js.map +1 -1
- package/bibliotecas/dialetos/egua-classico/matematica.d.ts +1 -1
- package/bibliotecas/dialetos/egua-classico/matematica.js +541 -541
- package/bibliotecas/dialetos/egua-classico/matematica.js.map +1 -1
- package/bibliotecas/dialetos/egua-classico/tempo.d.ts +1 -1
- package/bibliotecas/dialetos/egua-classico/tempo.js +39 -39
- package/bibliotecas/dialetos/egua-classico/tempo.js.map +1 -1
- package/bibliotecas/dialetos/egua-classico/textos.d.ts +8 -8
- package/bibliotecas/dialetos/egua-classico/textos.js +201 -201
- package/bibliotecas/dialetos/egua-classico/textos.js.map +1 -1
- package/bibliotecas/primitivas-dicionario.d.ts +6 -6
- package/bibliotecas/primitivas-dicionario.d.ts.map +1 -1
- package/bibliotecas/primitivas-dicionario.js +10 -10
- package/bibliotecas/primitivas-numero.d.ts +6 -6
- package/bibliotecas/primitivas-numero.d.ts.map +1 -1
- package/bibliotecas/primitivas-numero.js +10 -10
- package/bibliotecas/primitivas-texto.d.ts +17 -17
- package/bibliotecas/primitivas-texto.d.ts.map +1 -1
- package/bibliotecas/primitivas-texto.js +22 -22
- package/bibliotecas/primitivas-texto.js.map +1 -1
- package/bibliotecas/primitivas-vetor.d.ts +21 -21
- package/bibliotecas/primitivas-vetor.d.ts.map +1 -1
- package/bibliotecas/primitivas-vetor.js +90 -90
- package/bibliotecas/primitivas-vetor.js.map +1 -1
- package/bin/package.json +5 -4
- package/construtos/acesso-elemento-matriz.d.ts +12 -12
- package/construtos/acesso-elemento-matriz.js +17 -17
- package/construtos/acesso-indice-variavel.d.ts +15 -15
- package/construtos/acesso-indice-variavel.js +20 -20
- package/construtos/acesso-metodo-ou-propriedade.d.ts +14 -14
- package/construtos/acesso-metodo-ou-propriedade.js +19 -19
- package/construtos/agrupamento.d.ts +14 -14
- package/construtos/agrupamento.js +19 -19
- package/construtos/atribuicao-por-indice.d.ts +11 -11
- package/construtos/atribuicao-por-indice.js +16 -16
- package/construtos/atribuicao-por-indices-matriz.d.ts +12 -12
- package/construtos/atribuicao-por-indices-matriz.js +17 -17
- package/construtos/atribuir.d.ts +15 -15
- package/construtos/atribuir.js +24 -24
- package/construtos/atribuir.js.map +1 -1
- package/construtos/binario.d.ts +33 -33
- package/construtos/binario.js +38 -38
- package/construtos/chamada.d.ts +15 -15
- package/construtos/chamada.js +21 -21
- package/construtos/comentario.d.ts +15 -15
- package/construtos/comentario.js +20 -20
- package/construtos/constante.d.ts +12 -12
- package/construtos/constante.js +17 -17
- package/construtos/construto.d.ts +7 -7
- package/construtos/construto.js +2 -2
- package/construtos/decorador.d.ts +14 -14
- package/construtos/decorador.js +19 -19
- package/construtos/definir-valor.d.ts +11 -11
- package/construtos/definir-valor.js +16 -16
- package/construtos/dicionario.d.ts +10 -10
- package/construtos/dicionario.js +15 -15
- package/construtos/expressao-regular.d.ts +10 -10
- package/construtos/expressao-regular.js +15 -15
- package/construtos/fim-para.d.ts +22 -22
- package/construtos/fim-para.js +25 -25
- package/construtos/formatacao-escrita.d.ts +16 -16
- package/construtos/formatacao-escrita.js +21 -21
- package/construtos/funcao.d.ts +12 -12
- package/construtos/funcao.js +16 -16
- package/construtos/index.d.ts +29 -29
- package/construtos/index.js +45 -45
- package/construtos/isto.d.ts +9 -9
- package/construtos/isto.js +14 -14
- package/construtos/literal.d.ts +10 -10
- package/construtos/literal.js +14 -14
- package/construtos/logico.d.ts +11 -11
- package/construtos/logico.js +16 -16
- package/construtos/qual-tipo.d.ts +11 -11
- package/construtos/qual-tipo.js +16 -16
- package/construtos/super.d.ts +10 -10
- package/construtos/super.js +15 -15
- package/construtos/tipo-de.d.ts +10 -10
- package/construtos/tipo-de.js +15 -15
- package/construtos/tuplas/deceto.d.ts +18 -18
- package/construtos/tuplas/deceto.js +32 -32
- package/construtos/tuplas/dupla.d.ts +6 -6
- package/construtos/tuplas/dupla.js +12 -12
- package/construtos/tuplas/index.d.ts +13 -13
- package/construtos/tuplas/index.js +67 -67
- package/construtos/tuplas/index.js.map +1 -1
- package/construtos/tuplas/noneto.d.ts +15 -15
- package/construtos/tuplas/noneto.js +25 -25
- package/construtos/tuplas/octeto.d.ts +14 -14
- package/construtos/tuplas/octeto.js +24 -24
- package/construtos/tuplas/quarteto.d.ts +8 -8
- package/construtos/tuplas/quarteto.js +14 -14
- package/construtos/tuplas/quinteto.d.ts +9 -9
- package/construtos/tuplas/quinteto.js +15 -15
- package/construtos/tuplas/septeto.d.ts +13 -13
- package/construtos/tuplas/septeto.js +23 -23
- package/construtos/tuplas/sexteto.d.ts +10 -10
- package/construtos/tuplas/sexteto.js +16 -16
- package/construtos/tuplas/trio.d.ts +7 -7
- package/construtos/tuplas/trio.js +13 -13
- package/construtos/tuplas/tupla.d.ts +8 -8
- package/construtos/tuplas/tupla.js +9 -9
- package/construtos/unario.d.ts +11 -11
- package/construtos/unario.js +16 -16
- package/construtos/variavel.d.ts +9 -9
- package/construtos/variavel.js +14 -14
- package/construtos/vetor.d.ts +11 -11
- package/construtos/vetor.js +21 -21
- package/construtos/vetor.js.map +1 -1
- package/declaracoes/aleatorio.d.ts +15 -15
- package/declaracoes/aleatorio.js +15 -15
- package/declaracoes/bloco.d.ts +7 -7
- package/declaracoes/bloco.js +14 -14
- package/declaracoes/cabecalho-programa.d.ts +7 -7
- package/declaracoes/cabecalho-programa.js +14 -14
- package/declaracoes/classe.d.ts +14 -14
- package/declaracoes/classe.js +18 -18
- package/declaracoes/const-multiplo.d.ts +14 -14
- package/declaracoes/const-multiplo.js +19 -19
- package/declaracoes/const.d.ts +14 -14
- package/declaracoes/const.js +19 -19
- package/declaracoes/continua.d.ts +6 -6
- package/declaracoes/continua.js +13 -13
- package/declaracoes/declaracao.d.ts +8 -8
- package/declaracoes/declaracao.js +17 -17
- package/declaracoes/enquanto.d.ts +10 -10
- package/declaracoes/enquanto.js +15 -15
- package/declaracoes/escolha.d.ts +14 -14
- package/declaracoes/escolha.js +19 -19
- package/declaracoes/escreva-mesma-linha.d.ts +8 -8
- package/declaracoes/escreva-mesma-linha.js +14 -14
- package/declaracoes/escreva.d.ts +8 -8
- package/declaracoes/escreva.js +14 -14
- package/declaracoes/expressao.d.ts +8 -8
- package/declaracoes/expressao.js +14 -14
- package/declaracoes/falhar.d.ts +8 -8
- package/declaracoes/falhar.js +15 -15
- package/declaracoes/fazer.d.ts +10 -10
- package/declaracoes/fazer.js +15 -15
- package/declaracoes/funcao.d.ts +11 -11
- package/declaracoes/funcao.js +17 -17
- package/declaracoes/importar.d.ts +9 -9
- package/declaracoes/importar.js +15 -15
- package/declaracoes/index.d.ts +31 -31
- package/declaracoes/index.js +47 -47
- package/declaracoes/inicio-algoritmo.d.ts +6 -6
- package/declaracoes/inicio-algoritmo.js +13 -13
- package/declaracoes/leia-multiplo.d.ts +14 -14
- package/declaracoes/leia-multiplo.js +21 -21
- package/declaracoes/leia.d.ts +17 -17
- package/declaracoes/leia.js +21 -21
- package/declaracoes/para-cada.d.ts +11 -11
- package/declaracoes/para-cada.js +17 -17
- package/declaracoes/para.d.ts +19 -19
- package/declaracoes/para.js +24 -24
- package/declaracoes/propriedade-classe.d.ts +10 -10
- package/declaracoes/propriedade-classe.js +16 -16
- package/declaracoes/retorna.d.ts +8 -8
- package/declaracoes/retorna.js +15 -15
- package/declaracoes/se.d.ts +11 -11
- package/declaracoes/se.js +17 -17
- package/declaracoes/sustar.d.ts +6 -6
- package/declaracoes/sustar.js +13 -13
- package/declaracoes/tendo-como.d.ts +16 -16
- package/declaracoes/tendo-como.js +21 -21
- package/declaracoes/tente.d.ts +14 -14
- package/declaracoes/tente.js +20 -20
- package/declaracoes/var-multiplo.d.ts +15 -15
- package/declaracoes/var-multiplo.js +20 -20
- package/declaracoes/var.d.ts +16 -16
- package/declaracoes/var.js +21 -21
- package/depuracao/cyrb53.d.ts +9 -9
- package/depuracao/cyrb53.js +22 -22
- package/depuracao/cyrb53.js.map +1 -1
- package/depuracao/index.d.ts +2 -2
- package/depuracao/index.js +23 -23
- package/depuracao/ponto-parada.d.ts +4 -4
- package/depuracao/ponto-parada.js +2 -2
- package/espaco-variaveis.d.ts +19 -19
- package/espaco-variaveis.js +19 -19
- package/estruturas/chamavel.d.ts +7 -7
- package/estruturas/chamavel.js +12 -12
- package/estruturas/classe-padrao.d.ts +31 -31
- package/estruturas/classe-padrao.js +39 -39
- package/estruturas/delegua-funcao.d.ts +29 -29
- package/estruturas/delegua-funcao.js +141 -141
- package/estruturas/delegua-funcao.js.map +1 -1
- package/estruturas/descritor-tipo-classe.d.ts +37 -37
- package/estruturas/descritor-tipo-classe.js +79 -79
- package/estruturas/descritor-tipo-classe.js.map +1 -1
- package/estruturas/funcao-padrao.d.ts +23 -23
- package/estruturas/funcao-padrao.js +34 -34
- package/estruturas/index.d.ts +9 -9
- package/estruturas/index.js +25 -25
- package/estruturas/metodo-primitiva.d.ts +28 -28
- package/estruturas/metodo-primitiva.js +40 -40
- package/estruturas/modulo.d.ts +18 -18
- package/estruturas/modulo.js +24 -24
- package/estruturas/objeto-delegua-classe.d.ts +26 -26
- package/estruturas/objeto-delegua-classe.js +53 -53
- package/estruturas/objeto-delegua-classe.js.map +1 -1
- package/estruturas/objeto-padrao.d.ts +18 -18
- package/estruturas/objeto-padrao.js +32 -32
- package/estruturas/objeto-padrao.js.map +1 -1
- package/excecoes/erro-em-tempo-de-execucao.d.ts +7 -7
- package/excecoes/erro-em-tempo-de-execucao.js +13 -13
- package/excecoes/index.d.ts +1 -1
- package/excecoes/index.js +17 -17
- package/formatadores/formatador-delegua.d.ts +79 -79
- package/formatadores/formatador-delegua.js +676 -676
- package/formatadores/formatador-delegua.js.map +1 -1
- package/formatadores/index.d.ts +1 -1
- package/formatadores/index.js +17 -17
- package/geracao-identificadores/index.d.ts +1 -1
- package/geracao-identificadores/index.js +22 -23
- package/geracao-identificadores/index.js.map +1 -1
- package/index.d.ts +9 -9
- package/index.js +27 -27
- package/interfaces/analisador-semantico-interface.d.ts +6 -6
- package/interfaces/analisador-semantico-interface.js +2 -2
- package/interfaces/avaliador-sintatico-interface.d.ts +55 -55
- package/interfaces/avaliador-sintatico-interface.js +2 -2
- package/interfaces/construtos/index.d.ts +4 -4
- package/interfaces/construtos/index.js +2 -2
- package/interfaces/erros/diagnostico-analisador-semantico.d.ts +14 -14
- package/interfaces/erros/diagnostico-analisador-semantico.js +10 -10
- package/interfaces/erros/diagnostico-analisador-semantico.js.map +1 -1
- package/interfaces/erros/erro-interpretador.d.ts +8 -8
- package/interfaces/erros/erro-interpretador.js +2 -2
- package/interfaces/erros/index.d.ts +1 -1
- package/interfaces/erros/index.js +17 -17
- package/interfaces/escopo-execucao.d.ts +12 -12
- package/interfaces/escopo-execucao.js +2 -2
- package/interfaces/formatador-comum-interface.d.ts +11 -11
- package/interfaces/formatador-comum-interface.js +2 -2
- package/interfaces/funcao-hipotetica-interface.d.ts +3 -3
- package/interfaces/funcao-hipotetica-interface.js +2 -2
- package/interfaces/index.d.ts +16 -16
- package/interfaces/index.js +32 -32
- package/interfaces/interpretador-com-depuracao-interface.d.ts +17 -17
- package/interfaces/interpretador-com-depuracao-interface.js +2 -2
- package/interfaces/interpretador-interface-potigol.d.ts +5 -5
- package/interfaces/interpretador-interface-potigol.js +2 -2
- package/interfaces/interpretador-interface.d.ts +20 -20
- package/interfaces/interpretador-interface.js +2 -2
- package/interfaces/lexador-interface.d.ts +23 -23
- package/interfaces/lexador-interface.js +2 -2
- package/interfaces/parametro-interface.d.ts +15 -15
- package/interfaces/parametro-interface.js +2 -2
- package/interfaces/pilha-escopos-execucao-interface.d.ts +26 -26
- package/interfaces/pilha-escopos-execucao-interface.js +2 -2
- package/interfaces/pilha-interface.d.ts +7 -7
- package/interfaces/pilha-interface.js +2 -2
- package/interfaces/resolvedor-interface.d.ts +41 -41
- package/interfaces/resolvedor-interface.js +2 -2
- package/interfaces/retornos/index.d.ts +4 -4
- package/interfaces/retornos/index.js +20 -20
- package/interfaces/retornos/retorno-analisador-semantico.d.ts +4 -4
- package/interfaces/retornos/retorno-analisador-semantico.js +2 -2
- package/interfaces/retornos/retorno-avaliador-sintatico.d.ts +5 -5
- package/interfaces/retornos/retorno-avaliador-sintatico.js +2 -2
- package/interfaces/retornos/retorno-execucao-interface.d.ts +5 -5
- package/interfaces/retornos/retorno-execucao-interface.js +2 -2
- package/interfaces/retornos/retorno-interpretador.d.ts +5 -5
- package/interfaces/retornos/retorno-interpretador.js +2 -2
- package/interfaces/retornos/retorno-lexador.d.ts +9 -9
- package/interfaces/retornos/retorno-lexador.js +2 -2
- package/interfaces/simbolo-interface.d.ts +7 -7
- package/interfaces/simbolo-interface.js +2 -2
- package/interfaces/tradutor-interface.d.ts +3 -3
- package/interfaces/tradutor-interface.js +2 -2
- package/interfaces/variavel-hipotetica-interface.d.ts +8 -8
- package/interfaces/variavel-hipotetica-interface.js +2 -2
- package/interfaces/variavel-interface.d.ts +8 -8
- package/interfaces/variavel-interface.js +2 -2
- package/interfaces/visitante-comum-interface.d.ts +58 -58
- package/interfaces/visitante-comum-interface.js +2 -2
- package/interpretador/argumento-interface.d.ts +4 -4
- package/interpretador/argumento-interface.js +2 -2
- package/interpretador/comum.d.ts +2 -2
- package/interpretador/comum.js +51 -52
- package/interpretador/comum.js.map +1 -1
- package/interpretador/dialetos/egua-classico/index.d.ts +1 -1
- package/interpretador/dialetos/egua-classico/index.js +17 -17
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.d.ts +119 -119
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js +815 -815
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/erro-resolvedor.d.ts +5 -5
- package/interpretador/dialetos/egua-classico/resolvedor/erro-resolvedor.js +11 -11
- package/interpretador/dialetos/egua-classico/resolvedor/index.d.ts +3 -3
- package/interpretador/dialetos/egua-classico/resolvedor/index.js +19 -19
- package/interpretador/dialetos/egua-classico/resolvedor/pilha-escopos.d.ts +9 -9
- package/interpretador/dialetos/egua-classico/resolvedor/pilha-escopos.js +25 -25
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts +106 -106
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js +441 -441
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/retorno-resolvedor.d.ts +6 -6
- package/interpretador/dialetos/egua-classico/resolvedor/retorno-resolvedor.js +2 -2
- package/interpretador/dialetos/index.d.ts +2 -2
- package/interpretador/dialetos/index.js +18 -18
- package/interpretador/dialetos/portugol-ipt/index.d.ts +1 -1
- package/interpretador/dialetos/portugol-ipt/index.js +17 -17
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.d.ts +133 -133
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js +501 -501
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js.map +1 -1
- package/interpretador/index.d.ts +3 -3
- package/interpretador/index.js +19 -19
- package/interpretador/inferenciador.d.ts +15 -15
- package/interpretador/inferenciador.d.ts.map +1 -1
- package/interpretador/inferenciador.js +80 -80
- package/interpretador/inferenciador.js.map +1 -1
- package/interpretador/interpretador-base.d.ts +268 -268
- package/interpretador/interpretador-base.js +1399 -1399
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador-com-depuracao.d.ts +190 -190
- package/interpretador/interpretador-com-depuracao.js +568 -568
- package/interpretador/interpretador-com-depuracao.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts +39 -39
- package/interpretador/pilha-escopos-execucao.js +243 -243
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/lexador/dialetos/index.d.ts +4 -4
- package/lexador/dialetos/index.js +20 -20
- package/lexador/dialetos/lexador-egua-classico.d.ts +36 -36
- package/lexador/dialetos/lexador-egua-classico.js +286 -286
- package/lexador/dialetos/lexador-egua-classico.js.map +1 -1
- package/lexador/dialetos/lexador-guarani.d.ts +10 -10
- package/lexador/dialetos/lexador-guarani.js +113 -113
- package/lexador/dialetos/lexador-guarani.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts +51 -51
- package/lexador/dialetos/lexador-pitugues.js +398 -398
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/lexador/dialetos/lexador-portugol-ipt.d.ts +33 -33
- package/lexador/dialetos/lexador-portugol-ipt.js +237 -237
- package/lexador/dialetos/lexador-portugol-ipt.js.map +1 -1
- package/lexador/dialetos/palavras-reservadas/egua-classico.d.ts +32 -32
- package/lexador/dialetos/palavras-reservadas/egua-classico.js +39 -39
- package/lexador/dialetos/palavras-reservadas/guarani.d.ts +3 -3
- package/lexador/dialetos/palavras-reservadas/guarani.js +10 -10
- package/lexador/dialetos/palavras-reservadas/portugol-ipt.d.ts +13 -13
- package/lexador/dialetos/palavras-reservadas/portugol-ipt.js +20 -20
- package/lexador/dialetos/palavras-reservadas/rantiaquin.d.ts +1 -1
- package/lexador/dialetos/palavras-reservadas/rantiaquin.js +4 -4
- package/lexador/dialetos/pragma.d.ts +8 -8
- package/lexador/dialetos/pragma.js +2 -2
- package/lexador/erro-lexador.d.ts +5 -5
- package/lexador/erro-lexador.js +2 -2
- package/lexador/index.d.ts +4 -4
- package/lexador/index.js +20 -20
- package/lexador/lexador-base-linha-unica.d.ts +28 -28
- package/lexador/lexador-base-linha-unica.js +82 -82
- package/lexador/lexador-base-linha-unica.js.map +1 -1
- package/lexador/lexador-base.d.ts +41 -41
- package/lexador/lexador-base.js +112 -112
- package/lexador/lexador-base.js.map +1 -1
- package/lexador/lexador.d.ts +43 -43
- package/lexador/lexador.js +440 -440
- package/lexador/lexador.js.map +1 -1
- package/lexador/micro-lexador.d.ts +29 -29
- package/lexador/micro-lexador.js +207 -207
- package/lexador/micro-lexador.js.map +1 -1
- package/lexador/palavras-reservadas.d.ts +54 -54
- package/lexador/palavras-reservadas.js +61 -61
- package/lexador/simbolo.d.ts +10 -10
- package/lexador/simbolo.js +16 -16
- package/lexador/traducao/lexador-javascript.d.ts +28 -28
- package/lexador/traducao/lexador-javascript.js +58 -58
- package/package.json +5 -4
- package/quebras/index.d.ts +10 -10
- package/quebras/index.js +19 -19
- package/tipo-dados-elementar.d.ts +1 -1
- package/tipo-dados-elementar.js +2 -2
- package/tipos-de-dados/delegua.d.ts +18 -18
- package/tipos-de-dados/delegua.js +19 -19
- package/tipos-de-dados/listas-delegua.d.ts +6 -6
- package/tipos-de-dados/listas-delegua.js +7 -7
- package/tipos-de-dados/listas-primitivos.d.ts +5 -5
- package/tipos-de-dados/listas-primitivos.js +6 -6
- package/tipos-de-dados/primitivos.d.ts +16 -16
- package/tipos-de-dados/primitivos.js +17 -17
- package/tipos-de-simbolos/comum.d.ts +23 -23
- package/tipos-de-simbolos/comum.js +24 -24
- package/tipos-de-simbolos/delegua.d.ts +91 -91
- package/tipos-de-simbolos/delegua.js +92 -92
- package/tipos-de-simbolos/egua-classico.d.ts +75 -75
- package/tipos-de-simbolos/egua-classico.js +76 -76
- package/tipos-de-simbolos/guarani.d.ts +14 -14
- package/tipos-de-simbolos/guarani.js +15 -15
- package/tipos-de-simbolos/guarani.js.map +1 -1
- package/tipos-de-simbolos/microgramaticas/delegua.d.ts +46 -46
- package/tipos-de-simbolos/microgramaticas/delegua.js +47 -47
- package/tipos-de-simbolos/pitugues.d.ts +75 -75
- package/tipos-de-simbolos/pitugues.js +76 -76
- package/tipos-de-simbolos/portugol-ipt.d.ts +36 -36
- package/tipos-de-simbolos/portugol-ipt.js +37 -37
- package/tipos-de-simbolos/rantiaquin.d.ts +2 -2
- package/tipos-de-simbolos/rantiaquin.js +3 -3
- package/tradutores/dicionarios/dicionario-delegua-javascript.d.ts +2 -2
- package/tradutores/dicionarios/dicionario-delegua-javascript.js +10 -10
- package/tradutores/dicionarios/index.d.ts +1 -1
- package/tradutores/dicionarios/index.js +17 -17
- package/tradutores/index.d.ts +6 -6
- package/tradutores/index.js +22 -22
- package/tradutores/python/python3-lexer.d.ts +152 -152
- package/tradutores/python/python3-lexer.js +1227 -1227
- package/tradutores/python/python3-lexer.js.map +1 -1
- package/tradutores/python/python3-listener.d.ts +964 -964
- package/tradutores/python/python3-listener.js +3 -3
- package/tradutores/python/python3-parser.d.ts +1342 -1342
- package/tradutores/python/python3-parser.js +11226 -11226
- package/tradutores/python/python3-parser.js.map +1 -1
- package/tradutores/python/python3-visitor.d.ts +619 -619
- package/tradutores/python/python3-visitor.js +3 -3
- package/tradutores/tradutor-assembly-x64.d.ts +19 -19
- package/tradutores/tradutor-assembly-x64.js +128 -128
- package/tradutores/tradutor-assembly-x64.js.map +1 -1
- package/tradutores/tradutor-assemblyscript.d.ts +91 -91
- package/tradutores/tradutor-assemblyscript.js +590 -590
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-javascript.d.ts +95 -95
- package/tradutores/tradutor-javascript.js +577 -577
- package/tradutores/tradutor-javascript.js.map +1 -1
- package/tradutores/tradutor-portugol-ipt.d.ts +21 -21
- package/tradutores/tradutor-portugol-ipt.js +60 -60
- package/tradutores/tradutor-portugol-ipt.js.map +1 -1
- package/tradutores/tradutor-python.d.ts +65 -65
- package/tradutores/tradutor-python.js +461 -461
- package/tradutores/tradutor-python.js.map +1 -1
- package/tradutores/tradutor-reverso-javascript.d.ts +50 -50
- package/tradutores/tradutor-reverso-javascript.js +392 -392
- package/tradutores/tradutor-reverso-javascript.js.map +1 -1
- package/tradutores/tradutor-reverso-python.d.ts +32 -32
- package/tradutores/tradutor-reverso-python.js +71 -71
- package/tradutores/tradutor-reverso-python.js.map +1 -1
- package/umd/delegua.js +26337 -26340
|
@@ -1,816 +1,816 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.InterpretadorEguaClassico = void 0;
|
|
7
|
-
const espaco_variaveis_1 = require("../../../espaco-variaveis");
|
|
8
|
-
const chamavel_1 = require("../../../estruturas/chamavel");
|
|
9
|
-
const descritor_tipo_classe_1 = require("../../../estruturas/descritor-tipo-classe");
|
|
10
|
-
const delegua_funcao_1 = require("../../../estruturas/delegua-funcao");
|
|
11
|
-
const funcao_padrao_1 = require("../../../estruturas/funcao-padrao");
|
|
12
|
-
const modulo_1 = require("../../../estruturas/modulo");
|
|
13
|
-
const objeto_delegua_classe_1 = require("../../../estruturas/objeto-delegua-classe");
|
|
14
|
-
const excecoes_1 = require("../../../excecoes");
|
|
15
|
-
const quebras_1 = require("../../../quebras");
|
|
16
|
-
const inferenciador_1 = require("../../inferenciador");
|
|
17
|
-
const pilha_escopos_execucao_1 = require("../../pilha-escopos-execucao");
|
|
18
|
-
const egua_classico_1 = __importDefault(require("../../../tipos-de-simbolos/egua-classico"));
|
|
19
|
-
const biblioteca_global_1 = __importDefault(require("../../../bibliotecas/dialetos/egua-classico/biblioteca-global"));
|
|
20
|
-
const resolvedor_1 = require("./resolvedor/resolvedor");
|
|
21
|
-
/**
|
|
22
|
-
* O Interpretador visita todos os elementos complexos gerados pelo analisador sintático (_Parser_)
|
|
23
|
-
* e de fato executa a lógica de programação descrita no código.
|
|
24
|
-
*/
|
|
25
|
-
class InterpretadorEguaClassico {
|
|
26
|
-
constructor(diretorioBase) {
|
|
27
|
-
// Esta variável indica que propriedades de classes precisam ser
|
|
28
|
-
// declaradas para serem válidas.
|
|
29
|
-
// Égua não requer isso, mas precisamos ter o valor
|
|
30
|
-
// aqui por questões de compatibilidade com outros elementos.
|
|
31
|
-
this.requerDeclaracaoPropriedades = false;
|
|
32
|
-
this.interfaceEntradaSaida = null;
|
|
33
|
-
this.resolvedor = new resolvedor_1.ResolvedorEguaClassico();
|
|
34
|
-
this.diretorioBase = diretorioBase;
|
|
35
|
-
this.funcaoDeRetorno = console.log;
|
|
36
|
-
this.locais = new Map();
|
|
37
|
-
this.erros = [];
|
|
38
|
-
this.pilhaEscoposExecucao = new pilha_escopos_execucao_1.PilhaEscoposExecucao();
|
|
39
|
-
const escopoExecucao = {
|
|
40
|
-
declaracoes: [],
|
|
41
|
-
declaracaoAtual: 0,
|
|
42
|
-
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
43
|
-
finalizado: false,
|
|
44
|
-
tipo: 'outro',
|
|
45
|
-
emLacoRepeticao: false,
|
|
46
|
-
};
|
|
47
|
-
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
48
|
-
(0, biblioteca_global_1.default)(this, this.pilhaEscoposExecucao);
|
|
49
|
-
}
|
|
50
|
-
visitarDeclaracaoComentario(declaracao) {
|
|
51
|
-
return Promise.resolve();
|
|
52
|
-
}
|
|
53
|
-
visitarDeclaracaoTendoComo(declaracao) {
|
|
54
|
-
throw new Error('Método não implementado.');
|
|
55
|
-
}
|
|
56
|
-
visitarDeclaracaoInicioAlgoritmo(declaracao) {
|
|
57
|
-
throw new Error('Método não implementado.');
|
|
58
|
-
}
|
|
59
|
-
visitarDeclaracaoCabecalhoPrograma(declaracao) {
|
|
60
|
-
throw new Error('Método não implementado.');
|
|
61
|
-
}
|
|
62
|
-
visitarExpressaoTupla(expressao) {
|
|
63
|
-
throw new Error('Método não implementado.');
|
|
64
|
-
}
|
|
65
|
-
visitarExpressaoAcessoElementoMatriz(expressao) {
|
|
66
|
-
throw new Error('Método não implementado.');
|
|
67
|
-
}
|
|
68
|
-
visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) {
|
|
69
|
-
throw new Error('Método não implementado.');
|
|
70
|
-
}
|
|
71
|
-
visitarExpressaoExpressaoRegular(expressao) {
|
|
72
|
-
throw new Error('Método não implementado.');
|
|
73
|
-
}
|
|
74
|
-
visitarExpressaoTipoDe(expressao) {
|
|
75
|
-
throw new Error('Método não implementado.');
|
|
76
|
-
}
|
|
77
|
-
visitarExpressaoQualTipo(expressao) {
|
|
78
|
-
throw new Error('Método não implementado.');
|
|
79
|
-
}
|
|
80
|
-
visitarExpressaoFalhar(expressao) {
|
|
81
|
-
throw new Error('Método não implementado.');
|
|
82
|
-
}
|
|
83
|
-
visitarDeclaracaoParaCada(declaracao) {
|
|
84
|
-
throw new Error('Método não implementado.');
|
|
85
|
-
}
|
|
86
|
-
visitarDeclaracaoConst(declaracao) {
|
|
87
|
-
throw new Error('Método não implementado.');
|
|
88
|
-
}
|
|
89
|
-
visitarDeclaracaoConstMultiplo(declaracao) {
|
|
90
|
-
throw new Error('Método não implementado.');
|
|
91
|
-
}
|
|
92
|
-
visitarExpressaoFimPara(declaracao) {
|
|
93
|
-
throw new Error('Método não implementado.');
|
|
94
|
-
}
|
|
95
|
-
visitarExpressaoFormatacaoEscrita(declaracao) {
|
|
96
|
-
throw new Error('Método não implementado.');
|
|
97
|
-
}
|
|
98
|
-
visitarDeclaracaoEscrevaMesmaLinha(declaracao) {
|
|
99
|
-
throw new Error('Método não implementado.');
|
|
100
|
-
}
|
|
101
|
-
visitarExpressaoLeia(expressao) {
|
|
102
|
-
throw new Error('Método não implementado.');
|
|
103
|
-
}
|
|
104
|
-
visitarExpressaoLeiaMultiplo(expressao) {
|
|
105
|
-
throw new Error('Método não implementado.');
|
|
106
|
-
}
|
|
107
|
-
visitarExpressaoLiteral(expressao) {
|
|
108
|
-
return expressao.valor;
|
|
109
|
-
}
|
|
110
|
-
avaliar(expressao) {
|
|
111
|
-
return expressao.aceitar(this);
|
|
112
|
-
}
|
|
113
|
-
visitarExpressaoAgrupamento(expressao) {
|
|
114
|
-
return this.avaliar(expressao.expressao);
|
|
115
|
-
}
|
|
116
|
-
visitarDeclaracaoAleatorio(declaracao) {
|
|
117
|
-
throw new Error('Método não implementado');
|
|
118
|
-
}
|
|
119
|
-
eVerdadeiro(objeto) {
|
|
120
|
-
if (objeto === null)
|
|
121
|
-
return false;
|
|
122
|
-
if (typeof objeto === 'boolean')
|
|
123
|
-
return Boolean(objeto);
|
|
124
|
-
if (objeto.hasOwnProperty('valor')) {
|
|
125
|
-
return Boolean(objeto.valor);
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
verificarOperandoNumero(operador, operando) {
|
|
130
|
-
if (typeof operando === 'number' || operando.tipo === 'número')
|
|
131
|
-
return;
|
|
132
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operador precisa ser um número.', operador.linha);
|
|
133
|
-
}
|
|
134
|
-
async visitarExpressaoUnaria(expr) {
|
|
135
|
-
const direita = await this.avaliar(expr.direita);
|
|
136
|
-
const valor = direita.hasOwnProperty('valor') ? direita.valor : direita;
|
|
137
|
-
switch (expr.operador.tipo) {
|
|
138
|
-
case egua_classico_1.default.SUBTRACAO:
|
|
139
|
-
this.verificarOperandoNumero(expr.operador, valor);
|
|
140
|
-
return -valor;
|
|
141
|
-
case egua_classico_1.default.NEGACAO:
|
|
142
|
-
return !this.eVerdadeiro(valor);
|
|
143
|
-
case egua_classico_1.default.BIT_NOT:
|
|
144
|
-
return ~valor;
|
|
145
|
-
}
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
eIgual(esquerda, direita) {
|
|
149
|
-
if (esquerda && esquerda.tipo) {
|
|
150
|
-
if (esquerda.tipo === 'nulo' && direita.tipo && direita.tipo === 'nulo')
|
|
151
|
-
return true;
|
|
152
|
-
if (esquerda.tipo === 'nulo')
|
|
153
|
-
return false;
|
|
154
|
-
return esquerda.valor === direita.valor;
|
|
155
|
-
}
|
|
156
|
-
if (esquerda === null && direita === null)
|
|
157
|
-
return true;
|
|
158
|
-
if (esquerda === null)
|
|
159
|
-
return false;
|
|
160
|
-
return esquerda === direita;
|
|
161
|
-
}
|
|
162
|
-
verificarOperandosNumeros(operador, direita, esquerda) {
|
|
163
|
-
const tipoDireita = direita.tipo ? direita.tipo : typeof direita === 'number' ? 'número' : String(NaN);
|
|
164
|
-
const tipoEsquerda = esquerda.tipo
|
|
165
|
-
? esquerda.tipo
|
|
166
|
-
: typeof esquerda === 'number'
|
|
167
|
-
? 'número'
|
|
168
|
-
: String(NaN);
|
|
169
|
-
const tiposNumericos = ['inteiro', 'numero', 'número', 'real'];
|
|
170
|
-
if (tiposNumericos.includes(tipoDireita.toLowerCase()) && tiposNumericos.includes(tipoEsquerda.toLowerCase()))
|
|
171
|
-
return;
|
|
172
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
|
|
173
|
-
}
|
|
174
|
-
async visitarExpressaoBinaria(expressao) {
|
|
175
|
-
try {
|
|
176
|
-
const esquerda = await this.avaliar(expressao.esquerda);
|
|
177
|
-
const direita = await this.avaliar(expressao.direita);
|
|
178
|
-
const valorEsquerdo = esquerda && esquerda.hasOwnProperty('valor') ? esquerda.valor : esquerda;
|
|
179
|
-
const valorDireito = direita && direita.hasOwnProperty('valor') ? direita.valor : direita;
|
|
180
|
-
const tipoEsquerdo = esquerda && esquerda.hasOwnProperty('tipo') ? esquerda.tipo : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
|
|
181
|
-
const tipoDireito = direita && direita.hasOwnProperty('tipo') ? direita.tipo : (0, inferenciador_1.inferirTipoVariavel)(direita);
|
|
182
|
-
switch (expressao.operador.tipo) {
|
|
183
|
-
case egua_classico_1.default.EXPONENCIACAO:
|
|
184
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
185
|
-
return Math.pow(valorEsquerdo, valorDireito);
|
|
186
|
-
case egua_classico_1.default.MAIOR:
|
|
187
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
188
|
-
return Number(valorEsquerdo) > Number(valorDireito);
|
|
189
|
-
case egua_classico_1.default.MAIOR_IGUAL:
|
|
190
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
191
|
-
return Number(valorEsquerdo) >= Number(valorDireito);
|
|
192
|
-
case egua_classico_1.default.MENOR:
|
|
193
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
194
|
-
return Number(valorEsquerdo) < Number(valorDireito);
|
|
195
|
-
case egua_classico_1.default.MENOR_IGUAL:
|
|
196
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
197
|
-
return Number(valorEsquerdo) <= Number(valorDireito);
|
|
198
|
-
case egua_classico_1.default.SUBTRACAO:
|
|
199
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
200
|
-
return Number(valorEsquerdo) - Number(valorDireito);
|
|
201
|
-
case egua_classico_1.default.ADICAO:
|
|
202
|
-
if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
|
|
203
|
-
return Number(valorEsquerdo) + Number(valorDireito);
|
|
204
|
-
}
|
|
205
|
-
else if (tipoEsquerdo === 'texto' && tipoDireito === 'texto') {
|
|
206
|
-
return String(valorEsquerdo) + String(valorDireito);
|
|
207
|
-
}
|
|
208
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
|
|
209
|
-
case egua_classico_1.default.DIVISAO:
|
|
210
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
211
|
-
return Number(valorEsquerdo) / Number(valorDireito);
|
|
212
|
-
case egua_classico_1.default.MULTIPLICACAO:
|
|
213
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
214
|
-
return Number(valorEsquerdo) * Number(valorDireito);
|
|
215
|
-
case egua_classico_1.default.MODULO:
|
|
216
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
217
|
-
return Number(valorEsquerdo) % Number(valorDireito);
|
|
218
|
-
case egua_classico_1.default.BIT_AND:
|
|
219
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
220
|
-
return Number(valorEsquerdo) & Number(valorDireito);
|
|
221
|
-
case egua_classico_1.default.BIT_XOR:
|
|
222
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
223
|
-
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
224
|
-
case egua_classico_1.default.BIT_OR:
|
|
225
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
226
|
-
return Number(valorEsquerdo) | Number(valorDireito);
|
|
227
|
-
case egua_classico_1.default.MENOR_MENOR:
|
|
228
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
229
|
-
return Number(valorEsquerdo) << Number(valorDireito);
|
|
230
|
-
case egua_classico_1.default.MAIOR_MAIOR:
|
|
231
|
-
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
232
|
-
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
233
|
-
case egua_classico_1.default.DIFERENTE:
|
|
234
|
-
return !this.eIgual(valorEsquerdo, valorDireito);
|
|
235
|
-
case egua_classico_1.default.IGUAL_IGUAL:
|
|
236
|
-
return this.eIgual(valorEsquerdo, valorDireito);
|
|
237
|
-
}
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
catch (erro) {
|
|
241
|
-
return Promise.reject(erro);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
async visitarExpressaoDeChamada(expressao) {
|
|
245
|
-
const variavelEntidadeChamada = await this.avaliar(expressao.entidadeChamada);
|
|
246
|
-
if (variavelEntidadeChamada === null) {
|
|
247
|
-
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Chamada de função ou método inexistente: ' + String(expressao.entidadeChamada), expressao.linha));
|
|
248
|
-
}
|
|
249
|
-
const entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
|
|
250
|
-
? variavelEntidadeChamada.valor
|
|
251
|
-
: variavelEntidadeChamada;
|
|
252
|
-
let argumentos = [];
|
|
253
|
-
for (let i = 0; i < expressao.argumentos.length; i++) {
|
|
254
|
-
const variavelArgumento = expressao.argumentos[i];
|
|
255
|
-
const nomeArgumento = variavelArgumento.hasOwnProperty('simbolo')
|
|
256
|
-
? variavelArgumento.simbolo.lexema
|
|
257
|
-
: undefined;
|
|
258
|
-
argumentos.push({
|
|
259
|
-
nome: variavelArgumento,
|
|
260
|
-
valor: await this.avaliar(variavelArgumento),
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
|
|
264
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
|
|
265
|
-
}
|
|
266
|
-
let parametros;
|
|
267
|
-
if (entidadeChamada instanceof delegua_funcao_1.DeleguaFuncao) {
|
|
268
|
-
parametros = entidadeChamada.declaracao.parametros;
|
|
269
|
-
}
|
|
270
|
-
else if (entidadeChamada instanceof descritor_tipo_classe_1.DescritorTipoClasse) {
|
|
271
|
-
parametros = entidadeChamada.metodos.inicializacao
|
|
272
|
-
? entidadeChamada.metodos.inicializacao.declaracao.parametros
|
|
273
|
-
: [];
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
parametros = [];
|
|
277
|
-
}
|
|
278
|
-
// Isso aqui completa os parâmetros não preenchidos com nulos.
|
|
279
|
-
if (argumentos.length < entidadeChamada.aridade()) {
|
|
280
|
-
const diferenca = entidadeChamada.aridade() - argumentos.length;
|
|
281
|
-
for (let i = 0; i < diferenca; i++) {
|
|
282
|
-
argumentos.push(null);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
if (parametros && parametros.length > 0 && parametros[parametros.length - 1]['tipo'] === 'multiplo') {
|
|
287
|
-
let novosArgumentos = argumentos.slice(0, parametros.length - 1);
|
|
288
|
-
novosArgumentos = novosArgumentos.concat(argumentos.slice(parametros.length - 1, argumentos.length));
|
|
289
|
-
argumentos = novosArgumentos;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
|
|
293
|
-
return entidadeChamada.chamar(undefined, argumentos.map((a) => (a !== null && a.hasOwnProperty('valor') ? a.valor : a)), expressao.entidadeChamada.simbolo);
|
|
294
|
-
}
|
|
295
|
-
return entidadeChamada.chamar(this, argumentos);
|
|
296
|
-
}
|
|
297
|
-
async visitarExpressaoDeAtribuicao(expressao) {
|
|
298
|
-
const valor = await this.avaliar(expressao.valor);
|
|
299
|
-
this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
|
|
300
|
-
return valor;
|
|
301
|
-
}
|
|
302
|
-
procurarVariavel(simbolo, expressao) {
|
|
303
|
-
return this.pilhaEscoposExecucao.obterValorVariavel(simbolo);
|
|
304
|
-
}
|
|
305
|
-
visitarExpressaoDeVariavel(expressao) {
|
|
306
|
-
return Promise.resolve(this.procurarVariavel(expressao.simbolo, expressao));
|
|
307
|
-
}
|
|
308
|
-
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
309
|
-
return await this.avaliar(declaracao.expressao);
|
|
310
|
-
}
|
|
311
|
-
async visitarExpressaoLogica(expressao) {
|
|
312
|
-
const esquerda = await this.avaliar(expressao.esquerda);
|
|
313
|
-
if (expressao.operador.tipo === egua_classico_1.default.EM) {
|
|
314
|
-
const direita = await this.avaliar(expressao.direita);
|
|
315
|
-
if (Array.isArray(direita) || typeof direita === 'string') {
|
|
316
|
-
return direita.includes(esquerda);
|
|
317
|
-
}
|
|
318
|
-
else if (direita.constructor === Object) {
|
|
319
|
-
return esquerda in direita;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
// se um estado for verdadeiro, retorna verdadeiro
|
|
326
|
-
if (expressao.operador.tipo === egua_classico_1.default.OU) {
|
|
327
|
-
if (this.eVerdadeiro(esquerda))
|
|
328
|
-
return esquerda;
|
|
329
|
-
}
|
|
330
|
-
// se um estado for falso, retorna falso
|
|
331
|
-
if (expressao.operador.tipo === egua_classico_1.default.E) {
|
|
332
|
-
if (!this.eVerdadeiro(esquerda))
|
|
333
|
-
return esquerda;
|
|
334
|
-
}
|
|
335
|
-
return await this.avaliar(expressao.direita);
|
|
336
|
-
}
|
|
337
|
-
async visitarDeclaracaoSe(declaracao) {
|
|
338
|
-
if (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
339
|
-
return await this.executar(declaracao.caminhoEntao);
|
|
340
|
-
}
|
|
341
|
-
for (let i = 0; i < declaracao.caminhosSeSenao.length; i++) {
|
|
342
|
-
const atual = declaracao.caminhosSeSenao[i];
|
|
343
|
-
if (this.eVerdadeiro(await this.avaliar(atual.condicao))) {
|
|
344
|
-
return await this.executar(atual.caminho);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (declaracao.caminhoSenao !== null) {
|
|
348
|
-
return await this.executar(declaracao.caminhoSenao);
|
|
349
|
-
}
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
async visitarDeclaracaoPara(declaracao) {
|
|
353
|
-
if (declaracao.inicializador !== null) {
|
|
354
|
-
await this.avaliar(declaracao.inicializador);
|
|
355
|
-
}
|
|
356
|
-
while (true) {
|
|
357
|
-
if (declaracao.condicao !== null) {
|
|
358
|
-
if (!this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
try {
|
|
363
|
-
await this.executar(declaracao.corpo);
|
|
364
|
-
}
|
|
365
|
-
catch (erro) {
|
|
366
|
-
throw erro;
|
|
367
|
-
}
|
|
368
|
-
if (declaracao.incrementar !== null) {
|
|
369
|
-
await this.avaliar(declaracao.incrementar);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return null;
|
|
373
|
-
}
|
|
374
|
-
async visitarDeclaracaoFazer(declaracao) {
|
|
375
|
-
do {
|
|
376
|
-
try {
|
|
377
|
-
await this.executar(declaracao.caminhoFazer);
|
|
378
|
-
}
|
|
379
|
-
catch (erro) {
|
|
380
|
-
throw erro;
|
|
381
|
-
}
|
|
382
|
-
} while (this.eVerdadeiro(await this.avaliar(declaracao.condicaoEnquanto)));
|
|
383
|
-
}
|
|
384
|
-
async visitarDeclaracaoEscolha(declaracao) {
|
|
385
|
-
const condicaoEscolha = await this.avaliar(declaracao.identificadorOuLiteral);
|
|
386
|
-
const caminhos = declaracao.caminhos;
|
|
387
|
-
const caminhoPadrao = declaracao.caminhoPadrao;
|
|
388
|
-
let encontrado = false;
|
|
389
|
-
try {
|
|
390
|
-
for (let i = 0; i < caminhos.length; i++) {
|
|
391
|
-
const caminho = caminhos[i];
|
|
392
|
-
for (let j = 0; j < caminho.condicoes.length; j++) {
|
|
393
|
-
if ((await this.avaliar(caminho.condicoes[j])) === condicaoEscolha) {
|
|
394
|
-
encontrado = true;
|
|
395
|
-
try {
|
|
396
|
-
for (let k = 0; k < caminho.declaracoes.length; k++) {
|
|
397
|
-
await this.executar(caminho.declaracoes[k]);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
catch (erro) {
|
|
401
|
-
throw erro;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
if (caminhoPadrao !== null && encontrado === false) {
|
|
407
|
-
for (let i = 0; i < caminhoPadrao.declaracoes.length; i++) {
|
|
408
|
-
await this.executar(caminhoPadrao['declaracoes'][i]);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
catch (erro) {
|
|
413
|
-
throw erro;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
async visitarDeclaracaoTente(declaracao) {
|
|
417
|
-
let valorRetorno;
|
|
418
|
-
try {
|
|
419
|
-
let sucesso = true;
|
|
420
|
-
try {
|
|
421
|
-
valorRetorno = await this.executarBloco(declaracao.caminhoTente);
|
|
422
|
-
}
|
|
423
|
-
catch (erro) {
|
|
424
|
-
sucesso = false;
|
|
425
|
-
if (declaracao.caminhoPegue !== null) {
|
|
426
|
-
valorRetorno = await this.executarBloco(declaracao.caminhoPegue);
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
this.erros.push(erro);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
if (sucesso && declaracao.caminhoSenao !== null) {
|
|
433
|
-
valorRetorno = await this.executarBloco(declaracao.caminhoSenao);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
finally {
|
|
437
|
-
if (declaracao.caminhoFinalmente !== null)
|
|
438
|
-
valorRetorno = await this.executarBloco(declaracao.caminhoFinalmente);
|
|
439
|
-
}
|
|
440
|
-
return valorRetorno;
|
|
441
|
-
}
|
|
442
|
-
async visitarDeclaracaoEnquanto(declaracao) {
|
|
443
|
-
while (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
444
|
-
try {
|
|
445
|
-
await this.executar(declaracao.corpo);
|
|
446
|
-
}
|
|
447
|
-
catch (erro) {
|
|
448
|
-
throw erro;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return null;
|
|
452
|
-
}
|
|
453
|
-
// TODO: Implementar em `delegua-node`.
|
|
454
|
-
async visitarDeclaracaoImportar(declaracao) {
|
|
455
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Importação não suportada em núcleo da linguagem puro. Favor executar a aplicação usando o pacote NPM `delegua-node`.', declaracao.linha);
|
|
456
|
-
/* const caminhoRelativo = await this.avaliar(declaracao.caminho);
|
|
457
|
-
const caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
|
|
458
|
-
// const nomeArquivo = caminho.basename(caminhoTotal);
|
|
459
|
-
|
|
460
|
-
let dados: any = carregarModuloPorNome(caminhoRelativo);
|
|
461
|
-
if (dados) return dados;
|
|
462
|
-
|
|
463
|
-
try {
|
|
464
|
-
if (!sistemaArquivos.existsSync(caminhoTotal)) {
|
|
465
|
-
throw new ErroEmTempoDeExecucao(
|
|
466
|
-
declaracao.simboloFechamento,
|
|
467
|
-
'Não foi possível encontrar arquivo importado.',
|
|
468
|
-
declaracao.linha
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
} catch (erro) {
|
|
472
|
-
throw new ErroEmTempoDeExecucao(
|
|
473
|
-
declaracao.simboloFechamento,
|
|
474
|
-
'Não foi possível ler o arquivo.',
|
|
475
|
-
declaracao.linha
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
dados = sistemaArquivos.readFileSync(caminhoTotal).toString();
|
|
480
|
-
|
|
481
|
-
const delegua = new Delegua(this.Delegua.dialeto, false);
|
|
482
|
-
|
|
483
|
-
delegua.executar(dados);
|
|
484
|
-
|
|
485
|
-
const exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
|
|
486
|
-
|
|
487
|
-
const eDicionario = (objeto: any) => objeto.constructor === Object;
|
|
488
|
-
|
|
489
|
-
if (eDicionario(exportar)) {
|
|
490
|
-
const novoModulo = new DeleguaModulo();
|
|
491
|
-
|
|
492
|
-
const chaves = Object.keys(exportar);
|
|
493
|
-
for (let i = 0; i < chaves.length; i++) {
|
|
494
|
-
novoModulo[chaves[i]] = exportar[chaves[i]];
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
return novoModulo;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
return exportar; */
|
|
501
|
-
}
|
|
502
|
-
async visitarDeclaracaoEscreva(declaracao) {
|
|
503
|
-
try {
|
|
504
|
-
const resultadoAvaliacao = await this.avaliar(declaracao.argumentos[0]);
|
|
505
|
-
let valor = (resultadoAvaliacao === null || resultadoAvaliacao === void 0 ? void 0 : resultadoAvaliacao.hasOwnProperty('valor')) ? resultadoAvaliacao.valor : resultadoAvaliacao;
|
|
506
|
-
console.log(this.paraTexto(valor));
|
|
507
|
-
return null;
|
|
508
|
-
}
|
|
509
|
-
catch (erro) {
|
|
510
|
-
this.erros.push({
|
|
511
|
-
erroInterno: erro,
|
|
512
|
-
linha: declaracao.linha,
|
|
513
|
-
hashArquivo: declaracao.hashArquivo,
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
|
|
519
|
-
* executa as declarações empilhadas.
|
|
520
|
-
*
|
|
521
|
-
* Se o retorno do último bloco foi uma exceção (normalmente um erro em tempo de execução),
|
|
522
|
-
* atira a exceção daqui.
|
|
523
|
-
* Isso é usado, por exemplo, em blocos `tente ... pegue ... finalmente`.
|
|
524
|
-
* @param declaracoes Um vetor de declaracoes a ser executado.
|
|
525
|
-
* @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
|
|
526
|
-
*/
|
|
527
|
-
async executarBloco(declaracoes, ambiente) {
|
|
528
|
-
const escopoExecucao = {
|
|
529
|
-
declaracoes: declaracoes,
|
|
530
|
-
declaracaoAtual: 0,
|
|
531
|
-
ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
|
|
532
|
-
finalizado: false,
|
|
533
|
-
tipo: 'outro',
|
|
534
|
-
emLacoRepeticao: false,
|
|
535
|
-
};
|
|
536
|
-
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
537
|
-
const retornoUltimoEscopo = await this.executarUltimoEscopo();
|
|
538
|
-
if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
|
|
539
|
-
throw retornoUltimoEscopo;
|
|
540
|
-
}
|
|
541
|
-
return retornoUltimoEscopo;
|
|
542
|
-
}
|
|
543
|
-
async visitarExpressaoBloco(declaracao) {
|
|
544
|
-
return await this.executarBloco(declaracao.declaracoes);
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Executa expressão de definição de variável.
|
|
548
|
-
* @param declaracao A declaração Var
|
|
549
|
-
* @returns Sempre retorna nulo.
|
|
550
|
-
*/
|
|
551
|
-
async visitarDeclaracaoVar(declaracao) {
|
|
552
|
-
let valorOuOutraVariavel = null;
|
|
553
|
-
if (declaracao.inicializador !== null) {
|
|
554
|
-
valorOuOutraVariavel = await this.avaliar(declaracao.inicializador);
|
|
555
|
-
}
|
|
556
|
-
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel && valorOuOutraVariavel.hasOwnProperty('valor')
|
|
557
|
-
? valorOuOutraVariavel.valor
|
|
558
|
-
: valorOuOutraVariavel);
|
|
559
|
-
return null;
|
|
560
|
-
}
|
|
561
|
-
async visitarDeclaracaoVarMultiplo(declaracao) {
|
|
562
|
-
throw new Error('Método não implementado.');
|
|
563
|
-
}
|
|
564
|
-
visitarExpressaoContinua(declaracao) {
|
|
565
|
-
return new quebras_1.ContinuarQuebra();
|
|
566
|
-
}
|
|
567
|
-
visitarExpressaoSustar(declaracao) {
|
|
568
|
-
return new quebras_1.SustarQuebra();
|
|
569
|
-
}
|
|
570
|
-
async visitarExpressaoRetornar(declaracao) {
|
|
571
|
-
let valor = null;
|
|
572
|
-
if (declaracao.valor != null)
|
|
573
|
-
valor = await this.avaliar(declaracao.valor);
|
|
574
|
-
return new quebras_1.RetornoQuebra(valor);
|
|
575
|
-
}
|
|
576
|
-
async visitarExpressaoDeleguaFuncao(expressao) {
|
|
577
|
-
return new delegua_funcao_1.DeleguaFuncao(null, expressao);
|
|
578
|
-
}
|
|
579
|
-
async visitarExpressaoAtribuicaoPorIndice(expressao) {
|
|
580
|
-
const objeto = await this.avaliar(expressao.objeto);
|
|
581
|
-
let indice = await this.avaliar(expressao.indice);
|
|
582
|
-
const valor = await this.avaliar(expressao.valor);
|
|
583
|
-
if (Array.isArray(objeto)) {
|
|
584
|
-
if (indice < 0 && objeto.length !== 0) {
|
|
585
|
-
while (indice < 0) {
|
|
586
|
-
indice += objeto.length;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
while (objeto.length < indice) {
|
|
590
|
-
objeto.push(null);
|
|
591
|
-
}
|
|
592
|
-
objeto[indice] = valor;
|
|
593
|
-
}
|
|
594
|
-
else if (objeto.constructor === Object ||
|
|
595
|
-
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
596
|
-
objeto instanceof delegua_funcao_1.DeleguaFuncao ||
|
|
597
|
-
objeto instanceof descritor_tipo_classe_1.DescritorTipoClasse ||
|
|
598
|
-
objeto instanceof modulo_1.DeleguaModulo) {
|
|
599
|
-
objeto[indice] = valor;
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
async visitarExpressaoAcessoIndiceVariavel(expressao) {
|
|
606
|
-
const variavelObjeto = await this.avaliar(expressao.entidadeChamada);
|
|
607
|
-
const objeto = variavelObjeto.hasOwnProperty('valor') ? variavelObjeto.valor : variavelObjeto;
|
|
608
|
-
let indice = await this.avaliar(expressao.indice);
|
|
609
|
-
const valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
|
|
610
|
-
if (Array.isArray(objeto)) {
|
|
611
|
-
if (!Number.isInteger(valorIndice)) {
|
|
612
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
613
|
-
}
|
|
614
|
-
if (indice < 0 && objeto.length !== 0) {
|
|
615
|
-
while (indice < 0) {
|
|
616
|
-
indice += objeto.length;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
if (indice >= objeto.length) {
|
|
620
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
|
|
621
|
-
}
|
|
622
|
-
return objeto[indice];
|
|
623
|
-
}
|
|
624
|
-
else if (objeto.constructor === Object ||
|
|
625
|
-
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
626
|
-
objeto instanceof delegua_funcao_1.DeleguaFuncao ||
|
|
627
|
-
objeto instanceof descritor_tipo_classe_1.DescritorTipoClasse ||
|
|
628
|
-
objeto instanceof modulo_1.DeleguaModulo) {
|
|
629
|
-
return objeto[indice] || null;
|
|
630
|
-
}
|
|
631
|
-
else if (typeof objeto === 'string') {
|
|
632
|
-
if (!Number.isInteger(indice)) {
|
|
633
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
634
|
-
}
|
|
635
|
-
if (indice < 0 && objeto.length !== 0) {
|
|
636
|
-
while (indice < 0) {
|
|
637
|
-
indice += objeto.length;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (indice >= objeto.length) {
|
|
641
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
|
|
642
|
-
}
|
|
643
|
-
return objeto.charAt(indice);
|
|
644
|
-
}
|
|
645
|
-
else {
|
|
646
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
async visitarExpressaoDefinirValor(expressao) {
|
|
650
|
-
const objeto = await this.avaliar(expressao.objeto);
|
|
651
|
-
if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) && objeto.constructor !== Object) {
|
|
652
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
|
|
653
|
-
}
|
|
654
|
-
const valor = await this.avaliar(expressao.valor);
|
|
655
|
-
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
656
|
-
objeto.definir(expressao.nome, valor);
|
|
657
|
-
return valor;
|
|
658
|
-
}
|
|
659
|
-
else if (objeto.constructor === Object) {
|
|
660
|
-
objeto[expressao.simbolo.lexema] = valor;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
664
|
-
const funcao = new delegua_funcao_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
665
|
-
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
666
|
-
}
|
|
667
|
-
async visitarDeclaracaoClasse(declaracao) {
|
|
668
|
-
let superClasse = null;
|
|
669
|
-
if (declaracao.superClasse !== null) {
|
|
670
|
-
const variavelSuperClasse = await this.avaliar(declaracao.superClasse);
|
|
671
|
-
superClasse = variavelSuperClasse.valor;
|
|
672
|
-
if (!(superClasse instanceof descritor_tipo_classe_1.DescritorTipoClasse)) {
|
|
673
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'Superclasse precisa ser uma classe.', declaracao.linha);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
|
|
677
|
-
if (declaracao.superClasse !== null) {
|
|
678
|
-
this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
|
|
679
|
-
}
|
|
680
|
-
const metodos = {};
|
|
681
|
-
const definirMetodos = declaracao.metodos;
|
|
682
|
-
for (let i = 0; i < declaracao.metodos.length; i++) {
|
|
683
|
-
const metodoAtual = definirMetodos[i];
|
|
684
|
-
const eInicializador = metodoAtual.simbolo.lexema === 'construtor';
|
|
685
|
-
const funcao = new delegua_funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
|
|
686
|
-
metodos[metodoAtual.simbolo.lexema] = funcao;
|
|
687
|
-
}
|
|
688
|
-
const deleguaClasse = new descritor_tipo_classe_1.DescritorTipoClasse(declaracao.simbolo, superClasse, metodos);
|
|
689
|
-
deleguaClasse.dialetoRequerExpansaoPropriedadesEspacoVariaveis = false;
|
|
690
|
-
deleguaClasse.dialetoRequerDeclaracaoPropriedades = false;
|
|
691
|
-
// TODO: Recolocar isso se for necessário.
|
|
692
|
-
/* if (superClasse !== null) {
|
|
693
|
-
this.ambiente = this.ambiente.enclosing;
|
|
694
|
-
} */
|
|
695
|
-
this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
|
|
696
|
-
return null;
|
|
697
|
-
}
|
|
698
|
-
async visitarExpressaoAcessoMetodo(expressao) {
|
|
699
|
-
const variavelObjeto = await this.avaliar(expressao.objeto);
|
|
700
|
-
const objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
|
|
701
|
-
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
702
|
-
return objeto.obter(expressao.simbolo) || null;
|
|
703
|
-
}
|
|
704
|
-
else if (objeto.constructor === Object) {
|
|
705
|
-
return objeto[expressao.simbolo.lexema] || null;
|
|
706
|
-
}
|
|
707
|
-
else if (objeto instanceof modulo_1.DeleguaModulo) {
|
|
708
|
-
return objeto[expressao.simbolo.lexema] || null;
|
|
709
|
-
}
|
|
710
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
|
|
711
|
-
}
|
|
712
|
-
async visitarExpressaoIsto(expressao) {
|
|
713
|
-
return Promise.resolve(this.procurarVariavel(expressao.palavraChave, expressao));
|
|
714
|
-
}
|
|
715
|
-
async visitarExpressaoDicionario(expressao) {
|
|
716
|
-
const dicionario = {};
|
|
717
|
-
for (let i = 0; i < expressao.chaves.length; i++) {
|
|
718
|
-
dicionario[await this.avaliar(expressao.chaves[i])] = await this.avaliar(expressao.valores[i]);
|
|
719
|
-
}
|
|
720
|
-
return dicionario;
|
|
721
|
-
}
|
|
722
|
-
async visitarExpressaoVetor(expressao) {
|
|
723
|
-
const valores = [];
|
|
724
|
-
for (let i = 0; i < expressao.valores.length; i++) {
|
|
725
|
-
valores.push(await this.avaliar(expressao.valores[i]));
|
|
726
|
-
}
|
|
727
|
-
return valores;
|
|
728
|
-
}
|
|
729
|
-
visitarExpressaoSuper(expressao) {
|
|
730
|
-
const distancia = this.locais.get(expressao);
|
|
731
|
-
const superClasse = this.pilhaEscoposExecucao.obterVariavelEm(distancia, 'super');
|
|
732
|
-
const objeto = this.pilhaEscoposExecucao.obterVariavelEm(distancia - 1, 'isto');
|
|
733
|
-
const metodo = superClasse.valor.encontrarMetodo(expressao.metodo.lexema);
|
|
734
|
-
if (metodo === undefined) {
|
|
735
|
-
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.metodo, 'Método chamado indefinido.', expressao.linha);
|
|
736
|
-
}
|
|
737
|
-
return metodo.definirInstancia(objeto.valor);
|
|
738
|
-
}
|
|
739
|
-
paraTexto(objeto) {
|
|
740
|
-
if (objeto === null)
|
|
741
|
-
return 'nulo';
|
|
742
|
-
if (typeof objeto === 'boolean') {
|
|
743
|
-
return objeto ? 'verdadeiro' : 'falso';
|
|
744
|
-
}
|
|
745
|
-
if (objeto instanceof Date) {
|
|
746
|
-
const formato = Intl.DateTimeFormat('pt', {
|
|
747
|
-
dateStyle: 'full',
|
|
748
|
-
timeStyle: 'full',
|
|
749
|
-
});
|
|
750
|
-
return formato.format(objeto);
|
|
751
|
-
}
|
|
752
|
-
if (Array.isArray(objeto))
|
|
753
|
-
return objeto;
|
|
754
|
-
if (typeof objeto === 'object')
|
|
755
|
-
return JSON.stringify(objeto);
|
|
756
|
-
if (objeto === undefined) {
|
|
757
|
-
return 'nulo';
|
|
758
|
-
}
|
|
759
|
-
return objeto.toString();
|
|
760
|
-
}
|
|
761
|
-
async executar(declaracao, mostrarResultado = false) {
|
|
762
|
-
return await declaracao.aceitar(this);
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* Executa o último escopo empilhado no topo na pilha de escopos do Interpretador.
|
|
766
|
-
* Originalmente, Égua não trabalha com uma pilha de escopos.
|
|
767
|
-
*
|
|
768
|
-
* O tratamento das exceções é feito de acordo com o bloco chamador.
|
|
769
|
-
* Por exemplo, em `tente ... pegue ... finalmente`, a exceção é capturada e tratada.
|
|
770
|
-
* Em outros blocos, pode ser desejável ter o erro em tela.
|
|
771
|
-
*
|
|
772
|
-
* Essa implementação é derivada do Interpretador de Delégua, mas simulando todos os
|
|
773
|
-
* comportamos do interpretador Égua original.
|
|
774
|
-
* Interpretador Égua: https://github.com/eguatech/egua/blob/master/src/interpreter.js
|
|
775
|
-
* @returns O resultado da execução do escopo, se houver.
|
|
776
|
-
*/
|
|
777
|
-
async executarUltimoEscopo() {
|
|
778
|
-
const ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
|
|
779
|
-
try {
|
|
780
|
-
let retornoExecucao;
|
|
781
|
-
for (; !(retornoExecucao instanceof quebras_1.Quebra) && ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length; ultimoEscopo.declaracaoAtual++) {
|
|
782
|
-
retornoExecucao = await this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual]);
|
|
783
|
-
}
|
|
784
|
-
return retornoExecucao;
|
|
785
|
-
}
|
|
786
|
-
catch (erro) {
|
|
787
|
-
return Promise.reject(erro);
|
|
788
|
-
}
|
|
789
|
-
finally {
|
|
790
|
-
this.pilhaEscoposExecucao.removerUltimo();
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
async interpretar(declaracoes) {
|
|
794
|
-
this.erros = [];
|
|
795
|
-
const retornoResolvedor = await this.resolvedor.resolver(declaracoes);
|
|
796
|
-
this.locais = retornoResolvedor.locais;
|
|
797
|
-
const escopoExecucao = {
|
|
798
|
-
declaracoes: declaracoes,
|
|
799
|
-
declaracaoAtual: 0,
|
|
800
|
-
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
801
|
-
finalizado: false,
|
|
802
|
-
tipo: 'outro',
|
|
803
|
-
emLacoRepeticao: false,
|
|
804
|
-
};
|
|
805
|
-
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
806
|
-
await this.executarUltimoEscopo();
|
|
807
|
-
return {
|
|
808
|
-
erros: this.erros,
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
finalizacao() {
|
|
812
|
-
this.funcaoDeRetorno();
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
exports.InterpretadorEguaClassico = InterpretadorEguaClassico;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InterpretadorEguaClassico = void 0;
|
|
7
|
+
const espaco_variaveis_1 = require("../../../espaco-variaveis");
|
|
8
|
+
const chamavel_1 = require("../../../estruturas/chamavel");
|
|
9
|
+
const descritor_tipo_classe_1 = require("../../../estruturas/descritor-tipo-classe");
|
|
10
|
+
const delegua_funcao_1 = require("../../../estruturas/delegua-funcao");
|
|
11
|
+
const funcao_padrao_1 = require("../../../estruturas/funcao-padrao");
|
|
12
|
+
const modulo_1 = require("../../../estruturas/modulo");
|
|
13
|
+
const objeto_delegua_classe_1 = require("../../../estruturas/objeto-delegua-classe");
|
|
14
|
+
const excecoes_1 = require("../../../excecoes");
|
|
15
|
+
const quebras_1 = require("../../../quebras");
|
|
16
|
+
const inferenciador_1 = require("../../inferenciador");
|
|
17
|
+
const pilha_escopos_execucao_1 = require("../../pilha-escopos-execucao");
|
|
18
|
+
const egua_classico_1 = __importDefault(require("../../../tipos-de-simbolos/egua-classico"));
|
|
19
|
+
const biblioteca_global_1 = __importDefault(require("../../../bibliotecas/dialetos/egua-classico/biblioteca-global"));
|
|
20
|
+
const resolvedor_1 = require("./resolvedor/resolvedor");
|
|
21
|
+
/**
|
|
22
|
+
* O Interpretador visita todos os elementos complexos gerados pelo analisador sintático (_Parser_)
|
|
23
|
+
* e de fato executa a lógica de programação descrita no código.
|
|
24
|
+
*/
|
|
25
|
+
class InterpretadorEguaClassico {
|
|
26
|
+
constructor(diretorioBase) {
|
|
27
|
+
// Esta variável indica que propriedades de classes precisam ser
|
|
28
|
+
// declaradas para serem válidas.
|
|
29
|
+
// Égua não requer isso, mas precisamos ter o valor
|
|
30
|
+
// aqui por questões de compatibilidade com outros elementos.
|
|
31
|
+
this.requerDeclaracaoPropriedades = false;
|
|
32
|
+
this.interfaceEntradaSaida = null;
|
|
33
|
+
this.resolvedor = new resolvedor_1.ResolvedorEguaClassico();
|
|
34
|
+
this.diretorioBase = diretorioBase;
|
|
35
|
+
this.funcaoDeRetorno = console.log;
|
|
36
|
+
this.locais = new Map();
|
|
37
|
+
this.erros = [];
|
|
38
|
+
this.pilhaEscoposExecucao = new pilha_escopos_execucao_1.PilhaEscoposExecucao();
|
|
39
|
+
const escopoExecucao = {
|
|
40
|
+
declaracoes: [],
|
|
41
|
+
declaracaoAtual: 0,
|
|
42
|
+
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
43
|
+
finalizado: false,
|
|
44
|
+
tipo: 'outro',
|
|
45
|
+
emLacoRepeticao: false,
|
|
46
|
+
};
|
|
47
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
48
|
+
(0, biblioteca_global_1.default)(this, this.pilhaEscoposExecucao);
|
|
49
|
+
}
|
|
50
|
+
visitarDeclaracaoComentario(declaracao) {
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
visitarDeclaracaoTendoComo(declaracao) {
|
|
54
|
+
throw new Error('Método não implementado.');
|
|
55
|
+
}
|
|
56
|
+
visitarDeclaracaoInicioAlgoritmo(declaracao) {
|
|
57
|
+
throw new Error('Método não implementado.');
|
|
58
|
+
}
|
|
59
|
+
visitarDeclaracaoCabecalhoPrograma(declaracao) {
|
|
60
|
+
throw new Error('Método não implementado.');
|
|
61
|
+
}
|
|
62
|
+
visitarExpressaoTupla(expressao) {
|
|
63
|
+
throw new Error('Método não implementado.');
|
|
64
|
+
}
|
|
65
|
+
visitarExpressaoAcessoElementoMatriz(expressao) {
|
|
66
|
+
throw new Error('Método não implementado.');
|
|
67
|
+
}
|
|
68
|
+
visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) {
|
|
69
|
+
throw new Error('Método não implementado.');
|
|
70
|
+
}
|
|
71
|
+
visitarExpressaoExpressaoRegular(expressao) {
|
|
72
|
+
throw new Error('Método não implementado.');
|
|
73
|
+
}
|
|
74
|
+
visitarExpressaoTipoDe(expressao) {
|
|
75
|
+
throw new Error('Método não implementado.');
|
|
76
|
+
}
|
|
77
|
+
visitarExpressaoQualTipo(expressao) {
|
|
78
|
+
throw new Error('Método não implementado.');
|
|
79
|
+
}
|
|
80
|
+
visitarExpressaoFalhar(expressao) {
|
|
81
|
+
throw new Error('Método não implementado.');
|
|
82
|
+
}
|
|
83
|
+
visitarDeclaracaoParaCada(declaracao) {
|
|
84
|
+
throw new Error('Método não implementado.');
|
|
85
|
+
}
|
|
86
|
+
visitarDeclaracaoConst(declaracao) {
|
|
87
|
+
throw new Error('Método não implementado.');
|
|
88
|
+
}
|
|
89
|
+
visitarDeclaracaoConstMultiplo(declaracao) {
|
|
90
|
+
throw new Error('Método não implementado.');
|
|
91
|
+
}
|
|
92
|
+
visitarExpressaoFimPara(declaracao) {
|
|
93
|
+
throw new Error('Método não implementado.');
|
|
94
|
+
}
|
|
95
|
+
visitarExpressaoFormatacaoEscrita(declaracao) {
|
|
96
|
+
throw new Error('Método não implementado.');
|
|
97
|
+
}
|
|
98
|
+
visitarDeclaracaoEscrevaMesmaLinha(declaracao) {
|
|
99
|
+
throw new Error('Método não implementado.');
|
|
100
|
+
}
|
|
101
|
+
visitarExpressaoLeia(expressao) {
|
|
102
|
+
throw new Error('Método não implementado.');
|
|
103
|
+
}
|
|
104
|
+
visitarExpressaoLeiaMultiplo(expressao) {
|
|
105
|
+
throw new Error('Método não implementado.');
|
|
106
|
+
}
|
|
107
|
+
visitarExpressaoLiteral(expressao) {
|
|
108
|
+
return expressao.valor;
|
|
109
|
+
}
|
|
110
|
+
avaliar(expressao) {
|
|
111
|
+
return expressao.aceitar(this);
|
|
112
|
+
}
|
|
113
|
+
visitarExpressaoAgrupamento(expressao) {
|
|
114
|
+
return this.avaliar(expressao.expressao);
|
|
115
|
+
}
|
|
116
|
+
visitarDeclaracaoAleatorio(declaracao) {
|
|
117
|
+
throw new Error('Método não implementado');
|
|
118
|
+
}
|
|
119
|
+
eVerdadeiro(objeto) {
|
|
120
|
+
if (objeto === null)
|
|
121
|
+
return false;
|
|
122
|
+
if (typeof objeto === 'boolean')
|
|
123
|
+
return Boolean(objeto);
|
|
124
|
+
if (objeto.hasOwnProperty('valor')) {
|
|
125
|
+
return Boolean(objeto.valor);
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
verificarOperandoNumero(operador, operando) {
|
|
130
|
+
if (typeof operando === 'number' || operando.tipo === 'número')
|
|
131
|
+
return;
|
|
132
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operador precisa ser um número.', operador.linha);
|
|
133
|
+
}
|
|
134
|
+
async visitarExpressaoUnaria(expr) {
|
|
135
|
+
const direita = await this.avaliar(expr.direita);
|
|
136
|
+
const valor = direita.hasOwnProperty('valor') ? direita.valor : direita;
|
|
137
|
+
switch (expr.operador.tipo) {
|
|
138
|
+
case egua_classico_1.default.SUBTRACAO:
|
|
139
|
+
this.verificarOperandoNumero(expr.operador, valor);
|
|
140
|
+
return -valor;
|
|
141
|
+
case egua_classico_1.default.NEGACAO:
|
|
142
|
+
return !this.eVerdadeiro(valor);
|
|
143
|
+
case egua_classico_1.default.BIT_NOT:
|
|
144
|
+
return ~valor;
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
eIgual(esquerda, direita) {
|
|
149
|
+
if (esquerda && esquerda.tipo) {
|
|
150
|
+
if (esquerda.tipo === 'nulo' && direita.tipo && direita.tipo === 'nulo')
|
|
151
|
+
return true;
|
|
152
|
+
if (esquerda.tipo === 'nulo')
|
|
153
|
+
return false;
|
|
154
|
+
return esquerda.valor === direita.valor;
|
|
155
|
+
}
|
|
156
|
+
if (esquerda === null && direita === null)
|
|
157
|
+
return true;
|
|
158
|
+
if (esquerda === null)
|
|
159
|
+
return false;
|
|
160
|
+
return esquerda === direita;
|
|
161
|
+
}
|
|
162
|
+
verificarOperandosNumeros(operador, direita, esquerda) {
|
|
163
|
+
const tipoDireita = direita.tipo ? direita.tipo : typeof direita === 'number' ? 'número' : String(NaN);
|
|
164
|
+
const tipoEsquerda = esquerda.tipo
|
|
165
|
+
? esquerda.tipo
|
|
166
|
+
: typeof esquerda === 'number'
|
|
167
|
+
? 'número'
|
|
168
|
+
: String(NaN);
|
|
169
|
+
const tiposNumericos = ['inteiro', 'numero', 'número', 'real'];
|
|
170
|
+
if (tiposNumericos.includes(tipoDireita.toLowerCase()) && tiposNumericos.includes(tipoEsquerda.toLowerCase()))
|
|
171
|
+
return;
|
|
172
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
|
|
173
|
+
}
|
|
174
|
+
async visitarExpressaoBinaria(expressao) {
|
|
175
|
+
try {
|
|
176
|
+
const esquerda = await this.avaliar(expressao.esquerda);
|
|
177
|
+
const direita = await this.avaliar(expressao.direita);
|
|
178
|
+
const valorEsquerdo = esquerda && esquerda.hasOwnProperty('valor') ? esquerda.valor : esquerda;
|
|
179
|
+
const valorDireito = direita && direita.hasOwnProperty('valor') ? direita.valor : direita;
|
|
180
|
+
const tipoEsquerdo = esquerda && esquerda.hasOwnProperty('tipo') ? esquerda.tipo : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
|
|
181
|
+
const tipoDireito = direita && direita.hasOwnProperty('tipo') ? direita.tipo : (0, inferenciador_1.inferirTipoVariavel)(direita);
|
|
182
|
+
switch (expressao.operador.tipo) {
|
|
183
|
+
case egua_classico_1.default.EXPONENCIACAO:
|
|
184
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
185
|
+
return Math.pow(valorEsquerdo, valorDireito);
|
|
186
|
+
case egua_classico_1.default.MAIOR:
|
|
187
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
188
|
+
return Number(valorEsquerdo) > Number(valorDireito);
|
|
189
|
+
case egua_classico_1.default.MAIOR_IGUAL:
|
|
190
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
191
|
+
return Number(valorEsquerdo) >= Number(valorDireito);
|
|
192
|
+
case egua_classico_1.default.MENOR:
|
|
193
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
194
|
+
return Number(valorEsquerdo) < Number(valorDireito);
|
|
195
|
+
case egua_classico_1.default.MENOR_IGUAL:
|
|
196
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
197
|
+
return Number(valorEsquerdo) <= Number(valorDireito);
|
|
198
|
+
case egua_classico_1.default.SUBTRACAO:
|
|
199
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
200
|
+
return Number(valorEsquerdo) - Number(valorDireito);
|
|
201
|
+
case egua_classico_1.default.ADICAO:
|
|
202
|
+
if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
|
|
203
|
+
return Number(valorEsquerdo) + Number(valorDireito);
|
|
204
|
+
}
|
|
205
|
+
else if (tipoEsquerdo === 'texto' && tipoDireito === 'texto') {
|
|
206
|
+
return String(valorEsquerdo) + String(valorDireito);
|
|
207
|
+
}
|
|
208
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
|
|
209
|
+
case egua_classico_1.default.DIVISAO:
|
|
210
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
211
|
+
return Number(valorEsquerdo) / Number(valorDireito);
|
|
212
|
+
case egua_classico_1.default.MULTIPLICACAO:
|
|
213
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
214
|
+
return Number(valorEsquerdo) * Number(valorDireito);
|
|
215
|
+
case egua_classico_1.default.MODULO:
|
|
216
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
217
|
+
return Number(valorEsquerdo) % Number(valorDireito);
|
|
218
|
+
case egua_classico_1.default.BIT_AND:
|
|
219
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
220
|
+
return Number(valorEsquerdo) & Number(valorDireito);
|
|
221
|
+
case egua_classico_1.default.BIT_XOR:
|
|
222
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
223
|
+
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
224
|
+
case egua_classico_1.default.BIT_OR:
|
|
225
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
226
|
+
return Number(valorEsquerdo) | Number(valorDireito);
|
|
227
|
+
case egua_classico_1.default.MENOR_MENOR:
|
|
228
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
229
|
+
return Number(valorEsquerdo) << Number(valorDireito);
|
|
230
|
+
case egua_classico_1.default.MAIOR_MAIOR:
|
|
231
|
+
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
232
|
+
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
233
|
+
case egua_classico_1.default.DIFERENTE:
|
|
234
|
+
return !this.eIgual(valorEsquerdo, valorDireito);
|
|
235
|
+
case egua_classico_1.default.IGUAL_IGUAL:
|
|
236
|
+
return this.eIgual(valorEsquerdo, valorDireito);
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
catch (erro) {
|
|
241
|
+
return Promise.reject(erro);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async visitarExpressaoDeChamada(expressao) {
|
|
245
|
+
const variavelEntidadeChamada = await this.avaliar(expressao.entidadeChamada);
|
|
246
|
+
if (variavelEntidadeChamada === null) {
|
|
247
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Chamada de função ou método inexistente: ' + String(expressao.entidadeChamada), expressao.linha));
|
|
248
|
+
}
|
|
249
|
+
const entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
|
|
250
|
+
? variavelEntidadeChamada.valor
|
|
251
|
+
: variavelEntidadeChamada;
|
|
252
|
+
let argumentos = [];
|
|
253
|
+
for (let i = 0; i < expressao.argumentos.length; i++) {
|
|
254
|
+
const variavelArgumento = expressao.argumentos[i];
|
|
255
|
+
const nomeArgumento = variavelArgumento.hasOwnProperty('simbolo')
|
|
256
|
+
? variavelArgumento.simbolo.lexema
|
|
257
|
+
: undefined;
|
|
258
|
+
argumentos.push({
|
|
259
|
+
nome: variavelArgumento,
|
|
260
|
+
valor: await this.avaliar(variavelArgumento),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
|
|
264
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
|
|
265
|
+
}
|
|
266
|
+
let parametros;
|
|
267
|
+
if (entidadeChamada instanceof delegua_funcao_1.DeleguaFuncao) {
|
|
268
|
+
parametros = entidadeChamada.declaracao.parametros;
|
|
269
|
+
}
|
|
270
|
+
else if (entidadeChamada instanceof descritor_tipo_classe_1.DescritorTipoClasse) {
|
|
271
|
+
parametros = entidadeChamada.metodos.inicializacao
|
|
272
|
+
? entidadeChamada.metodos.inicializacao.declaracao.parametros
|
|
273
|
+
: [];
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
parametros = [];
|
|
277
|
+
}
|
|
278
|
+
// Isso aqui completa os parâmetros não preenchidos com nulos.
|
|
279
|
+
if (argumentos.length < entidadeChamada.aridade()) {
|
|
280
|
+
const diferenca = entidadeChamada.aridade() - argumentos.length;
|
|
281
|
+
for (let i = 0; i < diferenca; i++) {
|
|
282
|
+
argumentos.push(null);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
if (parametros && parametros.length > 0 && parametros[parametros.length - 1]['tipo'] === 'multiplo') {
|
|
287
|
+
let novosArgumentos = argumentos.slice(0, parametros.length - 1);
|
|
288
|
+
novosArgumentos = novosArgumentos.concat(argumentos.slice(parametros.length - 1, argumentos.length));
|
|
289
|
+
argumentos = novosArgumentos;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
|
|
293
|
+
return entidadeChamada.chamar(undefined, argumentos.map((a) => (a !== null && a.hasOwnProperty('valor') ? a.valor : a)), expressao.entidadeChamada.simbolo);
|
|
294
|
+
}
|
|
295
|
+
return entidadeChamada.chamar(this, argumentos);
|
|
296
|
+
}
|
|
297
|
+
async visitarExpressaoDeAtribuicao(expressao) {
|
|
298
|
+
const valor = await this.avaliar(expressao.valor);
|
|
299
|
+
this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
|
|
300
|
+
return valor;
|
|
301
|
+
}
|
|
302
|
+
procurarVariavel(simbolo, expressao) {
|
|
303
|
+
return this.pilhaEscoposExecucao.obterValorVariavel(simbolo);
|
|
304
|
+
}
|
|
305
|
+
visitarExpressaoDeVariavel(expressao) {
|
|
306
|
+
return Promise.resolve(this.procurarVariavel(expressao.simbolo, expressao));
|
|
307
|
+
}
|
|
308
|
+
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
309
|
+
return await this.avaliar(declaracao.expressao);
|
|
310
|
+
}
|
|
311
|
+
async visitarExpressaoLogica(expressao) {
|
|
312
|
+
const esquerda = await this.avaliar(expressao.esquerda);
|
|
313
|
+
if (expressao.operador.tipo === egua_classico_1.default.EM) {
|
|
314
|
+
const direita = await this.avaliar(expressao.direita);
|
|
315
|
+
if (Array.isArray(direita) || typeof direita === 'string') {
|
|
316
|
+
return direita.includes(esquerda);
|
|
317
|
+
}
|
|
318
|
+
else if (direita.constructor === Object) {
|
|
319
|
+
return esquerda in direita;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
// se um estado for verdadeiro, retorna verdadeiro
|
|
326
|
+
if (expressao.operador.tipo === egua_classico_1.default.OU) {
|
|
327
|
+
if (this.eVerdadeiro(esquerda))
|
|
328
|
+
return esquerda;
|
|
329
|
+
}
|
|
330
|
+
// se um estado for falso, retorna falso
|
|
331
|
+
if (expressao.operador.tipo === egua_classico_1.default.E) {
|
|
332
|
+
if (!this.eVerdadeiro(esquerda))
|
|
333
|
+
return esquerda;
|
|
334
|
+
}
|
|
335
|
+
return await this.avaliar(expressao.direita);
|
|
336
|
+
}
|
|
337
|
+
async visitarDeclaracaoSe(declaracao) {
|
|
338
|
+
if (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
339
|
+
return await this.executar(declaracao.caminhoEntao);
|
|
340
|
+
}
|
|
341
|
+
for (let i = 0; i < declaracao.caminhosSeSenao.length; i++) {
|
|
342
|
+
const atual = declaracao.caminhosSeSenao[i];
|
|
343
|
+
if (this.eVerdadeiro(await this.avaliar(atual.condicao))) {
|
|
344
|
+
return await this.executar(atual.caminho);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (declaracao.caminhoSenao !== null) {
|
|
348
|
+
return await this.executar(declaracao.caminhoSenao);
|
|
349
|
+
}
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
async visitarDeclaracaoPara(declaracao) {
|
|
353
|
+
if (declaracao.inicializador !== null) {
|
|
354
|
+
await this.avaliar(declaracao.inicializador);
|
|
355
|
+
}
|
|
356
|
+
while (true) {
|
|
357
|
+
if (declaracao.condicao !== null) {
|
|
358
|
+
if (!this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
await this.executar(declaracao.corpo);
|
|
364
|
+
}
|
|
365
|
+
catch (erro) {
|
|
366
|
+
throw erro;
|
|
367
|
+
}
|
|
368
|
+
if (declaracao.incrementar !== null) {
|
|
369
|
+
await this.avaliar(declaracao.incrementar);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
async visitarDeclaracaoFazer(declaracao) {
|
|
375
|
+
do {
|
|
376
|
+
try {
|
|
377
|
+
await this.executar(declaracao.caminhoFazer);
|
|
378
|
+
}
|
|
379
|
+
catch (erro) {
|
|
380
|
+
throw erro;
|
|
381
|
+
}
|
|
382
|
+
} while (this.eVerdadeiro(await this.avaliar(declaracao.condicaoEnquanto)));
|
|
383
|
+
}
|
|
384
|
+
async visitarDeclaracaoEscolha(declaracao) {
|
|
385
|
+
const condicaoEscolha = await this.avaliar(declaracao.identificadorOuLiteral);
|
|
386
|
+
const caminhos = declaracao.caminhos;
|
|
387
|
+
const caminhoPadrao = declaracao.caminhoPadrao;
|
|
388
|
+
let encontrado = false;
|
|
389
|
+
try {
|
|
390
|
+
for (let i = 0; i < caminhos.length; i++) {
|
|
391
|
+
const caminho = caminhos[i];
|
|
392
|
+
for (let j = 0; j < caminho.condicoes.length; j++) {
|
|
393
|
+
if ((await this.avaliar(caminho.condicoes[j])) === condicaoEscolha) {
|
|
394
|
+
encontrado = true;
|
|
395
|
+
try {
|
|
396
|
+
for (let k = 0; k < caminho.declaracoes.length; k++) {
|
|
397
|
+
await this.executar(caminho.declaracoes[k]);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
catch (erro) {
|
|
401
|
+
throw erro;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (caminhoPadrao !== null && encontrado === false) {
|
|
407
|
+
for (let i = 0; i < caminhoPadrao.declaracoes.length; i++) {
|
|
408
|
+
await this.executar(caminhoPadrao['declaracoes'][i]);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch (erro) {
|
|
413
|
+
throw erro;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async visitarDeclaracaoTente(declaracao) {
|
|
417
|
+
let valorRetorno;
|
|
418
|
+
try {
|
|
419
|
+
let sucesso = true;
|
|
420
|
+
try {
|
|
421
|
+
valorRetorno = await this.executarBloco(declaracao.caminhoTente);
|
|
422
|
+
}
|
|
423
|
+
catch (erro) {
|
|
424
|
+
sucesso = false;
|
|
425
|
+
if (declaracao.caminhoPegue !== null) {
|
|
426
|
+
valorRetorno = await this.executarBloco(declaracao.caminhoPegue);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
this.erros.push(erro);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (sucesso && declaracao.caminhoSenao !== null) {
|
|
433
|
+
valorRetorno = await this.executarBloco(declaracao.caminhoSenao);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
finally {
|
|
437
|
+
if (declaracao.caminhoFinalmente !== null)
|
|
438
|
+
valorRetorno = await this.executarBloco(declaracao.caminhoFinalmente);
|
|
439
|
+
}
|
|
440
|
+
return valorRetorno;
|
|
441
|
+
}
|
|
442
|
+
async visitarDeclaracaoEnquanto(declaracao) {
|
|
443
|
+
while (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
|
|
444
|
+
try {
|
|
445
|
+
await this.executar(declaracao.corpo);
|
|
446
|
+
}
|
|
447
|
+
catch (erro) {
|
|
448
|
+
throw erro;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
// TODO: Implementar em `delegua-node`.
|
|
454
|
+
async visitarDeclaracaoImportar(declaracao) {
|
|
455
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Importação não suportada em núcleo da linguagem puro. Favor executar a aplicação usando o pacote NPM `delegua-node`.', declaracao.linha);
|
|
456
|
+
/* const caminhoRelativo = await this.avaliar(declaracao.caminho);
|
|
457
|
+
const caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
|
|
458
|
+
// const nomeArquivo = caminho.basename(caminhoTotal);
|
|
459
|
+
|
|
460
|
+
let dados: any = carregarModuloPorNome(caminhoRelativo);
|
|
461
|
+
if (dados) return dados;
|
|
462
|
+
|
|
463
|
+
try {
|
|
464
|
+
if (!sistemaArquivos.existsSync(caminhoTotal)) {
|
|
465
|
+
throw new ErroEmTempoDeExecucao(
|
|
466
|
+
declaracao.simboloFechamento,
|
|
467
|
+
'Não foi possível encontrar arquivo importado.',
|
|
468
|
+
declaracao.linha
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
} catch (erro) {
|
|
472
|
+
throw new ErroEmTempoDeExecucao(
|
|
473
|
+
declaracao.simboloFechamento,
|
|
474
|
+
'Não foi possível ler o arquivo.',
|
|
475
|
+
declaracao.linha
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
dados = sistemaArquivos.readFileSync(caminhoTotal).toString();
|
|
480
|
+
|
|
481
|
+
const delegua = new Delegua(this.Delegua.dialeto, false);
|
|
482
|
+
|
|
483
|
+
delegua.executar(dados);
|
|
484
|
+
|
|
485
|
+
const exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
|
|
486
|
+
|
|
487
|
+
const eDicionario = (objeto: any) => objeto.constructor === Object;
|
|
488
|
+
|
|
489
|
+
if (eDicionario(exportar)) {
|
|
490
|
+
const novoModulo = new DeleguaModulo();
|
|
491
|
+
|
|
492
|
+
const chaves = Object.keys(exportar);
|
|
493
|
+
for (let i = 0; i < chaves.length; i++) {
|
|
494
|
+
novoModulo[chaves[i]] = exportar[chaves[i]];
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
return novoModulo;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return exportar; */
|
|
501
|
+
}
|
|
502
|
+
async visitarDeclaracaoEscreva(declaracao) {
|
|
503
|
+
try {
|
|
504
|
+
const resultadoAvaliacao = await this.avaliar(declaracao.argumentos[0]);
|
|
505
|
+
let valor = (resultadoAvaliacao === null || resultadoAvaliacao === void 0 ? void 0 : resultadoAvaliacao.hasOwnProperty('valor')) ? resultadoAvaliacao.valor : resultadoAvaliacao;
|
|
506
|
+
console.log(this.paraTexto(valor));
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
catch (erro) {
|
|
510
|
+
this.erros.push({
|
|
511
|
+
erroInterno: erro,
|
|
512
|
+
linha: declaracao.linha,
|
|
513
|
+
hashArquivo: declaracao.hashArquivo,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
|
|
519
|
+
* executa as declarações empilhadas.
|
|
520
|
+
*
|
|
521
|
+
* Se o retorno do último bloco foi uma exceção (normalmente um erro em tempo de execução),
|
|
522
|
+
* atira a exceção daqui.
|
|
523
|
+
* Isso é usado, por exemplo, em blocos `tente ... pegue ... finalmente`.
|
|
524
|
+
* @param declaracoes Um vetor de declaracoes a ser executado.
|
|
525
|
+
* @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
|
|
526
|
+
*/
|
|
527
|
+
async executarBloco(declaracoes, ambiente) {
|
|
528
|
+
const escopoExecucao = {
|
|
529
|
+
declaracoes: declaracoes,
|
|
530
|
+
declaracaoAtual: 0,
|
|
531
|
+
ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
|
|
532
|
+
finalizado: false,
|
|
533
|
+
tipo: 'outro',
|
|
534
|
+
emLacoRepeticao: false,
|
|
535
|
+
};
|
|
536
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
537
|
+
const retornoUltimoEscopo = await this.executarUltimoEscopo();
|
|
538
|
+
if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
|
|
539
|
+
throw retornoUltimoEscopo;
|
|
540
|
+
}
|
|
541
|
+
return retornoUltimoEscopo;
|
|
542
|
+
}
|
|
543
|
+
async visitarExpressaoBloco(declaracao) {
|
|
544
|
+
return await this.executarBloco(declaracao.declaracoes);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Executa expressão de definição de variável.
|
|
548
|
+
* @param declaracao A declaração Var
|
|
549
|
+
* @returns Sempre retorna nulo.
|
|
550
|
+
*/
|
|
551
|
+
async visitarDeclaracaoVar(declaracao) {
|
|
552
|
+
let valorOuOutraVariavel = null;
|
|
553
|
+
if (declaracao.inicializador !== null) {
|
|
554
|
+
valorOuOutraVariavel = await this.avaliar(declaracao.inicializador);
|
|
555
|
+
}
|
|
556
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel && valorOuOutraVariavel.hasOwnProperty('valor')
|
|
557
|
+
? valorOuOutraVariavel.valor
|
|
558
|
+
: valorOuOutraVariavel);
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
async visitarDeclaracaoVarMultiplo(declaracao) {
|
|
562
|
+
throw new Error('Método não implementado.');
|
|
563
|
+
}
|
|
564
|
+
visitarExpressaoContinua(declaracao) {
|
|
565
|
+
return new quebras_1.ContinuarQuebra();
|
|
566
|
+
}
|
|
567
|
+
visitarExpressaoSustar(declaracao) {
|
|
568
|
+
return new quebras_1.SustarQuebra();
|
|
569
|
+
}
|
|
570
|
+
async visitarExpressaoRetornar(declaracao) {
|
|
571
|
+
let valor = null;
|
|
572
|
+
if (declaracao.valor != null)
|
|
573
|
+
valor = await this.avaliar(declaracao.valor);
|
|
574
|
+
return new quebras_1.RetornoQuebra(valor);
|
|
575
|
+
}
|
|
576
|
+
async visitarExpressaoDeleguaFuncao(expressao) {
|
|
577
|
+
return new delegua_funcao_1.DeleguaFuncao(null, expressao);
|
|
578
|
+
}
|
|
579
|
+
async visitarExpressaoAtribuicaoPorIndice(expressao) {
|
|
580
|
+
const objeto = await this.avaliar(expressao.objeto);
|
|
581
|
+
let indice = await this.avaliar(expressao.indice);
|
|
582
|
+
const valor = await this.avaliar(expressao.valor);
|
|
583
|
+
if (Array.isArray(objeto)) {
|
|
584
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
585
|
+
while (indice < 0) {
|
|
586
|
+
indice += objeto.length;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
while (objeto.length < indice) {
|
|
590
|
+
objeto.push(null);
|
|
591
|
+
}
|
|
592
|
+
objeto[indice] = valor;
|
|
593
|
+
}
|
|
594
|
+
else if (objeto.constructor === Object ||
|
|
595
|
+
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
596
|
+
objeto instanceof delegua_funcao_1.DeleguaFuncao ||
|
|
597
|
+
objeto instanceof descritor_tipo_classe_1.DescritorTipoClasse ||
|
|
598
|
+
objeto instanceof modulo_1.DeleguaModulo) {
|
|
599
|
+
objeto[indice] = valor;
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
async visitarExpressaoAcessoIndiceVariavel(expressao) {
|
|
606
|
+
const variavelObjeto = await this.avaliar(expressao.entidadeChamada);
|
|
607
|
+
const objeto = variavelObjeto.hasOwnProperty('valor') ? variavelObjeto.valor : variavelObjeto;
|
|
608
|
+
let indice = await this.avaliar(expressao.indice);
|
|
609
|
+
const valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
|
|
610
|
+
if (Array.isArray(objeto)) {
|
|
611
|
+
if (!Number.isInteger(valorIndice)) {
|
|
612
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
613
|
+
}
|
|
614
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
615
|
+
while (indice < 0) {
|
|
616
|
+
indice += objeto.length;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (indice >= objeto.length) {
|
|
620
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
|
|
621
|
+
}
|
|
622
|
+
return objeto[indice];
|
|
623
|
+
}
|
|
624
|
+
else if (objeto.constructor === Object ||
|
|
625
|
+
objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
|
|
626
|
+
objeto instanceof delegua_funcao_1.DeleguaFuncao ||
|
|
627
|
+
objeto instanceof descritor_tipo_classe_1.DescritorTipoClasse ||
|
|
628
|
+
objeto instanceof modulo_1.DeleguaModulo) {
|
|
629
|
+
return objeto[indice] || null;
|
|
630
|
+
}
|
|
631
|
+
else if (typeof objeto === 'string') {
|
|
632
|
+
if (!Number.isInteger(indice)) {
|
|
633
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
|
|
634
|
+
}
|
|
635
|
+
if (indice < 0 && objeto.length !== 0) {
|
|
636
|
+
while (indice < 0) {
|
|
637
|
+
indice += objeto.length;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
if (indice >= objeto.length) {
|
|
641
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
|
|
642
|
+
}
|
|
643
|
+
return objeto.charAt(indice);
|
|
644
|
+
}
|
|
645
|
+
else {
|
|
646
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
async visitarExpressaoDefinirValor(expressao) {
|
|
650
|
+
const objeto = await this.avaliar(expressao.objeto);
|
|
651
|
+
if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) && objeto.constructor !== Object) {
|
|
652
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
|
|
653
|
+
}
|
|
654
|
+
const valor = await this.avaliar(expressao.valor);
|
|
655
|
+
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
656
|
+
objeto.definir(expressao.nome, valor);
|
|
657
|
+
return valor;
|
|
658
|
+
}
|
|
659
|
+
else if (objeto.constructor === Object) {
|
|
660
|
+
objeto[expressao.simbolo.lexema] = valor;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
664
|
+
const funcao = new delegua_funcao_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
|
|
665
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
|
|
666
|
+
}
|
|
667
|
+
async visitarDeclaracaoClasse(declaracao) {
|
|
668
|
+
let superClasse = null;
|
|
669
|
+
if (declaracao.superClasse !== null) {
|
|
670
|
+
const variavelSuperClasse = await this.avaliar(declaracao.superClasse);
|
|
671
|
+
superClasse = variavelSuperClasse.valor;
|
|
672
|
+
if (!(superClasse instanceof descritor_tipo_classe_1.DescritorTipoClasse)) {
|
|
673
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'Superclasse precisa ser uma classe.', declaracao.linha);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
|
|
677
|
+
if (declaracao.superClasse !== null) {
|
|
678
|
+
this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
|
|
679
|
+
}
|
|
680
|
+
const metodos = {};
|
|
681
|
+
const definirMetodos = declaracao.metodos;
|
|
682
|
+
for (let i = 0; i < declaracao.metodos.length; i++) {
|
|
683
|
+
const metodoAtual = definirMetodos[i];
|
|
684
|
+
const eInicializador = metodoAtual.simbolo.lexema === 'construtor';
|
|
685
|
+
const funcao = new delegua_funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
|
|
686
|
+
metodos[metodoAtual.simbolo.lexema] = funcao;
|
|
687
|
+
}
|
|
688
|
+
const deleguaClasse = new descritor_tipo_classe_1.DescritorTipoClasse(declaracao.simbolo, superClasse, metodos);
|
|
689
|
+
deleguaClasse.dialetoRequerExpansaoPropriedadesEspacoVariaveis = false;
|
|
690
|
+
deleguaClasse.dialetoRequerDeclaracaoPropriedades = false;
|
|
691
|
+
// TODO: Recolocar isso se for necessário.
|
|
692
|
+
/* if (superClasse !== null) {
|
|
693
|
+
this.ambiente = this.ambiente.enclosing;
|
|
694
|
+
} */
|
|
695
|
+
this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
async visitarExpressaoAcessoMetodo(expressao) {
|
|
699
|
+
const variavelObjeto = await this.avaliar(expressao.objeto);
|
|
700
|
+
const objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
|
|
701
|
+
if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
|
|
702
|
+
return objeto.obter(expressao.simbolo) || null;
|
|
703
|
+
}
|
|
704
|
+
else if (objeto.constructor === Object) {
|
|
705
|
+
return objeto[expressao.simbolo.lexema] || null;
|
|
706
|
+
}
|
|
707
|
+
else if (objeto instanceof modulo_1.DeleguaModulo) {
|
|
708
|
+
return objeto[expressao.simbolo.lexema] || null;
|
|
709
|
+
}
|
|
710
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
|
|
711
|
+
}
|
|
712
|
+
async visitarExpressaoIsto(expressao) {
|
|
713
|
+
return Promise.resolve(this.procurarVariavel(expressao.palavraChave, expressao));
|
|
714
|
+
}
|
|
715
|
+
async visitarExpressaoDicionario(expressao) {
|
|
716
|
+
const dicionario = {};
|
|
717
|
+
for (let i = 0; i < expressao.chaves.length; i++) {
|
|
718
|
+
dicionario[await this.avaliar(expressao.chaves[i])] = await this.avaliar(expressao.valores[i]);
|
|
719
|
+
}
|
|
720
|
+
return dicionario;
|
|
721
|
+
}
|
|
722
|
+
async visitarExpressaoVetor(expressao) {
|
|
723
|
+
const valores = [];
|
|
724
|
+
for (let i = 0; i < expressao.valores.length; i++) {
|
|
725
|
+
valores.push(await this.avaliar(expressao.valores[i]));
|
|
726
|
+
}
|
|
727
|
+
return valores;
|
|
728
|
+
}
|
|
729
|
+
visitarExpressaoSuper(expressao) {
|
|
730
|
+
const distancia = this.locais.get(expressao);
|
|
731
|
+
const superClasse = this.pilhaEscoposExecucao.obterVariavelEm(distancia, 'super');
|
|
732
|
+
const objeto = this.pilhaEscoposExecucao.obterVariavelEm(distancia - 1, 'isto');
|
|
733
|
+
const metodo = superClasse.valor.encontrarMetodo(expressao.metodo.lexema);
|
|
734
|
+
if (metodo === undefined) {
|
|
735
|
+
throw new excecoes_1.ErroEmTempoDeExecucao(expressao.metodo, 'Método chamado indefinido.', expressao.linha);
|
|
736
|
+
}
|
|
737
|
+
return metodo.definirInstancia(objeto.valor);
|
|
738
|
+
}
|
|
739
|
+
paraTexto(objeto) {
|
|
740
|
+
if (objeto === null)
|
|
741
|
+
return 'nulo';
|
|
742
|
+
if (typeof objeto === 'boolean') {
|
|
743
|
+
return objeto ? 'verdadeiro' : 'falso';
|
|
744
|
+
}
|
|
745
|
+
if (objeto instanceof Date) {
|
|
746
|
+
const formato = Intl.DateTimeFormat('pt', {
|
|
747
|
+
dateStyle: 'full',
|
|
748
|
+
timeStyle: 'full',
|
|
749
|
+
});
|
|
750
|
+
return formato.format(objeto);
|
|
751
|
+
}
|
|
752
|
+
if (Array.isArray(objeto))
|
|
753
|
+
return objeto;
|
|
754
|
+
if (typeof objeto === 'object')
|
|
755
|
+
return JSON.stringify(objeto);
|
|
756
|
+
if (objeto === undefined) {
|
|
757
|
+
return 'nulo';
|
|
758
|
+
}
|
|
759
|
+
return objeto.toString();
|
|
760
|
+
}
|
|
761
|
+
async executar(declaracao, mostrarResultado = false) {
|
|
762
|
+
return await declaracao.aceitar(this);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Executa o último escopo empilhado no topo na pilha de escopos do Interpretador.
|
|
766
|
+
* Originalmente, Égua não trabalha com uma pilha de escopos.
|
|
767
|
+
*
|
|
768
|
+
* O tratamento das exceções é feito de acordo com o bloco chamador.
|
|
769
|
+
* Por exemplo, em `tente ... pegue ... finalmente`, a exceção é capturada e tratada.
|
|
770
|
+
* Em outros blocos, pode ser desejável ter o erro em tela.
|
|
771
|
+
*
|
|
772
|
+
* Essa implementação é derivada do Interpretador de Delégua, mas simulando todos os
|
|
773
|
+
* comportamos do interpretador Égua original.
|
|
774
|
+
* Interpretador Égua: https://github.com/eguatech/egua/blob/master/src/interpreter.js
|
|
775
|
+
* @returns O resultado da execução do escopo, se houver.
|
|
776
|
+
*/
|
|
777
|
+
async executarUltimoEscopo() {
|
|
778
|
+
const ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
|
|
779
|
+
try {
|
|
780
|
+
let retornoExecucao;
|
|
781
|
+
for (; !(retornoExecucao instanceof quebras_1.Quebra) && ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length; ultimoEscopo.declaracaoAtual++) {
|
|
782
|
+
retornoExecucao = await this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual]);
|
|
783
|
+
}
|
|
784
|
+
return retornoExecucao;
|
|
785
|
+
}
|
|
786
|
+
catch (erro) {
|
|
787
|
+
return Promise.reject(erro);
|
|
788
|
+
}
|
|
789
|
+
finally {
|
|
790
|
+
this.pilhaEscoposExecucao.removerUltimo();
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
async interpretar(declaracoes) {
|
|
794
|
+
this.erros = [];
|
|
795
|
+
const retornoResolvedor = await this.resolvedor.resolver(declaracoes);
|
|
796
|
+
this.locais = retornoResolvedor.locais;
|
|
797
|
+
const escopoExecucao = {
|
|
798
|
+
declaracoes: declaracoes,
|
|
799
|
+
declaracaoAtual: 0,
|
|
800
|
+
ambiente: new espaco_variaveis_1.EspacoVariaveis(),
|
|
801
|
+
finalizado: false,
|
|
802
|
+
tipo: 'outro',
|
|
803
|
+
emLacoRepeticao: false,
|
|
804
|
+
};
|
|
805
|
+
this.pilhaEscoposExecucao.empilhar(escopoExecucao);
|
|
806
|
+
await this.executarUltimoEscopo();
|
|
807
|
+
return {
|
|
808
|
+
erros: this.erros,
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
finalizacao() {
|
|
812
|
+
this.funcaoDeRetorno();
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
exports.InterpretadorEguaClassico = InterpretadorEguaClassico;
|
|
816
816
|
//# sourceMappingURL=interpretador-egua-classico.js.map
|