@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,771 +1,771 @@
|
|
|
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.AvaliadorSintaticoPitugues = void 0;
|
|
7
|
-
const browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime"));
|
|
8
|
-
const construtos_1 = require("../../construtos");
|
|
9
|
-
const declaracoes_1 = require("../../declaracoes");
|
|
10
|
-
const erro_avaliador_sintatico_1 = require("../erro-avaliador-sintatico");
|
|
11
|
-
const pitugues_1 = __importDefault(require("../../tipos-de-simbolos/pitugues"));
|
|
12
|
-
const lexador_1 = require("../../lexador");
|
|
13
|
-
/**
|
|
14
|
-
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
15
|
-
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
16
|
-
* Há dois grupos de estruturas de alto nível: Construtos e Declarações.
|
|
17
|
-
*
|
|
18
|
-
* A grande diferença entre este avaliador e os demais é a forma como são entendidos os blocos de escopo.
|
|
19
|
-
* Este avaliador espera uma estrutura de pragmas, que explica quantos espaços há na frente de cada linha.
|
|
20
|
-
*/
|
|
21
|
-
class AvaliadorSintaticoPitugues {
|
|
22
|
-
constructor(performance = false) {
|
|
23
|
-
this.atual = 0;
|
|
24
|
-
this.blocos = 0;
|
|
25
|
-
this.performance = performance;
|
|
26
|
-
this.escopos = [];
|
|
27
|
-
}
|
|
28
|
-
declaracaoDeConstantes() {
|
|
29
|
-
throw new Error('Método não implementado.');
|
|
30
|
-
}
|
|
31
|
-
declaracaoDeVariavel() {
|
|
32
|
-
throw new Error('Método não implementado.');
|
|
33
|
-
}
|
|
34
|
-
declaracaoDeVariaveis() {
|
|
35
|
-
const identificadores = [];
|
|
36
|
-
let retorno = [];
|
|
37
|
-
do {
|
|
38
|
-
identificadores.push(this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome de variável.'));
|
|
39
|
-
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
40
|
-
if (!this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IGUAL)) {
|
|
41
|
-
for (let [indice, identificador] of identificadores.entries()) {
|
|
42
|
-
retorno.push(new declaracoes_1.Var(identificador, null));
|
|
43
|
-
}
|
|
44
|
-
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO_E_VIRGULA);
|
|
45
|
-
return retorno;
|
|
46
|
-
}
|
|
47
|
-
//this.consumir(tiposDeSimbolos.IGUAL, "Esperado '=' após identificador em instrução 'var'.");
|
|
48
|
-
const inicializadores = [];
|
|
49
|
-
do {
|
|
50
|
-
inicializadores.push(this.expressao());
|
|
51
|
-
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
52
|
-
if (identificadores.length !== inicializadores.length) {
|
|
53
|
-
throw this.erro(this.simboloAtual(), 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
54
|
-
}
|
|
55
|
-
for (let [indice, identificador] of identificadores.entries()) {
|
|
56
|
-
retorno.push(new declaracoes_1.Var(identificador, inicializadores[indice]));
|
|
57
|
-
}
|
|
58
|
-
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO_E_VIRGULA);
|
|
59
|
-
return retorno;
|
|
60
|
-
}
|
|
61
|
-
sincronizar() {
|
|
62
|
-
this.avancarEDevolverAnterior();
|
|
63
|
-
while (!this.estaNoFinal()) {
|
|
64
|
-
switch (this.simboloAtual().tipo) {
|
|
65
|
-
case pitugues_1.default.CLASSE:
|
|
66
|
-
case pitugues_1.default.FUNCAO:
|
|
67
|
-
case pitugues_1.default.FUNÇÃO:
|
|
68
|
-
case pitugues_1.default.VARIAVEL:
|
|
69
|
-
case pitugues_1.default.PARA:
|
|
70
|
-
case pitugues_1.default.SE:
|
|
71
|
-
case pitugues_1.default.ENQUANTO:
|
|
72
|
-
case pitugues_1.default.ESCREVA:
|
|
73
|
-
case pitugues_1.default.RETORNA:
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.avancarEDevolverAnterior();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
erro(simbolo, mensagemDeErro) {
|
|
80
|
-
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simbolo, mensagemDeErro);
|
|
81
|
-
this.erros.push(excecao);
|
|
82
|
-
return excecao;
|
|
83
|
-
}
|
|
84
|
-
consumir(tipo, mensagemDeErro) {
|
|
85
|
-
if (this.verificarTipoSimboloAtual(tipo))
|
|
86
|
-
return this.avancarEDevolverAnterior();
|
|
87
|
-
throw this.erro(this.simboloAtual(), mensagemDeErro);
|
|
88
|
-
}
|
|
89
|
-
verificarTipoSimboloAtual(tipo) {
|
|
90
|
-
if (this.estaNoFinal())
|
|
91
|
-
return false;
|
|
92
|
-
return this.simboloAtual().tipo === tipo;
|
|
93
|
-
}
|
|
94
|
-
verificarTipoProximoSimbolo(tipo) {
|
|
95
|
-
if (this.estaNoFinal())
|
|
96
|
-
return false;
|
|
97
|
-
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
98
|
-
}
|
|
99
|
-
simboloAtual() {
|
|
100
|
-
return this.simbolos[this.atual];
|
|
101
|
-
}
|
|
102
|
-
simboloAnterior() {
|
|
103
|
-
return this.simbolos[this.atual - 1];
|
|
104
|
-
}
|
|
105
|
-
simboloNaPosicao(posicao) {
|
|
106
|
-
return this.simbolos[this.atual + posicao];
|
|
107
|
-
}
|
|
108
|
-
estaNoFinal() {
|
|
109
|
-
return this.atual >= this.simbolos.length;
|
|
110
|
-
}
|
|
111
|
-
avancarEDevolverAnterior() {
|
|
112
|
-
if (!this.estaNoFinal())
|
|
113
|
-
this.atual += 1;
|
|
114
|
-
return this.simboloAnterior();
|
|
115
|
-
}
|
|
116
|
-
verificarSeSimboloAtualEIgualA(...argumentos) {
|
|
117
|
-
for (let i = 0; i < argumentos.length; i++) {
|
|
118
|
-
const tipoAtual = argumentos[i];
|
|
119
|
-
if (this.verificarTipoSimboloAtual(tipoAtual)) {
|
|
120
|
-
this.avancarEDevolverAnterior();
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
primario() {
|
|
127
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SUPER)) {
|
|
128
|
-
const simboloChave = this.simboloAnterior();
|
|
129
|
-
this.consumir(pitugues_1.default.PONTO, "Esperado '.' após 'super'.");
|
|
130
|
-
const metodo = this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome do método da Superclasse.');
|
|
131
|
-
return new construtos_1.Super(this.hashArquivo, simboloChave, metodo);
|
|
132
|
-
}
|
|
133
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_ESQUERDO)) {
|
|
134
|
-
const valores = [];
|
|
135
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_DIREITO)) {
|
|
136
|
-
return new construtos_1.Vetor(this.hashArquivo, 0, []);
|
|
137
|
-
}
|
|
138
|
-
while (!this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_DIREITO)) {
|
|
139
|
-
const valor = this.atribuir();
|
|
140
|
-
valores.push(valor);
|
|
141
|
-
if (this.simboloAtual().tipo !== pitugues_1.default.COLCHETE_DIREITO) {
|
|
142
|
-
this.consumir(pitugues_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return new construtos_1.Vetor(this.hashArquivo, 0, valores);
|
|
146
|
-
}
|
|
147
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CHAVE_ESQUERDA)) {
|
|
148
|
-
const chaves = [];
|
|
149
|
-
const valores = [];
|
|
150
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CHAVE_DIREITA)) {
|
|
151
|
-
return new construtos_1.Dicionario(this.hashArquivo, 0, [], []);
|
|
152
|
-
}
|
|
153
|
-
while (!this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CHAVE_DIREITA)) {
|
|
154
|
-
const chave = this.atribuir();
|
|
155
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' entre chave e valor.");
|
|
156
|
-
const valor = this.atribuir();
|
|
157
|
-
chaves.push(chave);
|
|
158
|
-
valores.push(valor);
|
|
159
|
-
if (this.simboloAtual().tipo !== pitugues_1.default.CHAVE_DIREITA) {
|
|
160
|
-
this.consumir(pitugues_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return new construtos_1.Dicionario(this.hashArquivo, 0, chaves, valores);
|
|
164
|
-
}
|
|
165
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.FALSO))
|
|
166
|
-
return new construtos_1.Literal(this.hashArquivo, 0, false);
|
|
167
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VERDADEIRO))
|
|
168
|
-
return new construtos_1.Literal(this.hashArquivo, 0, true);
|
|
169
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.NULO))
|
|
170
|
-
return new construtos_1.Literal(this.hashArquivo, 0, null);
|
|
171
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.ISTO))
|
|
172
|
-
return new construtos_1.Isto(this.hashArquivo, 0, this.simboloAnterior());
|
|
173
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.NUMERO, pitugues_1.default.TEXTO)) {
|
|
174
|
-
const simboloAnterior = this.simboloAnterior();
|
|
175
|
-
return new construtos_1.Literal(this.hashArquivo, Number(simboloAnterior.linha), simboloAnterior.literal);
|
|
176
|
-
}
|
|
177
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IDENTIFICADOR)) {
|
|
178
|
-
return new construtos_1.Variavel(this.hashArquivo, this.simboloAnterior());
|
|
179
|
-
}
|
|
180
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PARENTESE_ESQUERDO)) {
|
|
181
|
-
const expressao = this.expressao();
|
|
182
|
-
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
183
|
-
return new construtos_1.Agrupamento(this.hashArquivo, 0, expressao);
|
|
184
|
-
}
|
|
185
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IMPORTAR))
|
|
186
|
-
return this.declaracaoImportar();
|
|
187
|
-
throw this.erro(this.simboloAtual(), 'Esperado expressão.');
|
|
188
|
-
}
|
|
189
|
-
finalizarChamada(entidadeChamada) {
|
|
190
|
-
const argumentos = [];
|
|
191
|
-
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PARENTESE_DIREITO)) {
|
|
192
|
-
do {
|
|
193
|
-
if (argumentos.length >= 255) {
|
|
194
|
-
throw this.erro(this.simboloAtual(), 'Não pode haver mais de 255 argumentos.');
|
|
195
|
-
}
|
|
196
|
-
argumentos.push(this.expressao());
|
|
197
|
-
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
198
|
-
}
|
|
199
|
-
const parenteseDireito = this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos.");
|
|
200
|
-
return new construtos_1.Chamada(this.hashArquivo, entidadeChamada, parenteseDireito, argumentos);
|
|
201
|
-
}
|
|
202
|
-
chamar() {
|
|
203
|
-
let expressao = this.primario();
|
|
204
|
-
while (true) {
|
|
205
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PARENTESE_ESQUERDO)) {
|
|
206
|
-
expressao = this.finalizarChamada(expressao);
|
|
207
|
-
}
|
|
208
|
-
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO)) {
|
|
209
|
-
const nome = this.consumir(pitugues_1.default.IDENTIFICADOR, "Esperado nome do método após '.'.");
|
|
210
|
-
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
211
|
-
}
|
|
212
|
-
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_ESQUERDO)) {
|
|
213
|
-
const indice = this.expressao();
|
|
214
|
-
const simboloFechamento = this.consumir(pitugues_1.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
215
|
-
expressao = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, expressao, indice, simboloFechamento);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return expressao;
|
|
222
|
-
}
|
|
223
|
-
unario() {
|
|
224
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.NEGACAO, pitugues_1.default.SUBTRACAO, pitugues_1.default.BIT_NOT)) {
|
|
225
|
-
const operador = this.simboloAnterior();
|
|
226
|
-
const direito = this.unario();
|
|
227
|
-
return new construtos_1.Unario(this.hashArquivo, operador, direito);
|
|
228
|
-
}
|
|
229
|
-
return this.chamar();
|
|
230
|
-
}
|
|
231
|
-
exponenciacao() {
|
|
232
|
-
let expressao = this.unario();
|
|
233
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.EXPONENCIACAO)) {
|
|
234
|
-
const operador = this.simboloAnterior();
|
|
235
|
-
const direito = this.unario();
|
|
236
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
237
|
-
}
|
|
238
|
-
return expressao;
|
|
239
|
-
}
|
|
240
|
-
multiplicar() {
|
|
241
|
-
let expressao = this.exponenciacao();
|
|
242
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.DIVISAO, pitugues_1.default.DIVISAO_INTEIRA, pitugues_1.default.MULTIPLICACAO, pitugues_1.default.MODULO)) {
|
|
243
|
-
const operador = this.simboloAnterior();
|
|
244
|
-
const direito = this.exponenciacao();
|
|
245
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
246
|
-
}
|
|
247
|
-
return expressao;
|
|
248
|
-
}
|
|
249
|
-
adicaoOuSubtracao() {
|
|
250
|
-
let expressao = this.multiplicar();
|
|
251
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SUBTRACAO, pitugues_1.default.ADICAO)) {
|
|
252
|
-
const operador = this.simboloAnterior();
|
|
253
|
-
const direito = this.multiplicar();
|
|
254
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
255
|
-
}
|
|
256
|
-
return expressao;
|
|
257
|
-
}
|
|
258
|
-
bitShift() {
|
|
259
|
-
let expressao = this.adicaoOuSubtracao();
|
|
260
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.MENOR_MENOR, pitugues_1.default.MAIOR_MAIOR)) {
|
|
261
|
-
const operador = this.simboloAnterior();
|
|
262
|
-
const direito = this.adicaoOuSubtracao();
|
|
263
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
264
|
-
}
|
|
265
|
-
return expressao;
|
|
266
|
-
}
|
|
267
|
-
bitE() {
|
|
268
|
-
let expressao = this.bitShift();
|
|
269
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.BIT_AND)) {
|
|
270
|
-
const operador = this.simboloAnterior();
|
|
271
|
-
const direito = this.bitShift();
|
|
272
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
273
|
-
}
|
|
274
|
-
return expressao;
|
|
275
|
-
}
|
|
276
|
-
bitOu() {
|
|
277
|
-
let expressao = this.bitE();
|
|
278
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.BIT_OR, pitugues_1.default.BIT_XOR)) {
|
|
279
|
-
const operador = this.simboloAnterior();
|
|
280
|
-
const direito = this.bitE();
|
|
281
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
282
|
-
}
|
|
283
|
-
return expressao;
|
|
284
|
-
}
|
|
285
|
-
comparar() {
|
|
286
|
-
let expressao = this.bitOu();
|
|
287
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.MAIOR, pitugues_1.default.MAIOR_IGUAL, pitugues_1.default.MENOR, pitugues_1.default.MENOR_IGUAL)) {
|
|
288
|
-
const operador = this.simboloAnterior();
|
|
289
|
-
const direito = this.bitOu();
|
|
290
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
291
|
-
}
|
|
292
|
-
return expressao;
|
|
293
|
-
}
|
|
294
|
-
comparacaoIgualdade() {
|
|
295
|
-
let expressao = this.comparar();
|
|
296
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.DIFERENTE, pitugues_1.default.IGUAL_IGUAL)) {
|
|
297
|
-
const operador = this.simboloAnterior();
|
|
298
|
-
const direito = this.comparar();
|
|
299
|
-
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
300
|
-
}
|
|
301
|
-
return expressao;
|
|
302
|
-
}
|
|
303
|
-
em() {
|
|
304
|
-
let expressao = this.comparacaoIgualdade();
|
|
305
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.EM)) {
|
|
306
|
-
const operador = this.simboloAnterior();
|
|
307
|
-
const direito = this.comparacaoIgualdade();
|
|
308
|
-
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
309
|
-
}
|
|
310
|
-
return expressao;
|
|
311
|
-
}
|
|
312
|
-
e() {
|
|
313
|
-
let expressao = this.em();
|
|
314
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.E)) {
|
|
315
|
-
const operador = this.simboloAnterior();
|
|
316
|
-
const direito = this.em();
|
|
317
|
-
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
318
|
-
}
|
|
319
|
-
return expressao;
|
|
320
|
-
}
|
|
321
|
-
ou() {
|
|
322
|
-
let expressao = this.e();
|
|
323
|
-
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.OU)) {
|
|
324
|
-
const operador = this.simboloAnterior();
|
|
325
|
-
const direito = this.e();
|
|
326
|
-
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
327
|
-
}
|
|
328
|
-
return expressao;
|
|
329
|
-
}
|
|
330
|
-
atribuir() {
|
|
331
|
-
const expressao = this.ou();
|
|
332
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IGUAL) ||
|
|
333
|
-
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.MAIS_IGUAL)) {
|
|
334
|
-
const igual = this.simboloAnterior();
|
|
335
|
-
const valor = this.atribuir();
|
|
336
|
-
if (expressao instanceof construtos_1.Variavel) {
|
|
337
|
-
const simbolo = expressao.simbolo;
|
|
338
|
-
return new construtos_1.Atribuir(this.hashArquivo, simbolo, valor);
|
|
339
|
-
}
|
|
340
|
-
else if (expressao instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
341
|
-
return new construtos_1.DefinirValor(this.hashArquivo, 0, expressao.objeto, expressao.simbolo, valor);
|
|
342
|
-
}
|
|
343
|
-
else if (expressao instanceof construtos_1.AcessoIndiceVariavel) {
|
|
344
|
-
return new construtos_1.AtribuicaoPorIndice(this.hashArquivo, 0, expressao.entidadeChamada, expressao.indice, valor);
|
|
345
|
-
}
|
|
346
|
-
this.erro(igual, 'Tarefa de atribuição inválida');
|
|
347
|
-
}
|
|
348
|
-
return expressao;
|
|
349
|
-
}
|
|
350
|
-
expressao() {
|
|
351
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.LEIA))
|
|
352
|
-
return this.declaracaoLeia();
|
|
353
|
-
return this.atribuir();
|
|
354
|
-
}
|
|
355
|
-
declaracaoEscreva() {
|
|
356
|
-
const simboloAtual = this.simboloAtual();
|
|
357
|
-
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em escreva.");
|
|
358
|
-
const argumentos = [];
|
|
359
|
-
do {
|
|
360
|
-
argumentos.push(this.expressao());
|
|
361
|
-
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
362
|
-
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em escreva.");
|
|
363
|
-
return new declaracoes_1.Escreva(Number(simboloAtual.linha), simboloAtual.hashArquivo, argumentos);
|
|
364
|
-
}
|
|
365
|
-
declaracaoExpressao() {
|
|
366
|
-
const expressao = this.expressao();
|
|
367
|
-
return new declaracoes_1.Expressao(expressao);
|
|
368
|
-
}
|
|
369
|
-
declaracaoLeia() {
|
|
370
|
-
const simboloLeia = this.simbolos[this.atual];
|
|
371
|
-
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em leia.");
|
|
372
|
-
const argumentos = [];
|
|
373
|
-
do {
|
|
374
|
-
argumentos.push(this.expressao());
|
|
375
|
-
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
376
|
-
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em leia.");
|
|
377
|
-
return new declaracoes_1.Leia(simboloLeia, argumentos);
|
|
378
|
-
}
|
|
379
|
-
blocoEscopo() {
|
|
380
|
-
let declaracoes = [];
|
|
381
|
-
let simboloAtual = this.simboloAtual();
|
|
382
|
-
const simboloAnterior = this.simboloAnterior();
|
|
383
|
-
// Situação 1: não tem bloco de escopo.
|
|
384
|
-
//
|
|
385
|
-
// Exemplo: `se verdadeiro: escreva('Alguma coisa')`.
|
|
386
|
-
// Neste caso, linha do símbolo atual é igual à linha do símbolo anterior.
|
|
387
|
-
if (simboloAtual.linha === simboloAnterior.linha) {
|
|
388
|
-
declaracoes.push(this.resolverDeclaracaoForaDeBloco());
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
// Situação 2: símbolo atual fica na próxima linha.
|
|
392
|
-
//
|
|
393
|
-
// Verifica-se o número de espaços à esquerda da linha através dos pragmas.
|
|
394
|
-
// Se número de espaços da linha do símbolo atual é menor ou igual ao número de espaços
|
|
395
|
-
// da linha anterior, e bloco ainda não começou, é uma situação de erro.
|
|
396
|
-
let espacosIndentacaoLinhaAtual = this.pragmas[simboloAtual.linha].espacosIndentacao;
|
|
397
|
-
const espacosIndentacaoLinhaAnterior = this.pragmas[simboloAnterior.linha].espacosIndentacao;
|
|
398
|
-
if (espacosIndentacaoLinhaAtual <= espacosIndentacaoLinhaAnterior) {
|
|
399
|
-
this.erro(simboloAtual, `Indentação inconsistente na linha ${simboloAtual.linha}. ` +
|
|
400
|
-
`Esperado: >= ${espacosIndentacaoLinhaAnterior}. ` +
|
|
401
|
-
`Atual: ${espacosIndentacaoLinhaAtual}`);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
// Indentação ok, é um bloco de escopo.
|
|
405
|
-
// Inclui todas as declarações cujas linhas tenham o mesmo número de espaços
|
|
406
|
-
// de indentação do bloco.
|
|
407
|
-
// Se `simboloAtual` for definido em algum momento como indefinido,
|
|
408
|
-
// Significa que o código acabou, então o bloco também acabou.
|
|
409
|
-
const espacosIndentacaoBloco = espacosIndentacaoLinhaAtual;
|
|
410
|
-
while (espacosIndentacaoLinhaAtual === espacosIndentacaoBloco) {
|
|
411
|
-
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
412
|
-
if (Array.isArray(retornoDeclaracao)) {
|
|
413
|
-
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
declaracoes.push(retornoDeclaracao);
|
|
417
|
-
}
|
|
418
|
-
simboloAtual = this.simboloAtual();
|
|
419
|
-
if (!simboloAtual)
|
|
420
|
-
break;
|
|
421
|
-
espacosIndentacaoLinhaAtual = this.pragmas[simboloAtual.linha].espacosIndentacao;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
return declaracoes;
|
|
426
|
-
}
|
|
427
|
-
declaracaoEnquanto() {
|
|
428
|
-
try {
|
|
429
|
-
this.blocos += 1;
|
|
430
|
-
const condicao = this.expressao();
|
|
431
|
-
const bloco = this.resolverDeclaracao();
|
|
432
|
-
return new declaracoes_1.Enquanto(condicao, bloco);
|
|
433
|
-
}
|
|
434
|
-
finally {
|
|
435
|
-
this.blocos -= 1;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
declaracaoEscolha() {
|
|
439
|
-
try {
|
|
440
|
-
this.blocos += 1;
|
|
441
|
-
const condicao = this.expressao();
|
|
442
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após 'escolha'.");
|
|
443
|
-
const caminhos = [];
|
|
444
|
-
let caminhoPadrao = null;
|
|
445
|
-
while (!this.estaNoFinal() &&
|
|
446
|
-
[pitugues_1.default.CASO, pitugues_1.default.PADRAO].includes(this.simbolos[this.atual].tipo)) {
|
|
447
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CASO)) {
|
|
448
|
-
const caminhoCondicoes = [this.expressao()];
|
|
449
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após o 'caso'.");
|
|
450
|
-
while (this.verificarTipoSimboloAtual(pitugues_1.default.CASO)) {
|
|
451
|
-
this.consumir(pitugues_1.default.CASO, null);
|
|
452
|
-
caminhoCondicoes.push(this.expressao());
|
|
453
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'caso'.");
|
|
454
|
-
}
|
|
455
|
-
// Como dois-pontos é um símbolo usado para conferir se há um início de bloco,
|
|
456
|
-
// não podemos simplesmente chamar `this.resolverDeclaracao()` porque o dois-pontos já
|
|
457
|
-
// foi consumido na verificação.
|
|
458
|
-
// Outro problema é que, aparentemente, o Interpretador não espera um Bloco, e sim
|
|
459
|
-
// um vetor de Declaracao, o qual obtemos com `this.blocoEscopo()`.
|
|
460
|
-
const declaracoes = this.blocoEscopo();
|
|
461
|
-
caminhos.push({
|
|
462
|
-
condicoes: caminhoCondicoes,
|
|
463
|
-
declaracoes,
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PADRAO)) {
|
|
467
|
-
if (caminhoPadrao !== null) {
|
|
468
|
-
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.simboloAtual(), "Você só pode ter um caminho padrão em cada declaração de 'escolha'.");
|
|
469
|
-
this.erros.push(excecao);
|
|
470
|
-
throw excecao;
|
|
471
|
-
}
|
|
472
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'padrao'.");
|
|
473
|
-
// Como dois-pontos é um símbolo usado para conferir se há um início de bloco,
|
|
474
|
-
// não podemos simplesmente chamar `this.resolverDeclaracao()` porque o dois-pontos já
|
|
475
|
-
// foi consumido na verificação.
|
|
476
|
-
// Outro problema é que, aparentemente, o Interpretador não espera um Bloco, e sim
|
|
477
|
-
// um vetor de Declaracao, o qual obtemos com `this.blocoEscopo()`.
|
|
478
|
-
const declaracoes = this.blocoEscopo();
|
|
479
|
-
caminhoPadrao = {
|
|
480
|
-
declaracoes,
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return new declaracoes_1.Escolha(condicao, caminhos, caminhoPadrao);
|
|
485
|
-
}
|
|
486
|
-
finally {
|
|
487
|
-
this.blocos -= 1;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
declaracaoPara() {
|
|
491
|
-
try {
|
|
492
|
-
const simboloPara = this.simboloAnterior();
|
|
493
|
-
this.blocos += 1;
|
|
494
|
-
let inicializador;
|
|
495
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO_E_VIRGULA)) {
|
|
496
|
-
inicializador = null;
|
|
497
|
-
}
|
|
498
|
-
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VARIAVEL)) {
|
|
499
|
-
inicializador = this.declaracaoDeVariaveis();
|
|
500
|
-
}
|
|
501
|
-
else {
|
|
502
|
-
inicializador = this.declaracaoExpressao();
|
|
503
|
-
}
|
|
504
|
-
let condicao = null;
|
|
505
|
-
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PONTO_E_VIRGULA)) {
|
|
506
|
-
condicao = this.expressao();
|
|
507
|
-
}
|
|
508
|
-
let incrementar = null;
|
|
509
|
-
if (this.simbolos[this.atual].tipo !== pitugues_1.default.DOIS_PONTOS) {
|
|
510
|
-
incrementar = this.expressao();
|
|
511
|
-
}
|
|
512
|
-
const corpo = this.resolverDeclaracao();
|
|
513
|
-
return new declaracoes_1.Para(this.hashArquivo, Number(simboloPara.linha), inicializador, condicao, incrementar, corpo);
|
|
514
|
-
}
|
|
515
|
-
catch (erro) {
|
|
516
|
-
throw erro;
|
|
517
|
-
}
|
|
518
|
-
finally {
|
|
519
|
-
this.blocos -= 1;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
declaracaoSe() {
|
|
523
|
-
const condicao = this.expressao();
|
|
524
|
-
const caminhoEntao = this.resolverDeclaracao();
|
|
525
|
-
let caminhoSenao = null;
|
|
526
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SENAO, pitugues_1.default.SENÃO)) {
|
|
527
|
-
caminhoSenao = this.resolverDeclaracao();
|
|
528
|
-
}
|
|
529
|
-
return new declaracoes_1.Se(condicao, caminhoEntao, [], caminhoSenao);
|
|
530
|
-
}
|
|
531
|
-
declaracaoSustar() {
|
|
532
|
-
if (this.blocos < 1) {
|
|
533
|
-
this.erro(this.simboloAnterior(), "'sustar' deve estar dentro de um laço de repetição.");
|
|
534
|
-
}
|
|
535
|
-
return new declaracoes_1.Sustar(this.simboloAtual());
|
|
536
|
-
}
|
|
537
|
-
declaracaoContinua() {
|
|
538
|
-
if (this.blocos < 1) {
|
|
539
|
-
this.erro(this.simboloAnterior(), "'continua' precisa estar em um laço de repetição.");
|
|
540
|
-
}
|
|
541
|
-
return new declaracoes_1.Continua(this.simboloAtual());
|
|
542
|
-
}
|
|
543
|
-
declaracaoRetorna() {
|
|
544
|
-
const palavraChave = this.simboloAnterior();
|
|
545
|
-
let valor = null;
|
|
546
|
-
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PONTO_E_VIRGULA)) {
|
|
547
|
-
valor = this.expressao();
|
|
548
|
-
}
|
|
549
|
-
return new declaracoes_1.Retorna(palavraChave, valor);
|
|
550
|
-
}
|
|
551
|
-
declaracaoImportar() {
|
|
552
|
-
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
|
|
553
|
-
const caminho = this.expressao();
|
|
554
|
-
const simboloFechamento = this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
555
|
-
return new declaracoes_1.Importar(caminho, simboloFechamento);
|
|
556
|
-
}
|
|
557
|
-
declaracaoTente() {
|
|
558
|
-
const simboloTente = this.simboloAnterior();
|
|
559
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'tente'.");
|
|
560
|
-
const blocoTente = this.blocoEscopo();
|
|
561
|
-
let blocoPegue = null;
|
|
562
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PEGUE)) {
|
|
563
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'pegue'.");
|
|
564
|
-
blocoPegue = this.blocoEscopo();
|
|
565
|
-
}
|
|
566
|
-
let blocoSenao = null;
|
|
567
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SENAO, pitugues_1.default.SENÃO)) {
|
|
568
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'senão'.");
|
|
569
|
-
blocoSenao = this.blocoEscopo();
|
|
570
|
-
}
|
|
571
|
-
let blocoFinalmente = null;
|
|
572
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.FINALMENTE)) {
|
|
573
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'pegue'.");
|
|
574
|
-
blocoFinalmente = this.blocoEscopo();
|
|
575
|
-
}
|
|
576
|
-
return new declaracoes_1.Tente(simboloTente.hashArquivo, Number(simboloTente.linha), blocoTente, blocoPegue, blocoSenao, blocoFinalmente);
|
|
577
|
-
}
|
|
578
|
-
declaracaoFazer() {
|
|
579
|
-
const simboloFazer = this.simboloAnterior();
|
|
580
|
-
try {
|
|
581
|
-
this.blocos += 1;
|
|
582
|
-
const declaracaoOuBlocoFazer = this.resolverDeclaracao();
|
|
583
|
-
this.consumir(pitugues_1.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo da declaração 'fazer'.");
|
|
584
|
-
const condicaoEnquanto = this.expressao();
|
|
585
|
-
return new declaracoes_1.Fazer(simboloFazer.hashArquivo, Number(simboloFazer.linha), declaracaoOuBlocoFazer, condicaoEnquanto);
|
|
586
|
-
}
|
|
587
|
-
finally {
|
|
588
|
-
this.blocos -= 1;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
resolverDeclaracao() {
|
|
592
|
-
switch (this.simbolos[this.atual].tipo) {
|
|
593
|
-
case pitugues_1.default.CONSTANTE:
|
|
594
|
-
this.avancarEDevolverAnterior();
|
|
595
|
-
return this.declaracaoDeConstantes();
|
|
596
|
-
case pitugues_1.default.CONTINUA:
|
|
597
|
-
this.avancarEDevolverAnterior();
|
|
598
|
-
return this.declaracaoContinua();
|
|
599
|
-
case pitugues_1.default.DOIS_PONTOS:
|
|
600
|
-
this.avancarEDevolverAnterior();
|
|
601
|
-
const simboloInicioBloco = this.simboloAnterior();
|
|
602
|
-
return new declaracoes_1.Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
603
|
-
case pitugues_1.default.ENQUANTO:
|
|
604
|
-
this.avancarEDevolverAnterior();
|
|
605
|
-
return this.declaracaoEnquanto();
|
|
606
|
-
case pitugues_1.default.ESCOLHA:
|
|
607
|
-
this.avancarEDevolverAnterior();
|
|
608
|
-
return this.declaracaoEscolha();
|
|
609
|
-
case pitugues_1.default.ESCREVA:
|
|
610
|
-
this.avancarEDevolverAnterior();
|
|
611
|
-
return this.declaracaoEscreva();
|
|
612
|
-
case pitugues_1.default.FALHAR:
|
|
613
|
-
this.avancarEDevolverAnterior();
|
|
614
|
-
return this.declaracaoFalhar();
|
|
615
|
-
case pitugues_1.default.FAZER:
|
|
616
|
-
this.avancarEDevolverAnterior();
|
|
617
|
-
return this.declaracaoFazer();
|
|
618
|
-
case pitugues_1.default.PARA:
|
|
619
|
-
this.avancarEDevolverAnterior();
|
|
620
|
-
return this.declaracaoPara();
|
|
621
|
-
case pitugues_1.default.PAUSA:
|
|
622
|
-
case pitugues_1.default.SUSTAR:
|
|
623
|
-
this.avancarEDevolverAnterior();
|
|
624
|
-
return this.declaracaoSustar();
|
|
625
|
-
case pitugues_1.default.SE:
|
|
626
|
-
this.avancarEDevolverAnterior();
|
|
627
|
-
return this.declaracaoSe();
|
|
628
|
-
case pitugues_1.default.RETORNA:
|
|
629
|
-
this.avancarEDevolverAnterior();
|
|
630
|
-
return this.declaracaoRetorna();
|
|
631
|
-
case pitugues_1.default.TENTE:
|
|
632
|
-
this.avancarEDevolverAnterior();
|
|
633
|
-
return this.declaracaoTente();
|
|
634
|
-
case pitugues_1.default.VARIAVEL:
|
|
635
|
-
this.avancarEDevolverAnterior();
|
|
636
|
-
return this.declaracaoDeVariaveis();
|
|
637
|
-
}
|
|
638
|
-
/* if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.FAZER)) return this.declaracaoFazer();
|
|
639
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.TENTE)) return this.declaracaoTente();
|
|
640
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.ESCOLHA)) return this.declaracaoEscolha();
|
|
641
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.RETORNA)) return this.declaracaoRetorna();
|
|
642
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.CONTINUA)) return this.declaracaoContinua();
|
|
643
|
-
if (
|
|
644
|
-
this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.SUSTAR) ||
|
|
645
|
-
this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.PAUSA)
|
|
646
|
-
)
|
|
647
|
-
return this.declaracaoSustar();
|
|
648
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.PARA)) return this.declaracaoPara();
|
|
649
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.ENQUANTO)) return this.declaracaoEnquanto();
|
|
650
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.SE)) return this.declaracaoSe();
|
|
651
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.ESCREVA)) return this.declaracaoEscreva();
|
|
652
|
-
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.DOIS_PONTOS)) {
|
|
653
|
-
const simboloInicioBloco: SimboloInterface = this.simboloAnterior();
|
|
654
|
-
return new Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
655
|
-
} */
|
|
656
|
-
return this.declaracaoExpressao();
|
|
657
|
-
}
|
|
658
|
-
funcao(tipo, construtor) {
|
|
659
|
-
const simbolo = !construtor
|
|
660
|
-
? this.consumir(pitugues_1.default.IDENTIFICADOR, `Esperado nome ${tipo}.`)
|
|
661
|
-
: new lexador_1.Simbolo(pitugues_1.default.CONSTRUTOR, 'construtor', null, -1, -1);
|
|
662
|
-
return new declaracoes_1.FuncaoDeclaracao(simbolo, this.corpoDaFuncao(tipo));
|
|
663
|
-
}
|
|
664
|
-
logicaComumParametros() {
|
|
665
|
-
const parametros = [];
|
|
666
|
-
do {
|
|
667
|
-
if (parametros.length >= 255) {
|
|
668
|
-
this.erro(this.simboloAtual(), 'Não pode haver mais de 255 parâmetros');
|
|
669
|
-
}
|
|
670
|
-
const parametro = {};
|
|
671
|
-
if (this.simboloAtual().tipo === pitugues_1.default.MULTIPLICACAO) {
|
|
672
|
-
this.consumir(pitugues_1.default.MULTIPLICACAO, null);
|
|
673
|
-
parametro['tipo'] = 'multiplo';
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
parametro['tipo'] = 'padrao';
|
|
677
|
-
}
|
|
678
|
-
parametro['nome'] = this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome do parâmetro.');
|
|
679
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IGUAL)) {
|
|
680
|
-
parametro['valorPadrao'] = this.primario();
|
|
681
|
-
}
|
|
682
|
-
parametros.push(parametro);
|
|
683
|
-
if (parametro['tipo'] === 'multiplo')
|
|
684
|
-
break;
|
|
685
|
-
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
686
|
-
return parametros;
|
|
687
|
-
}
|
|
688
|
-
corpoDaFuncao(tipo) {
|
|
689
|
-
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, `Esperado '(' após o nome ${tipo}.`);
|
|
690
|
-
let parametros = [];
|
|
691
|
-
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PARENTESE_DIREITO)) {
|
|
692
|
-
parametros = this.logicaComumParametros();
|
|
693
|
-
}
|
|
694
|
-
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
695
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, `Esperado ':' antes do escopo do ${tipo}.`);
|
|
696
|
-
const corpo = this.blocoEscopo();
|
|
697
|
-
return new construtos_1.FuncaoConstruto(this.hashArquivo, 0, parametros, corpo);
|
|
698
|
-
}
|
|
699
|
-
declaracaoDeClasse() {
|
|
700
|
-
const simbolo = this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
701
|
-
let superClasse = null;
|
|
702
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.HERDA)) {
|
|
703
|
-
this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome da Superclasse.');
|
|
704
|
-
superClasse = new construtos_1.Variavel(this.hashArquivo, this.simboloAnterior());
|
|
705
|
-
}
|
|
706
|
-
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' antes do escopo da classe.");
|
|
707
|
-
const metodos = [];
|
|
708
|
-
while (!this.estaNoFinal() &&
|
|
709
|
-
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CONSTRUTOR, pitugues_1.default.FUNCAO, pitugues_1.default.FUNÇÃO)) {
|
|
710
|
-
metodos.push(this.funcao('método', this.simbolos[this.atual - 1].tipo === pitugues_1.default.CONSTRUTOR));
|
|
711
|
-
}
|
|
712
|
-
return new declaracoes_1.Classe(simbolo, superClasse, metodos);
|
|
713
|
-
}
|
|
714
|
-
declaracaoFalhar() {
|
|
715
|
-
const simboloFalha = this.simbolos[this.atual - 1];
|
|
716
|
-
const textoFalha = this.consumir(pitugues_1.default.TEXTO, 'Esperado texto para explicar falha.');
|
|
717
|
-
return new declaracoes_1.Falhar(simboloFalha, textoFalha.literal);
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* Consome o símbolo atual, verificando se é uma declaração de função, variável, classe
|
|
721
|
-
* ou uma expressão.
|
|
722
|
-
* @returns Objeto do tipo `Declaracao`.
|
|
723
|
-
*/
|
|
724
|
-
resolverDeclaracaoForaDeBloco() {
|
|
725
|
-
try {
|
|
726
|
-
if ((this.verificarTipoSimboloAtual(pitugues_1.default.FUNCAO) ||
|
|
727
|
-
this.verificarTipoSimboloAtual(pitugues_1.default.FUNÇÃO)) &&
|
|
728
|
-
this.verificarTipoProximoSimbolo(pitugues_1.default.IDENTIFICADOR)) {
|
|
729
|
-
this.avancarEDevolverAnterior();
|
|
730
|
-
return this.funcao('funcao');
|
|
731
|
-
}
|
|
732
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CLASSE))
|
|
733
|
-
return this.declaracaoDeClasse();
|
|
734
|
-
return this.resolverDeclaracao();
|
|
735
|
-
}
|
|
736
|
-
catch (erro) {
|
|
737
|
-
this.sincronizar();
|
|
738
|
-
return null;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
analisar(retornoLexador, hashArquivo) {
|
|
742
|
-
const inicioAnalise = (0, browser_process_hrtime_1.default)();
|
|
743
|
-
this.erros = [];
|
|
744
|
-
this.atual = 0;
|
|
745
|
-
this.blocos = 0;
|
|
746
|
-
this.escopos = [];
|
|
747
|
-
this.hashArquivo = hashArquivo || 0;
|
|
748
|
-
this.simbolos = (retornoLexador === null || retornoLexador === void 0 ? void 0 : retornoLexador.simbolos) || [];
|
|
749
|
-
this.pragmas = (retornoLexador === null || retornoLexador === void 0 ? void 0 : retornoLexador.pragmas) || {};
|
|
750
|
-
let declaracoes = [];
|
|
751
|
-
while (!this.estaNoFinal()) {
|
|
752
|
-
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
753
|
-
if (Array.isArray(retornoDeclaracao)) {
|
|
754
|
-
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
755
|
-
}
|
|
756
|
-
else {
|
|
757
|
-
declaracoes.push(retornoDeclaracao);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
if (this.performance) {
|
|
761
|
-
const deltaAnalise = (0, browser_process_hrtime_1.default)(inicioAnalise);
|
|
762
|
-
console.log(`[Avaliador Sintático] Tempo para análise: ${deltaAnalise[0] * 1e9 + deltaAnalise[1]}ns`);
|
|
763
|
-
}
|
|
764
|
-
return {
|
|
765
|
-
declaracoes: declaracoes,
|
|
766
|
-
erros: this.erros,
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
exports.AvaliadorSintaticoPitugues = AvaliadorSintaticoPitugues;
|
|
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.AvaliadorSintaticoPitugues = void 0;
|
|
7
|
+
const browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime"));
|
|
8
|
+
const construtos_1 = require("../../construtos");
|
|
9
|
+
const declaracoes_1 = require("../../declaracoes");
|
|
10
|
+
const erro_avaliador_sintatico_1 = require("../erro-avaliador-sintatico");
|
|
11
|
+
const pitugues_1 = __importDefault(require("../../tipos-de-simbolos/pitugues"));
|
|
12
|
+
const lexador_1 = require("../../lexador");
|
|
13
|
+
/**
|
|
14
|
+
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
15
|
+
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
16
|
+
* Há dois grupos de estruturas de alto nível: Construtos e Declarações.
|
|
17
|
+
*
|
|
18
|
+
* A grande diferença entre este avaliador e os demais é a forma como são entendidos os blocos de escopo.
|
|
19
|
+
* Este avaliador espera uma estrutura de pragmas, que explica quantos espaços há na frente de cada linha.
|
|
20
|
+
*/
|
|
21
|
+
class AvaliadorSintaticoPitugues {
|
|
22
|
+
constructor(performance = false) {
|
|
23
|
+
this.atual = 0;
|
|
24
|
+
this.blocos = 0;
|
|
25
|
+
this.performance = performance;
|
|
26
|
+
this.escopos = [];
|
|
27
|
+
}
|
|
28
|
+
declaracaoDeConstantes() {
|
|
29
|
+
throw new Error('Método não implementado.');
|
|
30
|
+
}
|
|
31
|
+
declaracaoDeVariavel() {
|
|
32
|
+
throw new Error('Método não implementado.');
|
|
33
|
+
}
|
|
34
|
+
declaracaoDeVariaveis() {
|
|
35
|
+
const identificadores = [];
|
|
36
|
+
let retorno = [];
|
|
37
|
+
do {
|
|
38
|
+
identificadores.push(this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome de variável.'));
|
|
39
|
+
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
40
|
+
if (!this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IGUAL)) {
|
|
41
|
+
for (let [indice, identificador] of identificadores.entries()) {
|
|
42
|
+
retorno.push(new declaracoes_1.Var(identificador, null));
|
|
43
|
+
}
|
|
44
|
+
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO_E_VIRGULA);
|
|
45
|
+
return retorno;
|
|
46
|
+
}
|
|
47
|
+
//this.consumir(tiposDeSimbolos.IGUAL, "Esperado '=' após identificador em instrução 'var'.");
|
|
48
|
+
const inicializadores = [];
|
|
49
|
+
do {
|
|
50
|
+
inicializadores.push(this.expressao());
|
|
51
|
+
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
52
|
+
if (identificadores.length !== inicializadores.length) {
|
|
53
|
+
throw this.erro(this.simboloAtual(), 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
54
|
+
}
|
|
55
|
+
for (let [indice, identificador] of identificadores.entries()) {
|
|
56
|
+
retorno.push(new declaracoes_1.Var(identificador, inicializadores[indice]));
|
|
57
|
+
}
|
|
58
|
+
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO_E_VIRGULA);
|
|
59
|
+
return retorno;
|
|
60
|
+
}
|
|
61
|
+
sincronizar() {
|
|
62
|
+
this.avancarEDevolverAnterior();
|
|
63
|
+
while (!this.estaNoFinal()) {
|
|
64
|
+
switch (this.simboloAtual().tipo) {
|
|
65
|
+
case pitugues_1.default.CLASSE:
|
|
66
|
+
case pitugues_1.default.FUNCAO:
|
|
67
|
+
case pitugues_1.default.FUNÇÃO:
|
|
68
|
+
case pitugues_1.default.VARIAVEL:
|
|
69
|
+
case pitugues_1.default.PARA:
|
|
70
|
+
case pitugues_1.default.SE:
|
|
71
|
+
case pitugues_1.default.ENQUANTO:
|
|
72
|
+
case pitugues_1.default.ESCREVA:
|
|
73
|
+
case pitugues_1.default.RETORNA:
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.avancarEDevolverAnterior();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
erro(simbolo, mensagemDeErro) {
|
|
80
|
+
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simbolo, mensagemDeErro);
|
|
81
|
+
this.erros.push(excecao);
|
|
82
|
+
return excecao;
|
|
83
|
+
}
|
|
84
|
+
consumir(tipo, mensagemDeErro) {
|
|
85
|
+
if (this.verificarTipoSimboloAtual(tipo))
|
|
86
|
+
return this.avancarEDevolverAnterior();
|
|
87
|
+
throw this.erro(this.simboloAtual(), mensagemDeErro);
|
|
88
|
+
}
|
|
89
|
+
verificarTipoSimboloAtual(tipo) {
|
|
90
|
+
if (this.estaNoFinal())
|
|
91
|
+
return false;
|
|
92
|
+
return this.simboloAtual().tipo === tipo;
|
|
93
|
+
}
|
|
94
|
+
verificarTipoProximoSimbolo(tipo) {
|
|
95
|
+
if (this.estaNoFinal())
|
|
96
|
+
return false;
|
|
97
|
+
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
98
|
+
}
|
|
99
|
+
simboloAtual() {
|
|
100
|
+
return this.simbolos[this.atual];
|
|
101
|
+
}
|
|
102
|
+
simboloAnterior() {
|
|
103
|
+
return this.simbolos[this.atual - 1];
|
|
104
|
+
}
|
|
105
|
+
simboloNaPosicao(posicao) {
|
|
106
|
+
return this.simbolos[this.atual + posicao];
|
|
107
|
+
}
|
|
108
|
+
estaNoFinal() {
|
|
109
|
+
return this.atual >= this.simbolos.length;
|
|
110
|
+
}
|
|
111
|
+
avancarEDevolverAnterior() {
|
|
112
|
+
if (!this.estaNoFinal())
|
|
113
|
+
this.atual += 1;
|
|
114
|
+
return this.simboloAnterior();
|
|
115
|
+
}
|
|
116
|
+
verificarSeSimboloAtualEIgualA(...argumentos) {
|
|
117
|
+
for (let i = 0; i < argumentos.length; i++) {
|
|
118
|
+
const tipoAtual = argumentos[i];
|
|
119
|
+
if (this.verificarTipoSimboloAtual(tipoAtual)) {
|
|
120
|
+
this.avancarEDevolverAnterior();
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
primario() {
|
|
127
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SUPER)) {
|
|
128
|
+
const simboloChave = this.simboloAnterior();
|
|
129
|
+
this.consumir(pitugues_1.default.PONTO, "Esperado '.' após 'super'.");
|
|
130
|
+
const metodo = this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome do método da Superclasse.');
|
|
131
|
+
return new construtos_1.Super(this.hashArquivo, simboloChave, metodo);
|
|
132
|
+
}
|
|
133
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_ESQUERDO)) {
|
|
134
|
+
const valores = [];
|
|
135
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_DIREITO)) {
|
|
136
|
+
return new construtos_1.Vetor(this.hashArquivo, 0, []);
|
|
137
|
+
}
|
|
138
|
+
while (!this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_DIREITO)) {
|
|
139
|
+
const valor = this.atribuir();
|
|
140
|
+
valores.push(valor);
|
|
141
|
+
if (this.simboloAtual().tipo !== pitugues_1.default.COLCHETE_DIREITO) {
|
|
142
|
+
this.consumir(pitugues_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return new construtos_1.Vetor(this.hashArquivo, 0, valores);
|
|
146
|
+
}
|
|
147
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CHAVE_ESQUERDA)) {
|
|
148
|
+
const chaves = [];
|
|
149
|
+
const valores = [];
|
|
150
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CHAVE_DIREITA)) {
|
|
151
|
+
return new construtos_1.Dicionario(this.hashArquivo, 0, [], []);
|
|
152
|
+
}
|
|
153
|
+
while (!this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CHAVE_DIREITA)) {
|
|
154
|
+
const chave = this.atribuir();
|
|
155
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' entre chave e valor.");
|
|
156
|
+
const valor = this.atribuir();
|
|
157
|
+
chaves.push(chave);
|
|
158
|
+
valores.push(valor);
|
|
159
|
+
if (this.simboloAtual().tipo !== pitugues_1.default.CHAVE_DIREITA) {
|
|
160
|
+
this.consumir(pitugues_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return new construtos_1.Dicionario(this.hashArquivo, 0, chaves, valores);
|
|
164
|
+
}
|
|
165
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.FALSO))
|
|
166
|
+
return new construtos_1.Literal(this.hashArquivo, 0, false);
|
|
167
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VERDADEIRO))
|
|
168
|
+
return new construtos_1.Literal(this.hashArquivo, 0, true);
|
|
169
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.NULO))
|
|
170
|
+
return new construtos_1.Literal(this.hashArquivo, 0, null);
|
|
171
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.ISTO))
|
|
172
|
+
return new construtos_1.Isto(this.hashArquivo, 0, this.simboloAnterior());
|
|
173
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.NUMERO, pitugues_1.default.TEXTO)) {
|
|
174
|
+
const simboloAnterior = this.simboloAnterior();
|
|
175
|
+
return new construtos_1.Literal(this.hashArquivo, Number(simboloAnterior.linha), simboloAnterior.literal);
|
|
176
|
+
}
|
|
177
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IDENTIFICADOR)) {
|
|
178
|
+
return new construtos_1.Variavel(this.hashArquivo, this.simboloAnterior());
|
|
179
|
+
}
|
|
180
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PARENTESE_ESQUERDO)) {
|
|
181
|
+
const expressao = this.expressao();
|
|
182
|
+
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
183
|
+
return new construtos_1.Agrupamento(this.hashArquivo, 0, expressao);
|
|
184
|
+
}
|
|
185
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IMPORTAR))
|
|
186
|
+
return this.declaracaoImportar();
|
|
187
|
+
throw this.erro(this.simboloAtual(), 'Esperado expressão.');
|
|
188
|
+
}
|
|
189
|
+
finalizarChamada(entidadeChamada) {
|
|
190
|
+
const argumentos = [];
|
|
191
|
+
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PARENTESE_DIREITO)) {
|
|
192
|
+
do {
|
|
193
|
+
if (argumentos.length >= 255) {
|
|
194
|
+
throw this.erro(this.simboloAtual(), 'Não pode haver mais de 255 argumentos.');
|
|
195
|
+
}
|
|
196
|
+
argumentos.push(this.expressao());
|
|
197
|
+
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
198
|
+
}
|
|
199
|
+
const parenteseDireito = this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos.");
|
|
200
|
+
return new construtos_1.Chamada(this.hashArquivo, entidadeChamada, parenteseDireito, argumentos);
|
|
201
|
+
}
|
|
202
|
+
chamar() {
|
|
203
|
+
let expressao = this.primario();
|
|
204
|
+
while (true) {
|
|
205
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PARENTESE_ESQUERDO)) {
|
|
206
|
+
expressao = this.finalizarChamada(expressao);
|
|
207
|
+
}
|
|
208
|
+
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO)) {
|
|
209
|
+
const nome = this.consumir(pitugues_1.default.IDENTIFICADOR, "Esperado nome do método após '.'.");
|
|
210
|
+
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
211
|
+
}
|
|
212
|
+
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.COLCHETE_ESQUERDO)) {
|
|
213
|
+
const indice = this.expressao();
|
|
214
|
+
const simboloFechamento = this.consumir(pitugues_1.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
215
|
+
expressao = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, expressao, indice, simboloFechamento);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return expressao;
|
|
222
|
+
}
|
|
223
|
+
unario() {
|
|
224
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.NEGACAO, pitugues_1.default.SUBTRACAO, pitugues_1.default.BIT_NOT)) {
|
|
225
|
+
const operador = this.simboloAnterior();
|
|
226
|
+
const direito = this.unario();
|
|
227
|
+
return new construtos_1.Unario(this.hashArquivo, operador, direito);
|
|
228
|
+
}
|
|
229
|
+
return this.chamar();
|
|
230
|
+
}
|
|
231
|
+
exponenciacao() {
|
|
232
|
+
let expressao = this.unario();
|
|
233
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.EXPONENCIACAO)) {
|
|
234
|
+
const operador = this.simboloAnterior();
|
|
235
|
+
const direito = this.unario();
|
|
236
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
237
|
+
}
|
|
238
|
+
return expressao;
|
|
239
|
+
}
|
|
240
|
+
multiplicar() {
|
|
241
|
+
let expressao = this.exponenciacao();
|
|
242
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.DIVISAO, pitugues_1.default.DIVISAO_INTEIRA, pitugues_1.default.MULTIPLICACAO, pitugues_1.default.MODULO)) {
|
|
243
|
+
const operador = this.simboloAnterior();
|
|
244
|
+
const direito = this.exponenciacao();
|
|
245
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
246
|
+
}
|
|
247
|
+
return expressao;
|
|
248
|
+
}
|
|
249
|
+
adicaoOuSubtracao() {
|
|
250
|
+
let expressao = this.multiplicar();
|
|
251
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SUBTRACAO, pitugues_1.default.ADICAO)) {
|
|
252
|
+
const operador = this.simboloAnterior();
|
|
253
|
+
const direito = this.multiplicar();
|
|
254
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
255
|
+
}
|
|
256
|
+
return expressao;
|
|
257
|
+
}
|
|
258
|
+
bitShift() {
|
|
259
|
+
let expressao = this.adicaoOuSubtracao();
|
|
260
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.MENOR_MENOR, pitugues_1.default.MAIOR_MAIOR)) {
|
|
261
|
+
const operador = this.simboloAnterior();
|
|
262
|
+
const direito = this.adicaoOuSubtracao();
|
|
263
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
264
|
+
}
|
|
265
|
+
return expressao;
|
|
266
|
+
}
|
|
267
|
+
bitE() {
|
|
268
|
+
let expressao = this.bitShift();
|
|
269
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.BIT_AND)) {
|
|
270
|
+
const operador = this.simboloAnterior();
|
|
271
|
+
const direito = this.bitShift();
|
|
272
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
273
|
+
}
|
|
274
|
+
return expressao;
|
|
275
|
+
}
|
|
276
|
+
bitOu() {
|
|
277
|
+
let expressao = this.bitE();
|
|
278
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.BIT_OR, pitugues_1.default.BIT_XOR)) {
|
|
279
|
+
const operador = this.simboloAnterior();
|
|
280
|
+
const direito = this.bitE();
|
|
281
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
282
|
+
}
|
|
283
|
+
return expressao;
|
|
284
|
+
}
|
|
285
|
+
comparar() {
|
|
286
|
+
let expressao = this.bitOu();
|
|
287
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.MAIOR, pitugues_1.default.MAIOR_IGUAL, pitugues_1.default.MENOR, pitugues_1.default.MENOR_IGUAL)) {
|
|
288
|
+
const operador = this.simboloAnterior();
|
|
289
|
+
const direito = this.bitOu();
|
|
290
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
291
|
+
}
|
|
292
|
+
return expressao;
|
|
293
|
+
}
|
|
294
|
+
comparacaoIgualdade() {
|
|
295
|
+
let expressao = this.comparar();
|
|
296
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.DIFERENTE, pitugues_1.default.IGUAL_IGUAL)) {
|
|
297
|
+
const operador = this.simboloAnterior();
|
|
298
|
+
const direito = this.comparar();
|
|
299
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
300
|
+
}
|
|
301
|
+
return expressao;
|
|
302
|
+
}
|
|
303
|
+
em() {
|
|
304
|
+
let expressao = this.comparacaoIgualdade();
|
|
305
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.EM)) {
|
|
306
|
+
const operador = this.simboloAnterior();
|
|
307
|
+
const direito = this.comparacaoIgualdade();
|
|
308
|
+
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
309
|
+
}
|
|
310
|
+
return expressao;
|
|
311
|
+
}
|
|
312
|
+
e() {
|
|
313
|
+
let expressao = this.em();
|
|
314
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.E)) {
|
|
315
|
+
const operador = this.simboloAnterior();
|
|
316
|
+
const direito = this.em();
|
|
317
|
+
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
318
|
+
}
|
|
319
|
+
return expressao;
|
|
320
|
+
}
|
|
321
|
+
ou() {
|
|
322
|
+
let expressao = this.e();
|
|
323
|
+
while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.OU)) {
|
|
324
|
+
const operador = this.simboloAnterior();
|
|
325
|
+
const direito = this.e();
|
|
326
|
+
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
327
|
+
}
|
|
328
|
+
return expressao;
|
|
329
|
+
}
|
|
330
|
+
atribuir() {
|
|
331
|
+
const expressao = this.ou();
|
|
332
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IGUAL) ||
|
|
333
|
+
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.MAIS_IGUAL)) {
|
|
334
|
+
const igual = this.simboloAnterior();
|
|
335
|
+
const valor = this.atribuir();
|
|
336
|
+
if (expressao instanceof construtos_1.Variavel) {
|
|
337
|
+
const simbolo = expressao.simbolo;
|
|
338
|
+
return new construtos_1.Atribuir(this.hashArquivo, simbolo, valor);
|
|
339
|
+
}
|
|
340
|
+
else if (expressao instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
341
|
+
return new construtos_1.DefinirValor(this.hashArquivo, 0, expressao.objeto, expressao.simbolo, valor);
|
|
342
|
+
}
|
|
343
|
+
else if (expressao instanceof construtos_1.AcessoIndiceVariavel) {
|
|
344
|
+
return new construtos_1.AtribuicaoPorIndice(this.hashArquivo, 0, expressao.entidadeChamada, expressao.indice, valor);
|
|
345
|
+
}
|
|
346
|
+
this.erro(igual, 'Tarefa de atribuição inválida');
|
|
347
|
+
}
|
|
348
|
+
return expressao;
|
|
349
|
+
}
|
|
350
|
+
expressao() {
|
|
351
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.LEIA))
|
|
352
|
+
return this.declaracaoLeia();
|
|
353
|
+
return this.atribuir();
|
|
354
|
+
}
|
|
355
|
+
declaracaoEscreva() {
|
|
356
|
+
const simboloAtual = this.simboloAtual();
|
|
357
|
+
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em escreva.");
|
|
358
|
+
const argumentos = [];
|
|
359
|
+
do {
|
|
360
|
+
argumentos.push(this.expressao());
|
|
361
|
+
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
362
|
+
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em escreva.");
|
|
363
|
+
return new declaracoes_1.Escreva(Number(simboloAtual.linha), simboloAtual.hashArquivo, argumentos);
|
|
364
|
+
}
|
|
365
|
+
declaracaoExpressao() {
|
|
366
|
+
const expressao = this.expressao();
|
|
367
|
+
return new declaracoes_1.Expressao(expressao);
|
|
368
|
+
}
|
|
369
|
+
declaracaoLeia() {
|
|
370
|
+
const simboloLeia = this.simbolos[this.atual];
|
|
371
|
+
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em leia.");
|
|
372
|
+
const argumentos = [];
|
|
373
|
+
do {
|
|
374
|
+
argumentos.push(this.expressao());
|
|
375
|
+
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
376
|
+
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em leia.");
|
|
377
|
+
return new declaracoes_1.Leia(simboloLeia, argumentos);
|
|
378
|
+
}
|
|
379
|
+
blocoEscopo() {
|
|
380
|
+
let declaracoes = [];
|
|
381
|
+
let simboloAtual = this.simboloAtual();
|
|
382
|
+
const simboloAnterior = this.simboloAnterior();
|
|
383
|
+
// Situação 1: não tem bloco de escopo.
|
|
384
|
+
//
|
|
385
|
+
// Exemplo: `se verdadeiro: escreva('Alguma coisa')`.
|
|
386
|
+
// Neste caso, linha do símbolo atual é igual à linha do símbolo anterior.
|
|
387
|
+
if (simboloAtual.linha === simboloAnterior.linha) {
|
|
388
|
+
declaracoes.push(this.resolverDeclaracaoForaDeBloco());
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
// Situação 2: símbolo atual fica na próxima linha.
|
|
392
|
+
//
|
|
393
|
+
// Verifica-se o número de espaços à esquerda da linha através dos pragmas.
|
|
394
|
+
// Se número de espaços da linha do símbolo atual é menor ou igual ao número de espaços
|
|
395
|
+
// da linha anterior, e bloco ainda não começou, é uma situação de erro.
|
|
396
|
+
let espacosIndentacaoLinhaAtual = this.pragmas[simboloAtual.linha].espacosIndentacao;
|
|
397
|
+
const espacosIndentacaoLinhaAnterior = this.pragmas[simboloAnterior.linha].espacosIndentacao;
|
|
398
|
+
if (espacosIndentacaoLinhaAtual <= espacosIndentacaoLinhaAnterior) {
|
|
399
|
+
this.erro(simboloAtual, `Indentação inconsistente na linha ${simboloAtual.linha}. ` +
|
|
400
|
+
`Esperado: >= ${espacosIndentacaoLinhaAnterior}. ` +
|
|
401
|
+
`Atual: ${espacosIndentacaoLinhaAtual}`);
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
// Indentação ok, é um bloco de escopo.
|
|
405
|
+
// Inclui todas as declarações cujas linhas tenham o mesmo número de espaços
|
|
406
|
+
// de indentação do bloco.
|
|
407
|
+
// Se `simboloAtual` for definido em algum momento como indefinido,
|
|
408
|
+
// Significa que o código acabou, então o bloco também acabou.
|
|
409
|
+
const espacosIndentacaoBloco = espacosIndentacaoLinhaAtual;
|
|
410
|
+
while (espacosIndentacaoLinhaAtual === espacosIndentacaoBloco) {
|
|
411
|
+
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
412
|
+
if (Array.isArray(retornoDeclaracao)) {
|
|
413
|
+
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
declaracoes.push(retornoDeclaracao);
|
|
417
|
+
}
|
|
418
|
+
simboloAtual = this.simboloAtual();
|
|
419
|
+
if (!simboloAtual)
|
|
420
|
+
break;
|
|
421
|
+
espacosIndentacaoLinhaAtual = this.pragmas[simboloAtual.linha].espacosIndentacao;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return declaracoes;
|
|
426
|
+
}
|
|
427
|
+
declaracaoEnquanto() {
|
|
428
|
+
try {
|
|
429
|
+
this.blocos += 1;
|
|
430
|
+
const condicao = this.expressao();
|
|
431
|
+
const bloco = this.resolverDeclaracao();
|
|
432
|
+
return new declaracoes_1.Enquanto(condicao, bloco);
|
|
433
|
+
}
|
|
434
|
+
finally {
|
|
435
|
+
this.blocos -= 1;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
declaracaoEscolha() {
|
|
439
|
+
try {
|
|
440
|
+
this.blocos += 1;
|
|
441
|
+
const condicao = this.expressao();
|
|
442
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após 'escolha'.");
|
|
443
|
+
const caminhos = [];
|
|
444
|
+
let caminhoPadrao = null;
|
|
445
|
+
while (!this.estaNoFinal() &&
|
|
446
|
+
[pitugues_1.default.CASO, pitugues_1.default.PADRAO].includes(this.simbolos[this.atual].tipo)) {
|
|
447
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CASO)) {
|
|
448
|
+
const caminhoCondicoes = [this.expressao()];
|
|
449
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após o 'caso'.");
|
|
450
|
+
while (this.verificarTipoSimboloAtual(pitugues_1.default.CASO)) {
|
|
451
|
+
this.consumir(pitugues_1.default.CASO, null);
|
|
452
|
+
caminhoCondicoes.push(this.expressao());
|
|
453
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'caso'.");
|
|
454
|
+
}
|
|
455
|
+
// Como dois-pontos é um símbolo usado para conferir se há um início de bloco,
|
|
456
|
+
// não podemos simplesmente chamar `this.resolverDeclaracao()` porque o dois-pontos já
|
|
457
|
+
// foi consumido na verificação.
|
|
458
|
+
// Outro problema é que, aparentemente, o Interpretador não espera um Bloco, e sim
|
|
459
|
+
// um vetor de Declaracao, o qual obtemos com `this.blocoEscopo()`.
|
|
460
|
+
const declaracoes = this.blocoEscopo();
|
|
461
|
+
caminhos.push({
|
|
462
|
+
condicoes: caminhoCondicoes,
|
|
463
|
+
declaracoes,
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PADRAO)) {
|
|
467
|
+
if (caminhoPadrao !== null) {
|
|
468
|
+
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.simboloAtual(), "Você só pode ter um caminho padrão em cada declaração de 'escolha'.");
|
|
469
|
+
this.erros.push(excecao);
|
|
470
|
+
throw excecao;
|
|
471
|
+
}
|
|
472
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'padrao'.");
|
|
473
|
+
// Como dois-pontos é um símbolo usado para conferir se há um início de bloco,
|
|
474
|
+
// não podemos simplesmente chamar `this.resolverDeclaracao()` porque o dois-pontos já
|
|
475
|
+
// foi consumido na verificação.
|
|
476
|
+
// Outro problema é que, aparentemente, o Interpretador não espera um Bloco, e sim
|
|
477
|
+
// um vetor de Declaracao, o qual obtemos com `this.blocoEscopo()`.
|
|
478
|
+
const declaracoes = this.blocoEscopo();
|
|
479
|
+
caminhoPadrao = {
|
|
480
|
+
declaracoes,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return new declaracoes_1.Escolha(condicao, caminhos, caminhoPadrao);
|
|
485
|
+
}
|
|
486
|
+
finally {
|
|
487
|
+
this.blocos -= 1;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
declaracaoPara() {
|
|
491
|
+
try {
|
|
492
|
+
const simboloPara = this.simboloAnterior();
|
|
493
|
+
this.blocos += 1;
|
|
494
|
+
let inicializador;
|
|
495
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PONTO_E_VIRGULA)) {
|
|
496
|
+
inicializador = null;
|
|
497
|
+
}
|
|
498
|
+
else if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VARIAVEL)) {
|
|
499
|
+
inicializador = this.declaracaoDeVariaveis();
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
inicializador = this.declaracaoExpressao();
|
|
503
|
+
}
|
|
504
|
+
let condicao = null;
|
|
505
|
+
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PONTO_E_VIRGULA)) {
|
|
506
|
+
condicao = this.expressao();
|
|
507
|
+
}
|
|
508
|
+
let incrementar = null;
|
|
509
|
+
if (this.simbolos[this.atual].tipo !== pitugues_1.default.DOIS_PONTOS) {
|
|
510
|
+
incrementar = this.expressao();
|
|
511
|
+
}
|
|
512
|
+
const corpo = this.resolverDeclaracao();
|
|
513
|
+
return new declaracoes_1.Para(this.hashArquivo, Number(simboloPara.linha), inicializador, condicao, incrementar, corpo);
|
|
514
|
+
}
|
|
515
|
+
catch (erro) {
|
|
516
|
+
throw erro;
|
|
517
|
+
}
|
|
518
|
+
finally {
|
|
519
|
+
this.blocos -= 1;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
declaracaoSe() {
|
|
523
|
+
const condicao = this.expressao();
|
|
524
|
+
const caminhoEntao = this.resolverDeclaracao();
|
|
525
|
+
let caminhoSenao = null;
|
|
526
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SENAO, pitugues_1.default.SENÃO)) {
|
|
527
|
+
caminhoSenao = this.resolverDeclaracao();
|
|
528
|
+
}
|
|
529
|
+
return new declaracoes_1.Se(condicao, caminhoEntao, [], caminhoSenao);
|
|
530
|
+
}
|
|
531
|
+
declaracaoSustar() {
|
|
532
|
+
if (this.blocos < 1) {
|
|
533
|
+
this.erro(this.simboloAnterior(), "'sustar' deve estar dentro de um laço de repetição.");
|
|
534
|
+
}
|
|
535
|
+
return new declaracoes_1.Sustar(this.simboloAtual());
|
|
536
|
+
}
|
|
537
|
+
declaracaoContinua() {
|
|
538
|
+
if (this.blocos < 1) {
|
|
539
|
+
this.erro(this.simboloAnterior(), "'continua' precisa estar em um laço de repetição.");
|
|
540
|
+
}
|
|
541
|
+
return new declaracoes_1.Continua(this.simboloAtual());
|
|
542
|
+
}
|
|
543
|
+
declaracaoRetorna() {
|
|
544
|
+
const palavraChave = this.simboloAnterior();
|
|
545
|
+
let valor = null;
|
|
546
|
+
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PONTO_E_VIRGULA)) {
|
|
547
|
+
valor = this.expressao();
|
|
548
|
+
}
|
|
549
|
+
return new declaracoes_1.Retorna(palavraChave, valor);
|
|
550
|
+
}
|
|
551
|
+
declaracaoImportar() {
|
|
552
|
+
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
|
|
553
|
+
const caminho = this.expressao();
|
|
554
|
+
const simboloFechamento = this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
555
|
+
return new declaracoes_1.Importar(caminho, simboloFechamento);
|
|
556
|
+
}
|
|
557
|
+
declaracaoTente() {
|
|
558
|
+
const simboloTente = this.simboloAnterior();
|
|
559
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'tente'.");
|
|
560
|
+
const blocoTente = this.blocoEscopo();
|
|
561
|
+
let blocoPegue = null;
|
|
562
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.PEGUE)) {
|
|
563
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'pegue'.");
|
|
564
|
+
blocoPegue = this.blocoEscopo();
|
|
565
|
+
}
|
|
566
|
+
let blocoSenao = null;
|
|
567
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.SENAO, pitugues_1.default.SENÃO)) {
|
|
568
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'senão'.");
|
|
569
|
+
blocoSenao = this.blocoEscopo();
|
|
570
|
+
}
|
|
571
|
+
let blocoFinalmente = null;
|
|
572
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.FINALMENTE)) {
|
|
573
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' após a declaração 'pegue'.");
|
|
574
|
+
blocoFinalmente = this.blocoEscopo();
|
|
575
|
+
}
|
|
576
|
+
return new declaracoes_1.Tente(simboloTente.hashArquivo, Number(simboloTente.linha), blocoTente, blocoPegue, blocoSenao, blocoFinalmente);
|
|
577
|
+
}
|
|
578
|
+
declaracaoFazer() {
|
|
579
|
+
const simboloFazer = this.simboloAnterior();
|
|
580
|
+
try {
|
|
581
|
+
this.blocos += 1;
|
|
582
|
+
const declaracaoOuBlocoFazer = this.resolverDeclaracao();
|
|
583
|
+
this.consumir(pitugues_1.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo da declaração 'fazer'.");
|
|
584
|
+
const condicaoEnquanto = this.expressao();
|
|
585
|
+
return new declaracoes_1.Fazer(simboloFazer.hashArquivo, Number(simboloFazer.linha), declaracaoOuBlocoFazer, condicaoEnquanto);
|
|
586
|
+
}
|
|
587
|
+
finally {
|
|
588
|
+
this.blocos -= 1;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
resolverDeclaracao() {
|
|
592
|
+
switch (this.simbolos[this.atual].tipo) {
|
|
593
|
+
case pitugues_1.default.CONSTANTE:
|
|
594
|
+
this.avancarEDevolverAnterior();
|
|
595
|
+
return this.declaracaoDeConstantes();
|
|
596
|
+
case pitugues_1.default.CONTINUA:
|
|
597
|
+
this.avancarEDevolverAnterior();
|
|
598
|
+
return this.declaracaoContinua();
|
|
599
|
+
case pitugues_1.default.DOIS_PONTOS:
|
|
600
|
+
this.avancarEDevolverAnterior();
|
|
601
|
+
const simboloInicioBloco = this.simboloAnterior();
|
|
602
|
+
return new declaracoes_1.Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
603
|
+
case pitugues_1.default.ENQUANTO:
|
|
604
|
+
this.avancarEDevolverAnterior();
|
|
605
|
+
return this.declaracaoEnquanto();
|
|
606
|
+
case pitugues_1.default.ESCOLHA:
|
|
607
|
+
this.avancarEDevolverAnterior();
|
|
608
|
+
return this.declaracaoEscolha();
|
|
609
|
+
case pitugues_1.default.ESCREVA:
|
|
610
|
+
this.avancarEDevolverAnterior();
|
|
611
|
+
return this.declaracaoEscreva();
|
|
612
|
+
case pitugues_1.default.FALHAR:
|
|
613
|
+
this.avancarEDevolverAnterior();
|
|
614
|
+
return this.declaracaoFalhar();
|
|
615
|
+
case pitugues_1.default.FAZER:
|
|
616
|
+
this.avancarEDevolverAnterior();
|
|
617
|
+
return this.declaracaoFazer();
|
|
618
|
+
case pitugues_1.default.PARA:
|
|
619
|
+
this.avancarEDevolverAnterior();
|
|
620
|
+
return this.declaracaoPara();
|
|
621
|
+
case pitugues_1.default.PAUSA:
|
|
622
|
+
case pitugues_1.default.SUSTAR:
|
|
623
|
+
this.avancarEDevolverAnterior();
|
|
624
|
+
return this.declaracaoSustar();
|
|
625
|
+
case pitugues_1.default.SE:
|
|
626
|
+
this.avancarEDevolverAnterior();
|
|
627
|
+
return this.declaracaoSe();
|
|
628
|
+
case pitugues_1.default.RETORNA:
|
|
629
|
+
this.avancarEDevolverAnterior();
|
|
630
|
+
return this.declaracaoRetorna();
|
|
631
|
+
case pitugues_1.default.TENTE:
|
|
632
|
+
this.avancarEDevolverAnterior();
|
|
633
|
+
return this.declaracaoTente();
|
|
634
|
+
case pitugues_1.default.VARIAVEL:
|
|
635
|
+
this.avancarEDevolverAnterior();
|
|
636
|
+
return this.declaracaoDeVariaveis();
|
|
637
|
+
}
|
|
638
|
+
/* if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.FAZER)) return this.declaracaoFazer();
|
|
639
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.TENTE)) return this.declaracaoTente();
|
|
640
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.ESCOLHA)) return this.declaracaoEscolha();
|
|
641
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.RETORNA)) return this.declaracaoRetorna();
|
|
642
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.CONTINUA)) return this.declaracaoContinua();
|
|
643
|
+
if (
|
|
644
|
+
this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.SUSTAR) ||
|
|
645
|
+
this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.PAUSA)
|
|
646
|
+
)
|
|
647
|
+
return this.declaracaoSustar();
|
|
648
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.PARA)) return this.declaracaoPara();
|
|
649
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.ENQUANTO)) return this.declaracaoEnquanto();
|
|
650
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.SE)) return this.declaracaoSe();
|
|
651
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.ESCREVA)) return this.declaracaoEscreva();
|
|
652
|
+
if (this.verificarSeSimboloAtualEIgualA(tiposDeSimbolos.DOIS_PONTOS)) {
|
|
653
|
+
const simboloInicioBloco: SimboloInterface = this.simboloAnterior();
|
|
654
|
+
return new Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
655
|
+
} */
|
|
656
|
+
return this.declaracaoExpressao();
|
|
657
|
+
}
|
|
658
|
+
funcao(tipo, construtor) {
|
|
659
|
+
const simbolo = !construtor
|
|
660
|
+
? this.consumir(pitugues_1.default.IDENTIFICADOR, `Esperado nome ${tipo}.`)
|
|
661
|
+
: new lexador_1.Simbolo(pitugues_1.default.CONSTRUTOR, 'construtor', null, -1, -1);
|
|
662
|
+
return new declaracoes_1.FuncaoDeclaracao(simbolo, this.corpoDaFuncao(tipo));
|
|
663
|
+
}
|
|
664
|
+
logicaComumParametros() {
|
|
665
|
+
const parametros = [];
|
|
666
|
+
do {
|
|
667
|
+
if (parametros.length >= 255) {
|
|
668
|
+
this.erro(this.simboloAtual(), 'Não pode haver mais de 255 parâmetros');
|
|
669
|
+
}
|
|
670
|
+
const parametro = {};
|
|
671
|
+
if (this.simboloAtual().tipo === pitugues_1.default.MULTIPLICACAO) {
|
|
672
|
+
this.consumir(pitugues_1.default.MULTIPLICACAO, null);
|
|
673
|
+
parametro['tipo'] = 'multiplo';
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
parametro['tipo'] = 'padrao';
|
|
677
|
+
}
|
|
678
|
+
parametro['nome'] = this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome do parâmetro.');
|
|
679
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.IGUAL)) {
|
|
680
|
+
parametro['valorPadrao'] = this.primario();
|
|
681
|
+
}
|
|
682
|
+
parametros.push(parametro);
|
|
683
|
+
if (parametro['tipo'] === 'multiplo')
|
|
684
|
+
break;
|
|
685
|
+
} while (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.VIRGULA));
|
|
686
|
+
return parametros;
|
|
687
|
+
}
|
|
688
|
+
corpoDaFuncao(tipo) {
|
|
689
|
+
this.consumir(pitugues_1.default.PARENTESE_ESQUERDO, `Esperado '(' após o nome ${tipo}.`);
|
|
690
|
+
let parametros = [];
|
|
691
|
+
if (!this.verificarTipoSimboloAtual(pitugues_1.default.PARENTESE_DIREITO)) {
|
|
692
|
+
parametros = this.logicaComumParametros();
|
|
693
|
+
}
|
|
694
|
+
this.consumir(pitugues_1.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
695
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, `Esperado ':' antes do escopo do ${tipo}.`);
|
|
696
|
+
const corpo = this.blocoEscopo();
|
|
697
|
+
return new construtos_1.FuncaoConstruto(this.hashArquivo, 0, parametros, corpo);
|
|
698
|
+
}
|
|
699
|
+
declaracaoDeClasse() {
|
|
700
|
+
const simbolo = this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
701
|
+
let superClasse = null;
|
|
702
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.HERDA)) {
|
|
703
|
+
this.consumir(pitugues_1.default.IDENTIFICADOR, 'Esperado nome da Superclasse.');
|
|
704
|
+
superClasse = new construtos_1.Variavel(this.hashArquivo, this.simboloAnterior());
|
|
705
|
+
}
|
|
706
|
+
this.consumir(pitugues_1.default.DOIS_PONTOS, "Esperado ':' antes do escopo da classe.");
|
|
707
|
+
const metodos = [];
|
|
708
|
+
while (!this.estaNoFinal() &&
|
|
709
|
+
this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CONSTRUTOR, pitugues_1.default.FUNCAO, pitugues_1.default.FUNÇÃO)) {
|
|
710
|
+
metodos.push(this.funcao('método', this.simbolos[this.atual - 1].tipo === pitugues_1.default.CONSTRUTOR));
|
|
711
|
+
}
|
|
712
|
+
return new declaracoes_1.Classe(simbolo, superClasse, metodos);
|
|
713
|
+
}
|
|
714
|
+
declaracaoFalhar() {
|
|
715
|
+
const simboloFalha = this.simbolos[this.atual - 1];
|
|
716
|
+
const textoFalha = this.consumir(pitugues_1.default.TEXTO, 'Esperado texto para explicar falha.');
|
|
717
|
+
return new declaracoes_1.Falhar(simboloFalha, textoFalha.literal);
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Consome o símbolo atual, verificando se é uma declaração de função, variável, classe
|
|
721
|
+
* ou uma expressão.
|
|
722
|
+
* @returns Objeto do tipo `Declaracao`.
|
|
723
|
+
*/
|
|
724
|
+
resolverDeclaracaoForaDeBloco() {
|
|
725
|
+
try {
|
|
726
|
+
if ((this.verificarTipoSimboloAtual(pitugues_1.default.FUNCAO) ||
|
|
727
|
+
this.verificarTipoSimboloAtual(pitugues_1.default.FUNÇÃO)) &&
|
|
728
|
+
this.verificarTipoProximoSimbolo(pitugues_1.default.IDENTIFICADOR)) {
|
|
729
|
+
this.avancarEDevolverAnterior();
|
|
730
|
+
return this.funcao('funcao');
|
|
731
|
+
}
|
|
732
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_1.default.CLASSE))
|
|
733
|
+
return this.declaracaoDeClasse();
|
|
734
|
+
return this.resolverDeclaracao();
|
|
735
|
+
}
|
|
736
|
+
catch (erro) {
|
|
737
|
+
this.sincronizar();
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
analisar(retornoLexador, hashArquivo) {
|
|
742
|
+
const inicioAnalise = (0, browser_process_hrtime_1.default)();
|
|
743
|
+
this.erros = [];
|
|
744
|
+
this.atual = 0;
|
|
745
|
+
this.blocos = 0;
|
|
746
|
+
this.escopos = [];
|
|
747
|
+
this.hashArquivo = hashArquivo || 0;
|
|
748
|
+
this.simbolos = (retornoLexador === null || retornoLexador === void 0 ? void 0 : retornoLexador.simbolos) || [];
|
|
749
|
+
this.pragmas = (retornoLexador === null || retornoLexador === void 0 ? void 0 : retornoLexador.pragmas) || {};
|
|
750
|
+
let declaracoes = [];
|
|
751
|
+
while (!this.estaNoFinal()) {
|
|
752
|
+
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
753
|
+
if (Array.isArray(retornoDeclaracao)) {
|
|
754
|
+
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
declaracoes.push(retornoDeclaracao);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (this.performance) {
|
|
761
|
+
const deltaAnalise = (0, browser_process_hrtime_1.default)(inicioAnalise);
|
|
762
|
+
console.log(`[Avaliador Sintático] Tempo para análise: ${deltaAnalise[0] * 1e9 + deltaAnalise[1]}ns`);
|
|
763
|
+
}
|
|
764
|
+
return {
|
|
765
|
+
declaracoes: declaracoes,
|
|
766
|
+
erros: this.erros,
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
exports.AvaliadorSintaticoPitugues = AvaliadorSintaticoPitugues;
|
|
771
771
|
//# sourceMappingURL=avaliador-sintatico-pitugues.js.map
|