@designliquido/delegua 0.61.1 → 0.61.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analisador-semantico/analisador-semantico-base.d.ts +2 -1
- package/analisador-semantico/analisador-semantico-base.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico-base.js +3 -0
- package/analisador-semantico/analisador-semantico-base.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +11 -7
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +8 -6
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +145 -85
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts +90 -0
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts.map +1 -0
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js +714 -0
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js.map +1 -0
- package/avaliador-sintatico/dialetos/index.d.ts +1 -0
- package/avaliador-sintatico/dialetos/index.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/index.js +1 -0
- package/avaliador-sintatico/dialetos/index.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts +9 -0
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/biblioteca-global.js +24 -0
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.js +1 -1
- package/bibliotecas/dialetos/egua-classico/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts +9 -0
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js +24 -0
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/funcao.d.ts +2 -1
- package/construtos/funcao.d.ts.map +1 -1
- package/construtos/funcao.js +2 -1
- package/construtos/funcao.js.map +1 -1
- package/construtos/isto.d.ts +4 -4
- package/construtos/isto.d.ts.map +1 -1
- package/construtos/isto.js +2 -2
- package/construtos/isto.js.map +1 -1
- package/declaracoes/classe.d.ts +1 -0
- package/declaracoes/classe.d.ts.map +1 -1
- package/declaracoes/classe.js.map +1 -1
- package/declaracoes/comentario.d.ts +1 -1
- package/declaracoes/comentario.d.ts.map +1 -1
- package/declaracoes/comentario.js +1 -1
- package/declaracoes/comentario.js.map +1 -1
- package/declaracoes/escreva.d.ts +2 -1
- package/declaracoes/escreva.d.ts.map +1 -1
- package/declaracoes/escreva.js.map +1 -1
- package/declaracoes/index.d.ts +1 -0
- package/declaracoes/index.d.ts.map +1 -1
- package/declaracoes/index.js +1 -0
- package/declaracoes/index.js.map +1 -1
- package/declaracoes/texto-documentacao.d.ts +12 -0
- package/declaracoes/texto-documentacao.d.ts.map +1 -0
- package/declaracoes/texto-documentacao.js +21 -0
- package/declaracoes/texto-documentacao.js.map +1 -0
- package/formatadores/formatador-delegua.d.ts +4 -2
- package/formatadores/formatador-delegua.d.ts.map +1 -1
- package/formatadores/formatador-delegua.js +55 -43
- package/formatadores/formatador-delegua.js.map +1 -1
- package/formatadores/formatador-pitugues.d.ts +70 -60
- package/formatadores/formatador-pitugues.d.ts.map +1 -1
- package/formatadores/formatador-pitugues.js +390 -227
- package/formatadores/formatador-pitugues.js.map +1 -1
- package/interfaces/visitante-comum-interface.d.ts +2 -1
- package/interfaces/visitante-comum-interface.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.d.ts +2 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js +4 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts +2 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js +7 -4
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js.map +1 -1
- package/interpretador/dialetos/pitugues/comum.js +11 -11
- package/interpretador/dialetos/pitugues/comum.js.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.d.ts +2 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.d.ts.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js +3 -0
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js.map +1 -1
- package/interpretador/estruturas/delegua-funcao.d.ts.map +1 -1
- package/interpretador/estruturas/delegua-funcao.js.map +1 -1
- package/interpretador/estruturas/metodo-primitiva.d.ts +3 -1
- package/interpretador/estruturas/metodo-primitiva.d.ts.map +1 -1
- package/interpretador/estruturas/metodo-primitiva.js +5 -2
- package/interpretador/estruturas/metodo-primitiva.js.map +1 -1
- package/interpretador/interpretador-base.d.ts +5 -4
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +50 -16
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +14 -11
- package/interpretador/interpretador.js.map +1 -1
- package/lexador/dialetos/index.d.ts +1 -0
- package/lexador/dialetos/index.d.ts.map +1 -1
- package/lexador/dialetos/index.js +1 -0
- package/lexador/dialetos/index.js.map +1 -1
- package/lexador/dialetos/lexador-prisma.d.ts +46 -0
- package/lexador/dialetos/lexador-prisma.d.ts.map +1 -0
- package/lexador/dialetos/lexador-prisma.js +357 -0
- package/lexador/dialetos/lexador-prisma.js.map +1 -0
- package/lexador/dialetos/palavras-reservadas/prisma.d.ts +40 -0
- package/lexador/dialetos/palavras-reservadas/prisma.d.ts.map +1 -0
- package/lexador/dialetos/palavras-reservadas/prisma.js +47 -0
- package/lexador/dialetos/palavras-reservadas/prisma.js.map +1 -0
- package/package.json +1 -1
- package/tipos-de-dados/dialetos/prisma.d.ts +28 -0
- package/tipos-de-dados/dialetos/prisma.d.ts.map +1 -0
- package/tipos-de-dados/dialetos/prisma.js +29 -0
- package/tipos-de-dados/dialetos/prisma.js.map +1 -0
- package/tipos-de-simbolos/prisma.d.ts +78 -0
- package/tipos-de-simbolos/prisma.d.ts.map +1 -0
- package/tipos-de-simbolos/prisma.js +79 -0
- package/tipos-de-simbolos/prisma.js.map +1 -0
- package/umd/delegua.js +2333 -803
|
@@ -0,0 +1,714 @@
|
|
|
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.AvaliadorSintaticoPrisma = 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 avaliador_sintatico_base_1 = require("../avaliador-sintatico-base");
|
|
11
|
+
const erro_avaliador_sintatico_1 = require("../erro-avaliador-sintatico");
|
|
12
|
+
const inferenciador_1 = require("../../inferenciador");
|
|
13
|
+
const pilha_escopos_1 = require("../pilha-escopos");
|
|
14
|
+
const informacao_escopo_1 = require("../informacao-escopo");
|
|
15
|
+
const comum_1 = require("../comum");
|
|
16
|
+
const informacao_elemento_sintatico_1 = require("../../informacao-elemento-sintatico");
|
|
17
|
+
const lexador_1 = require("../../lexador");
|
|
18
|
+
const prisma_1 = __importDefault(require("../../tipos-de-simbolos/prisma"));
|
|
19
|
+
const primitivas_dicionario_1 = __importDefault(require("../../bibliotecas/primitivas-dicionario"));
|
|
20
|
+
const primitivas_numero_1 = __importDefault(require("../../bibliotecas/primitivas-numero"));
|
|
21
|
+
const primitivas_texto_1 = __importDefault(require("../../bibliotecas/primitivas-texto"));
|
|
22
|
+
const primitivas_vetor_1 = __importDefault(require("../../bibliotecas/primitivas-vetor"));
|
|
23
|
+
/**
|
|
24
|
+
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
25
|
+
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
26
|
+
* Há dois grupos de estruturas de alto nível: Construtos e Declarações.
|
|
27
|
+
*
|
|
28
|
+
* Este avaliador sintático é específico para o dialeto Prisma da linguagem Delégua.
|
|
29
|
+
*/
|
|
30
|
+
class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSintaticoBase {
|
|
31
|
+
constructor(performance = false) {
|
|
32
|
+
super();
|
|
33
|
+
this.atual = 0;
|
|
34
|
+
this.blocos = 0;
|
|
35
|
+
this.performance = performance;
|
|
36
|
+
this.pilhaEscopos = new pilha_escopos_1.PilhaEscopos();
|
|
37
|
+
this.primitivasConhecidas = {};
|
|
38
|
+
this.tiposDefinidosEmCodigo = {};
|
|
39
|
+
(0, comum_1.registrarPrimitiva)(this.primitivasConhecidas, 'dicionário', primitivas_dicionario_1.default);
|
|
40
|
+
(0, comum_1.registrarPrimitiva)(this.primitivasConhecidas, 'número', primitivas_numero_1.default);
|
|
41
|
+
(0, comum_1.registrarPrimitiva)(this.primitivasConhecidas, 'texto', primitivas_texto_1.default);
|
|
42
|
+
(0, comum_1.registrarPrimitiva)(this.primitivasConhecidas, 'vetor', primitivas_vetor_1.default);
|
|
43
|
+
}
|
|
44
|
+
sincronizar() {
|
|
45
|
+
this.avancarEDevolverAnterior();
|
|
46
|
+
while (!this.estaNoFinal()) {
|
|
47
|
+
switch (this.simboloAtual().tipo) {
|
|
48
|
+
case prisma_1.default.CLASSE:
|
|
49
|
+
case prisma_1.default.FUNCAO:
|
|
50
|
+
case prisma_1.default.FUNÇÃO:
|
|
51
|
+
case prisma_1.default.LOCAL:
|
|
52
|
+
case prisma_1.default.PARA:
|
|
53
|
+
case prisma_1.default.SE:
|
|
54
|
+
case prisma_1.default.ENQUANTO:
|
|
55
|
+
case prisma_1.default.IMPRIMA:
|
|
56
|
+
case prisma_1.default.RETORNE:
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.avancarEDevolverAnterior();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
erro(simbolo, mensagemDeErro) {
|
|
63
|
+
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simbolo, mensagemDeErro);
|
|
64
|
+
this.erros.push(excecao);
|
|
65
|
+
return excecao;
|
|
66
|
+
}
|
|
67
|
+
consumir(tipo, mensagemDeErro) {
|
|
68
|
+
if (this.verificarTipoSimboloAtual(tipo))
|
|
69
|
+
return this.avancarEDevolverAnterior();
|
|
70
|
+
let simboloErro = this.simbolos[this.atual];
|
|
71
|
+
if (this.simbolos.length === 0) {
|
|
72
|
+
simboloErro = {
|
|
73
|
+
hashArquivo: this.hashArquivo,
|
|
74
|
+
linha: 1,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
else if (this.atual >= this.simbolos.length) {
|
|
78
|
+
simboloErro = this.simbolos[this.simbolos.length - 1];
|
|
79
|
+
}
|
|
80
|
+
throw this.erro(simboloErro, mensagemDeErro);
|
|
81
|
+
}
|
|
82
|
+
verificarTipoSimboloAtual(tipo) {
|
|
83
|
+
if (this.estaNoFinal())
|
|
84
|
+
return false;
|
|
85
|
+
return this.simboloAtual().tipo === tipo;
|
|
86
|
+
}
|
|
87
|
+
verificarTipoProximoSimbolo(tipo) {
|
|
88
|
+
if (this.estaNoFinal())
|
|
89
|
+
return false;
|
|
90
|
+
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
91
|
+
}
|
|
92
|
+
simboloAtual() {
|
|
93
|
+
return this.simbolos[this.atual];
|
|
94
|
+
}
|
|
95
|
+
simboloAnterior() {
|
|
96
|
+
return this.simbolos[this.atual - 1];
|
|
97
|
+
}
|
|
98
|
+
simboloNaPosicao(posicao) {
|
|
99
|
+
return this.simbolos[this.atual + posicao];
|
|
100
|
+
}
|
|
101
|
+
estaNoFinal() {
|
|
102
|
+
return this.atual >= this.simbolos.length;
|
|
103
|
+
}
|
|
104
|
+
avancarEDevolverAnterior() {
|
|
105
|
+
if (!this.estaNoFinal())
|
|
106
|
+
this.atual += 1;
|
|
107
|
+
return this.simboloAnterior();
|
|
108
|
+
}
|
|
109
|
+
verificarSeSimboloAtualEIgualA(...argumentos) {
|
|
110
|
+
for (let i = 0; i < argumentos.length; i++) {
|
|
111
|
+
const tipoAtual = argumentos[i];
|
|
112
|
+
if (this.verificarTipoSimboloAtual(tipoAtual)) {
|
|
113
|
+
this.avancarEDevolverAnterior();
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
primario() {
|
|
120
|
+
const simboloAtual = this.simbolos[this.atual];
|
|
121
|
+
let valores = [];
|
|
122
|
+
switch (simboloAtual.tipo) {
|
|
123
|
+
case prisma_1.default.COLCHETE_ESQUERDO:
|
|
124
|
+
this.avancarEDevolverAnterior();
|
|
125
|
+
switch (this.simboloAtual().tipo) {
|
|
126
|
+
case prisma_1.default.COLCHETE_ESQUERDO: // Texto multilinhas
|
|
127
|
+
return this.construtoTextoMultilinhas();
|
|
128
|
+
default:
|
|
129
|
+
throw this.erro(simboloAtual, 'Terminar.');
|
|
130
|
+
}
|
|
131
|
+
case prisma_1.default.CHAVE_ESQUERDA:
|
|
132
|
+
// Prisma tem o conceito de tabela, que não é exatamente um dicionário, mas é próximo.
|
|
133
|
+
// Aqui, vamos tratar como dicionário para simplificar.
|
|
134
|
+
this.avancarEDevolverAnterior();
|
|
135
|
+
const chaves = [];
|
|
136
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.CHAVE_DIREITA)) {
|
|
137
|
+
return new construtos_1.Dicionario(this.hashArquivo, simboloAtual.linha, [], []);
|
|
138
|
+
}
|
|
139
|
+
let indice = 1;
|
|
140
|
+
do {
|
|
141
|
+
let chave = String(indice);
|
|
142
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.COLCHETE_ESQUERDO)) {
|
|
143
|
+
// Lógica para índice nomeado
|
|
144
|
+
// TODO: Terminar
|
|
145
|
+
}
|
|
146
|
+
const valor = this.ou();
|
|
147
|
+
chaves.push(chave);
|
|
148
|
+
valores.push(valor);
|
|
149
|
+
indice++;
|
|
150
|
+
} while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.VIRGULA));
|
|
151
|
+
this.consumir(prisma_1.default.CHAVE_DIREITA, `Esperado fechamento de chave em tabela.`);
|
|
152
|
+
return new construtos_1.Dicionario(this.hashArquivo, simboloAtual.linha, chaves, valores);
|
|
153
|
+
case prisma_1.default.FALSO:
|
|
154
|
+
case prisma_1.default.VERDADEIRO:
|
|
155
|
+
const simboloLogico = this.avancarEDevolverAnterior();
|
|
156
|
+
return new construtos_1.Literal(this.hashArquivo, simboloAtual.linha, simboloLogico.tipo === prisma_1.default.VERDADEIRO, 'lógico');
|
|
157
|
+
case prisma_1.default.FUNCAO:
|
|
158
|
+
case prisma_1.default.FUNÇÃO:
|
|
159
|
+
const simboloFuncao = this.avancarEDevolverAnterior();
|
|
160
|
+
const corpoDaFuncao = this.corpoDaFuncao(simboloFuncao.lexema);
|
|
161
|
+
this.pilhaEscopos.definirInformacoesVariavel(simboloFuncao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(simboloFuncao.lexema, 'função'));
|
|
162
|
+
return corpoDaFuncao;
|
|
163
|
+
case prisma_1.default.IMPORTAR:
|
|
164
|
+
return this.expressaoImportar();
|
|
165
|
+
case prisma_1.default.NULO:
|
|
166
|
+
this.avancarEDevolverAnterior();
|
|
167
|
+
return new construtos_1.Literal(this.hashArquivo, simboloAtual.linha, null);
|
|
168
|
+
case prisma_1.default.ISTO:
|
|
169
|
+
const simboloIsto = this.avancarEDevolverAnterior();
|
|
170
|
+
return new construtos_1.Isto(this.hashArquivo, simboloAtual.linha, simboloIsto);
|
|
171
|
+
case prisma_1.default.LEIA:
|
|
172
|
+
return this.expressaoLeia();
|
|
173
|
+
case prisma_1.default.NUMERO:
|
|
174
|
+
case prisma_1.default.TEXTO:
|
|
175
|
+
const simboloLiteral = this.avancarEDevolverAnterior();
|
|
176
|
+
const tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(simboloLiteral.literal);
|
|
177
|
+
const tipoDadosElementar = (0, inferenciador_1.tipoInferenciaParaTipoDadosElementar)(tipoInferido);
|
|
178
|
+
return new construtos_1.Literal(this.hashArquivo, Number(simboloLiteral.linha), simboloLiteral.literal, tipoDadosElementar);
|
|
179
|
+
case prisma_1.default.IDENTIFICADOR:
|
|
180
|
+
const simboloIdentificador = this.avancarEDevolverAnterior();
|
|
181
|
+
let tipoOperando;
|
|
182
|
+
if (simboloIdentificador.lexema in this.tiposDefinidosEmCodigo) {
|
|
183
|
+
tipoOperando = simboloIdentificador.lexema;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
try {
|
|
187
|
+
tipoOperando = this.pilhaEscopos.obterTipoVariavelPorNome(simboloIdentificador.lexema);
|
|
188
|
+
}
|
|
189
|
+
catch (erro) {
|
|
190
|
+
throw this.erro(simboloIdentificador, erro.message);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return new construtos_1.Variavel(this.hashArquivo, simboloIdentificador, tipoOperando);
|
|
194
|
+
case prisma_1.default.PARENTESE_ESQUERDO:
|
|
195
|
+
this.avancarEDevolverAnterior();
|
|
196
|
+
const expressao = this.expressao();
|
|
197
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
198
|
+
return new construtos_1.Agrupamento(this.hashArquivo, simboloAtual.linha, expressao);
|
|
199
|
+
case prisma_1.default.SUPER:
|
|
200
|
+
const simboloSuper = this.avancarEDevolverAnterior();
|
|
201
|
+
return new construtos_1.Super(this.hashArquivo, simboloSuper, this.superclasseAtual);
|
|
202
|
+
}
|
|
203
|
+
throw this.erro(this.simboloAtual(), 'Esperado expressão.');
|
|
204
|
+
}
|
|
205
|
+
expressaoImportar() {
|
|
206
|
+
throw new Error('Método não implementado.');
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Construto para texto multilinhas.
|
|
210
|
+
* @returns
|
|
211
|
+
*/
|
|
212
|
+
construtoTextoMultilinhas() {
|
|
213
|
+
const segundoColchete = this.consumir(prisma_1.default.COLCHETE_ESQUERDO, "Esperado '[' antes do texto multilinhas.");
|
|
214
|
+
let texto = "";
|
|
215
|
+
let linha = segundoColchete.linha;
|
|
216
|
+
while (!this.verificarSeSimboloAtualEIgualA(prisma_1.default.COLCHETE_DIREITO)) {
|
|
217
|
+
texto += this.simbolos[this.atual].lexema + " ";
|
|
218
|
+
if (this.simbolos[this.atual].linha !== linha) {
|
|
219
|
+
texto += "\n";
|
|
220
|
+
linha = this.simbolos[this.atual].linha;
|
|
221
|
+
}
|
|
222
|
+
this.avancarEDevolverAnterior();
|
|
223
|
+
}
|
|
224
|
+
this.consumir(prisma_1.default.COLCHETE_DIREITO, "Esperado ']' após o texto multilinhas.");
|
|
225
|
+
return new construtos_1.Literal(this.hashArquivo, segundoColchete.linha, texto);
|
|
226
|
+
}
|
|
227
|
+
expressaoLeia() {
|
|
228
|
+
const simboloLeia = this.avancarEDevolverAnterior();
|
|
229
|
+
this.consumir(prisma_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em leia.");
|
|
230
|
+
const argumentos = [];
|
|
231
|
+
if (!this.verificarTipoSimboloAtual(prisma_1.default.PARENTESE_DIREITO)) {
|
|
232
|
+
do {
|
|
233
|
+
argumentos.push(this.expressao());
|
|
234
|
+
} while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.VIRGULA));
|
|
235
|
+
}
|
|
236
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em leia.");
|
|
237
|
+
return new construtos_1.Leia(simboloLeia, argumentos);
|
|
238
|
+
}
|
|
239
|
+
finalizarChamada(entidadeChamada) {
|
|
240
|
+
const argumentos = [];
|
|
241
|
+
if (!this.verificarTipoSimboloAtual(prisma_1.default.PARENTESE_DIREITO)) {
|
|
242
|
+
do {
|
|
243
|
+
if (argumentos.length >= 255) {
|
|
244
|
+
throw this.erro(this.simboloAtual(), 'Não pode haver mais de 255 argumentos.');
|
|
245
|
+
}
|
|
246
|
+
argumentos.push(this.expressao());
|
|
247
|
+
} while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.VIRGULA));
|
|
248
|
+
}
|
|
249
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos.");
|
|
250
|
+
return new construtos_1.Chamada(this.hashArquivo, entidadeChamada, argumentos);
|
|
251
|
+
}
|
|
252
|
+
chamar() {
|
|
253
|
+
let expressao = this.primario();
|
|
254
|
+
while (true) {
|
|
255
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.PARENTESE_ESQUERDO)) {
|
|
256
|
+
expressao = this.finalizarChamada(expressao);
|
|
257
|
+
}
|
|
258
|
+
else if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.PONTO)) {
|
|
259
|
+
const nome = this.consumir(prisma_1.default.IDENTIFICADOR, "Esperado nome do método após '.'.");
|
|
260
|
+
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
261
|
+
}
|
|
262
|
+
else if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.COLCHETE_ESQUERDO)) {
|
|
263
|
+
const indice = this.expressao();
|
|
264
|
+
const simboloFechamento = this.consumir(prisma_1.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
265
|
+
expressao = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, expressao, indice, simboloFechamento);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return expressao;
|
|
272
|
+
}
|
|
273
|
+
unario() {
|
|
274
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.NEGACAO, prisma_1.default.SUBTRACAO, prisma_1.default.BIT_NOT)) {
|
|
275
|
+
const operador = this.simboloAnterior();
|
|
276
|
+
const direito = this.unario();
|
|
277
|
+
return new construtos_1.Unario(this.hashArquivo, operador, direito);
|
|
278
|
+
}
|
|
279
|
+
return this.chamar();
|
|
280
|
+
}
|
|
281
|
+
exponenciacao() {
|
|
282
|
+
let expressao = this.unario();
|
|
283
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.EXPONENCIACAO)) {
|
|
284
|
+
const operador = this.simboloAnterior();
|
|
285
|
+
const direito = this.unario();
|
|
286
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
287
|
+
}
|
|
288
|
+
return expressao;
|
|
289
|
+
}
|
|
290
|
+
multiplicar() {
|
|
291
|
+
let expressao = this.exponenciacao();
|
|
292
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.DIVISAO, prisma_1.default.DIVISAO_INTEIRA, prisma_1.default.MULTIPLICACAO, prisma_1.default.MODULO)) {
|
|
293
|
+
const operador = this.simboloAnterior();
|
|
294
|
+
const direito = this.exponenciacao();
|
|
295
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
296
|
+
}
|
|
297
|
+
return expressao;
|
|
298
|
+
}
|
|
299
|
+
adicaoOuSubtracao() {
|
|
300
|
+
let expressao = this.multiplicar();
|
|
301
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.SUBTRACAO, prisma_1.default.ADICAO)) {
|
|
302
|
+
const operador = this.simboloAnterior();
|
|
303
|
+
const direito = this.multiplicar();
|
|
304
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
305
|
+
}
|
|
306
|
+
return expressao;
|
|
307
|
+
}
|
|
308
|
+
bitShift() {
|
|
309
|
+
let expressao = this.adicaoOuSubtracao();
|
|
310
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.MENOR_MENOR, prisma_1.default.MAIOR_MAIOR)) {
|
|
311
|
+
const operador = this.simboloAnterior();
|
|
312
|
+
const direito = this.adicaoOuSubtracao();
|
|
313
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
314
|
+
}
|
|
315
|
+
return expressao;
|
|
316
|
+
}
|
|
317
|
+
bitE() {
|
|
318
|
+
let expressao = this.bitShift();
|
|
319
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.BIT_AND)) {
|
|
320
|
+
const operador = this.simboloAnterior();
|
|
321
|
+
const direito = this.bitShift();
|
|
322
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
323
|
+
}
|
|
324
|
+
return expressao;
|
|
325
|
+
}
|
|
326
|
+
bitOu() {
|
|
327
|
+
let expressao = this.bitE();
|
|
328
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.BIT_OR, prisma_1.default.BIT_XOR)) {
|
|
329
|
+
const operador = this.simboloAnterior();
|
|
330
|
+
const direito = this.bitE();
|
|
331
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
332
|
+
}
|
|
333
|
+
return expressao;
|
|
334
|
+
}
|
|
335
|
+
comparar() {
|
|
336
|
+
let expressao = this.bitOu();
|
|
337
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.MAIOR, prisma_1.default.MAIOR_IGUAL, prisma_1.default.MENOR, prisma_1.default.MENOR_IGUAL)) {
|
|
338
|
+
const operador = this.simboloAnterior();
|
|
339
|
+
const direito = this.bitOu();
|
|
340
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
341
|
+
}
|
|
342
|
+
return expressao;
|
|
343
|
+
}
|
|
344
|
+
comparacaoIgualdade() {
|
|
345
|
+
let expressao = this.comparar();
|
|
346
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.DIFERENTE, prisma_1.default.IGUAL_IGUAL)) {
|
|
347
|
+
const operador = this.simboloAnterior();
|
|
348
|
+
const direito = this.comparar();
|
|
349
|
+
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
350
|
+
}
|
|
351
|
+
return expressao;
|
|
352
|
+
}
|
|
353
|
+
em() {
|
|
354
|
+
let expressao = this.comparacaoIgualdade();
|
|
355
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.EM)) {
|
|
356
|
+
const operador = this.simboloAnterior();
|
|
357
|
+
const direito = this.comparacaoIgualdade();
|
|
358
|
+
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
359
|
+
}
|
|
360
|
+
return expressao;
|
|
361
|
+
}
|
|
362
|
+
e() {
|
|
363
|
+
let expressao = this.em();
|
|
364
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.E)) {
|
|
365
|
+
const operador = this.simboloAnterior();
|
|
366
|
+
const direito = this.em();
|
|
367
|
+
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
368
|
+
}
|
|
369
|
+
return expressao;
|
|
370
|
+
}
|
|
371
|
+
ou() {
|
|
372
|
+
let expressao = this.e();
|
|
373
|
+
while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.OU)) {
|
|
374
|
+
const operador = this.simboloAnterior();
|
|
375
|
+
const direito = this.e();
|
|
376
|
+
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
377
|
+
}
|
|
378
|
+
return expressao;
|
|
379
|
+
}
|
|
380
|
+
atribuir() {
|
|
381
|
+
const expressao = this.ou();
|
|
382
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.IGUAL) ||
|
|
383
|
+
this.verificarSeSimboloAtualEIgualA(prisma_1.default.MAIS_IGUAL)) {
|
|
384
|
+
const igual = this.simboloAnterior();
|
|
385
|
+
const valor = this.atribuir();
|
|
386
|
+
if (expressao instanceof construtos_1.Variavel) {
|
|
387
|
+
return new construtos_1.Atribuir(this.hashArquivo, expressao, valor);
|
|
388
|
+
}
|
|
389
|
+
if (expressao instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
390
|
+
return new construtos_1.DefinirValor(this.hashArquivo, 0, expressao.objeto, expressao.simbolo, valor);
|
|
391
|
+
}
|
|
392
|
+
if (expressao instanceof construtos_1.AcessoIndiceVariavel) {
|
|
393
|
+
return new construtos_1.AtribuicaoPorIndice(this.hashArquivo, 0, expressao.entidadeChamada, expressao.indice, valor);
|
|
394
|
+
}
|
|
395
|
+
throw this.erro(igual, 'Tarefa de atribuição inválida');
|
|
396
|
+
}
|
|
397
|
+
return expressao;
|
|
398
|
+
}
|
|
399
|
+
expressao() {
|
|
400
|
+
return this.atribuir();
|
|
401
|
+
}
|
|
402
|
+
declaracaoEscreva() {
|
|
403
|
+
const simboloEscreva = this.simboloAnterior();
|
|
404
|
+
this.consumir(prisma_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em imprima.");
|
|
405
|
+
const argumentos = [];
|
|
406
|
+
if (!this.verificarTipoSimboloAtual(prisma_1.default.PARENTESE_DIREITO)) {
|
|
407
|
+
do {
|
|
408
|
+
argumentos.push(this.expressao());
|
|
409
|
+
} while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.VIRGULA));
|
|
410
|
+
}
|
|
411
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em imprima.");
|
|
412
|
+
this.verificarSeSimboloAtualEIgualA(prisma_1.default.PONTO_E_VIRGULA);
|
|
413
|
+
return new declaracoes_1.Escreva(Number(simboloEscreva.linha), simboloEscreva.hashArquivo, argumentos);
|
|
414
|
+
}
|
|
415
|
+
declaracaoExpressao() {
|
|
416
|
+
const expressao = this.expressao();
|
|
417
|
+
return new declaracoes_1.Expressao(expressao);
|
|
418
|
+
}
|
|
419
|
+
blocoEscopo() {
|
|
420
|
+
this.pilhaEscopos.empilhar(new informacao_escopo_1.InformacaoEscopo());
|
|
421
|
+
let declaracoes = [];
|
|
422
|
+
while (!this.verificarTipoSimboloAtual(prisma_1.default.FIM) && !this.estaNoFinal()) {
|
|
423
|
+
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
424
|
+
if (Array.isArray(retornoDeclaracao)) {
|
|
425
|
+
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
declaracoes.push(retornoDeclaracao);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
this.consumir(prisma_1.default.FIM, "Esperado 'fim' após o bloco.");
|
|
432
|
+
this.pilhaEscopos.removerUltimo();
|
|
433
|
+
return declaracoes;
|
|
434
|
+
}
|
|
435
|
+
declaracaoDeLocal() {
|
|
436
|
+
const identificador = this.consumir(prisma_1.default.IDENTIFICADOR, 'Esperado nome de variável.');
|
|
437
|
+
let inicializador = null;
|
|
438
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.IGUAL)) {
|
|
439
|
+
inicializador = this.expressao();
|
|
440
|
+
}
|
|
441
|
+
this.consumir(prisma_1.default.PONTO_E_VIRGULA, "Esperado ';' após declaração de variável.");
|
|
442
|
+
// Para Prisma, mantemos a tipagem inferida de forma simples por enquanto.
|
|
443
|
+
const tipo = 'qualquer';
|
|
444
|
+
this.pilhaEscopos.definirInformacoesVariavel(identificador.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(identificador.lexema, tipo));
|
|
445
|
+
return new declaracoes_1.Var(identificador, inicializador, tipo);
|
|
446
|
+
}
|
|
447
|
+
declaracaoEnquanto() {
|
|
448
|
+
try {
|
|
449
|
+
this.blocos += 1;
|
|
450
|
+
const condicao = this.expressao();
|
|
451
|
+
const bloco = this.resolverDeclaracao();
|
|
452
|
+
return new declaracoes_1.Enquanto(condicao, bloco);
|
|
453
|
+
}
|
|
454
|
+
finally {
|
|
455
|
+
this.blocos -= 1;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
declaracaoSe() {
|
|
459
|
+
const simboloSe = this.simbolos[this.atual];
|
|
460
|
+
const condicao = this.expressao();
|
|
461
|
+
this.consumir(prisma_1.default.ENTAO, "Esperado palavra reservada 'entao' ou 'então' após condição em declaração 'se'.");
|
|
462
|
+
const declaracoes = [];
|
|
463
|
+
do {
|
|
464
|
+
declaracoes.push(this.resolverDeclaracaoForaDeBloco());
|
|
465
|
+
} while (!this.estaNoFinal() &&
|
|
466
|
+
![prisma_1.default.SENAO, prisma_1.default.SENÃO, prisma_1.default.FIM].includes(this.simbolos[this.atual].tipo));
|
|
467
|
+
let caminhoSenao = null;
|
|
468
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.SENAO, prisma_1.default.SENÃO)) {
|
|
469
|
+
const simboloSenao = this.simbolos[this.atual - 1];
|
|
470
|
+
const declaracoesSenao = [];
|
|
471
|
+
do {
|
|
472
|
+
declaracoesSenao.push(this.resolverDeclaracaoForaDeBloco());
|
|
473
|
+
} while (![prisma_1.default.FIM].includes(this.simbolos[this.atual].tipo));
|
|
474
|
+
caminhoSenao = new declaracoes_1.Bloco(this.hashArquivo, Number(simboloSenao.linha), declaracoesSenao.filter((d) => d));
|
|
475
|
+
}
|
|
476
|
+
this.consumir(prisma_1.default.FIM, "Esperado palavra-chave 'fimse' para fechamento de declaração 'se'.");
|
|
477
|
+
return new declaracoes_1.Se(condicao, new declaracoes_1.Bloco(this.hashArquivo, Number(simboloSe.linha), declaracoes.filter((d) => d)), [], caminhoSenao);
|
|
478
|
+
}
|
|
479
|
+
declaracaoQuebre() {
|
|
480
|
+
if (this.blocos < 1) {
|
|
481
|
+
throw this.erro(this.simboloAnterior(), "'quebre' deve estar dentro de um laço de repetição.");
|
|
482
|
+
}
|
|
483
|
+
this.consumir(prisma_1.default.PONTO_E_VIRGULA, "Esperado ';' após 'quebre'.");
|
|
484
|
+
return new declaracoes_1.Sustar(this.simboloAtual());
|
|
485
|
+
}
|
|
486
|
+
declaracaoContinua() {
|
|
487
|
+
if (this.blocos < 1) {
|
|
488
|
+
throw this.erro(this.simboloAnterior(), "'continua' precisa estar em um laço de repetição.");
|
|
489
|
+
}
|
|
490
|
+
this.consumir(prisma_1.default.PONTO_E_VIRGULA, "Esperado ';' após 'continua'.");
|
|
491
|
+
return new declaracoes_1.Continua(this.simboloAtual());
|
|
492
|
+
}
|
|
493
|
+
declaracaoRetorna() {
|
|
494
|
+
const palavraChave = this.simboloAnterior();
|
|
495
|
+
let valor = null;
|
|
496
|
+
if (!this.verificarTipoSimboloAtual(prisma_1.default.PONTO_E_VIRGULA)) {
|
|
497
|
+
valor = this.expressao();
|
|
498
|
+
}
|
|
499
|
+
this.consumir(prisma_1.default.PONTO_E_VIRGULA, "Esperado ';' após valor de retorno.");
|
|
500
|
+
return new declaracoes_1.Retorna(palavraChave, valor);
|
|
501
|
+
}
|
|
502
|
+
declaracaoImportar() {
|
|
503
|
+
this.avancarEDevolverAnterior();
|
|
504
|
+
this.consumir(prisma_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
|
|
505
|
+
const caminho = this.expressao();
|
|
506
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
507
|
+
return new declaracoes_1.Importar(caminho);
|
|
508
|
+
}
|
|
509
|
+
corpoDaFuncao(tipo) {
|
|
510
|
+
const parenteseEsquerdo = this.consumir(prisma_1.default.PARENTESE_ESQUERDO, `Esperado '(' após o nome ${tipo}.`);
|
|
511
|
+
let parametros = [];
|
|
512
|
+
if (!this.verificarTipoSimboloAtual(prisma_1.default.PARENTESE_DIREITO)) {
|
|
513
|
+
parametros = this.logicaComumParametros();
|
|
514
|
+
}
|
|
515
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
516
|
+
let tipoRetorno = 'qualquer';
|
|
517
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.SETA)) {
|
|
518
|
+
tipoRetorno = 'qualquer'; // Simplificado por enquanto
|
|
519
|
+
}
|
|
520
|
+
const corpo = this.blocoEscopo();
|
|
521
|
+
return new construtos_1.FuncaoConstruto(this.hashArquivo, 0, parametros, corpo, tipoRetorno, false);
|
|
522
|
+
}
|
|
523
|
+
logicaComumParametros() {
|
|
524
|
+
const parametros = [];
|
|
525
|
+
do {
|
|
526
|
+
if (parametros.length >= 255) {
|
|
527
|
+
throw this.erro(this.simboloAtual(), 'Função não pode ter mais de 255 parâmetros.');
|
|
528
|
+
}
|
|
529
|
+
const parametro = {};
|
|
530
|
+
parametro.abrangencia = 'padrao';
|
|
531
|
+
parametro.nome = this.consumir(prisma_1.default.IDENTIFICADOR, 'Esperado nome do parâmetro.');
|
|
532
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.IGUAL)) {
|
|
533
|
+
parametro.valorPadrao = this.primario();
|
|
534
|
+
}
|
|
535
|
+
this.pilhaEscopos.definirInformacoesVariavel(parametro.nome.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(parametro.nome.lexema, parametro.tipoDado || 'qualquer'));
|
|
536
|
+
parametros.push(parametro);
|
|
537
|
+
} while (this.verificarSeSimboloAtualEIgualA(prisma_1.default.VIRGULA));
|
|
538
|
+
return parametros;
|
|
539
|
+
}
|
|
540
|
+
funcao(tipo) {
|
|
541
|
+
const simbolo = this.consumir(prisma_1.default.IDENTIFICADOR, `Esperado nome ${tipo}.`);
|
|
542
|
+
this.pilhaEscopos.definirInformacoesVariavel(simbolo.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(simbolo.lexema, 'qualquer'));
|
|
543
|
+
const corpoDaFuncao = this.corpoDaFuncao(tipo);
|
|
544
|
+
const tipoDaFuncao = `função<${corpoDaFuncao.tipo}>`;
|
|
545
|
+
this.pilhaEscopos.definirInformacoesVariavel(simbolo.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(simbolo.lexema, tipoDaFuncao));
|
|
546
|
+
const funcaoDeclaracao = new declaracoes_1.FuncaoDeclaracao(simbolo, corpoDaFuncao, tipoDaFuncao);
|
|
547
|
+
this.pilhaEscopos.registrarReferenciaFuncao(simbolo.lexema, funcaoDeclaracao);
|
|
548
|
+
return funcaoDeclaracao;
|
|
549
|
+
}
|
|
550
|
+
resolverDeclaracao() {
|
|
551
|
+
switch (this.simbolos[this.atual].tipo) {
|
|
552
|
+
case prisma_1.default.CONTINUA:
|
|
553
|
+
this.avancarEDevolverAnterior();
|
|
554
|
+
return this.declaracaoContinua();
|
|
555
|
+
case prisma_1.default.PONTO_E_VIRGULA:
|
|
556
|
+
// Ignora ponto e vírgula supérfluo
|
|
557
|
+
this.avancarEDevolverAnterior();
|
|
558
|
+
return null;
|
|
559
|
+
case prisma_1.default.ENTAO:
|
|
560
|
+
case prisma_1.default.INICIO:
|
|
561
|
+
const simboloInicioBloco = this.avancarEDevolverAnterior();
|
|
562
|
+
return new declaracoes_1.Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
563
|
+
case prisma_1.default.ENQUANTO:
|
|
564
|
+
this.avancarEDevolverAnterior();
|
|
565
|
+
return this.declaracaoEnquanto();
|
|
566
|
+
case prisma_1.default.IMPRIMA:
|
|
567
|
+
this.avancarEDevolverAnterior();
|
|
568
|
+
return this.declaracaoEscreva();
|
|
569
|
+
case prisma_1.default.PARA:
|
|
570
|
+
return this.declaracaoPara();
|
|
571
|
+
case prisma_1.default.QUEBRE:
|
|
572
|
+
this.avancarEDevolverAnterior();
|
|
573
|
+
return this.declaracaoQuebre();
|
|
574
|
+
case prisma_1.default.SE:
|
|
575
|
+
this.avancarEDevolverAnterior();
|
|
576
|
+
return this.declaracaoSe();
|
|
577
|
+
case prisma_1.default.RETORNE:
|
|
578
|
+
this.avancarEDevolverAnterior();
|
|
579
|
+
return this.declaracaoRetorna();
|
|
580
|
+
case prisma_1.default.LOCAL:
|
|
581
|
+
this.avancarEDevolverAnterior();
|
|
582
|
+
return this.declaracaoDeLocal();
|
|
583
|
+
}
|
|
584
|
+
return this.declaracaoExpressao();
|
|
585
|
+
}
|
|
586
|
+
declaracaoPara() {
|
|
587
|
+
try {
|
|
588
|
+
this.blocos += 1;
|
|
589
|
+
const simboloPara = this.avancarEDevolverAnterior();
|
|
590
|
+
const variavelIteracao = this.consumir(prisma_1.default.IDENTIFICADOR, "Esperado identificador de variável após 'para'.");
|
|
591
|
+
this.consumir(prisma_1.default.IGUAL, `'=' or 'em' esperado próximo a '${this.simbolos[this.atual].lexema}'.`);
|
|
592
|
+
const literalOuVariavelInicio = this.adicaoOuSubtracao();
|
|
593
|
+
this.consumir(prisma_1.default.VIRGULA, `Espera-se '=' próximo a '${this.simbolos[this.atual].lexema}'.`);
|
|
594
|
+
const literalOuVariavelFim = this.adicaoOuSubtracao();
|
|
595
|
+
let operadorCondicao = new lexador_1.Simbolo(prisma_1.default.MENOR_IGUAL, '<=', null, Number(simboloPara.linha), this.hashArquivo);
|
|
596
|
+
let operadorCondicaoIncremento = new lexador_1.Simbolo(prisma_1.default.MENOR, '<', null, Number(simboloPara.linha), this.hashArquivo);
|
|
597
|
+
let passo = new construtos_1.Literal(this.hashArquivo, Number(simboloPara.linha), 1);
|
|
598
|
+
const resolverIncrementoEmExecucao = false; // Mudar caso seja necessário.
|
|
599
|
+
this.consumir(prisma_1.default.INICIO, `espera-se 'inicio' proximo a '${this.simbolos[this.atual].lexema}'.`);
|
|
600
|
+
// Aqui já é seguro inicializar a variável.
|
|
601
|
+
this.pilhaEscopos.definirInformacoesVariavel(variavelIteracao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(variavelIteracao.lexema, 'inteiro'));
|
|
602
|
+
const declaracoesBlocoPara = [];
|
|
603
|
+
let simboloAtualBlocoPara = this.simbolos[this.atual];
|
|
604
|
+
while (simboloAtualBlocoPara.tipo !== prisma_1.default.FIM) {
|
|
605
|
+
declaracoesBlocoPara.push(this.resolverDeclaracaoForaDeBloco());
|
|
606
|
+
simboloAtualBlocoPara = this.simbolos[this.atual];
|
|
607
|
+
}
|
|
608
|
+
this.avancarEDevolverAnterior(); // fim
|
|
609
|
+
const corpo = new declaracoes_1.Bloco(this.hashArquivo, Number(simboloPara.linha) + 1, declaracoesBlocoPara.filter((d) => d));
|
|
610
|
+
const para = new declaracoes_1.Para(this.hashArquivo, Number(simboloPara.linha),
|
|
611
|
+
// Inicialização.
|
|
612
|
+
new declaracoes_1.Expressao(new construtos_1.Atribuir(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), literalOuVariavelInicio)),
|
|
613
|
+
// Condição.
|
|
614
|
+
new construtos_1.Binario(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), operadorCondicao, literalOuVariavelFim),
|
|
615
|
+
// Incremento, feito em construto especial `FimPara`.
|
|
616
|
+
new construtos_1.FimPara(this.hashArquivo, Number(simboloPara.linha), new construtos_1.Binario(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), operadorCondicaoIncremento, literalOuVariavelFim), new declaracoes_1.Expressao(new construtos_1.Atribuir(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), new construtos_1.Binario(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, variavelIteracao, 'inteiro'), new lexador_1.Simbolo(prisma_1.default.ADICAO, '+', null, Number(simboloPara.linha), this.hashArquivo), passo)))), corpo);
|
|
617
|
+
para.blocoPosExecucao = corpo;
|
|
618
|
+
para.resolverIncrementoEmExecucao = resolverIncrementoEmExecucao;
|
|
619
|
+
return para;
|
|
620
|
+
}
|
|
621
|
+
finally {
|
|
622
|
+
this.blocos -= 1;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
resolverDeclaracaoForaDeBloco() {
|
|
626
|
+
try {
|
|
627
|
+
if ((this.verificarTipoSimboloAtual(prisma_1.default.FUNCAO) ||
|
|
628
|
+
this.verificarTipoSimboloAtual(prisma_1.default.FUNÇÃO)) &&
|
|
629
|
+
this.verificarTipoProximoSimbolo(prisma_1.default.IDENTIFICADOR)) {
|
|
630
|
+
this.avancarEDevolverAnterior();
|
|
631
|
+
return this.funcao('funcao');
|
|
632
|
+
}
|
|
633
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.CLASSE))
|
|
634
|
+
return this.declaracaoDeClasse();
|
|
635
|
+
return this.resolverDeclaracao();
|
|
636
|
+
}
|
|
637
|
+
catch (erro) {
|
|
638
|
+
this.sincronizar();
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
declaracaoDeClasse() {
|
|
643
|
+
const simbolo = this.consumir(prisma_1.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
644
|
+
let superClasse = null;
|
|
645
|
+
if (this.verificarSeSimboloAtualEIgualA(prisma_1.default.PARENTESE_ESQUERDO)) {
|
|
646
|
+
const simboloSuperclasse = this.consumir(prisma_1.default.IDENTIFICADOR, 'Esperado nome da Superclasse.');
|
|
647
|
+
this.superclasseAtual = simboloSuperclasse.lexema;
|
|
648
|
+
superClasse = new construtos_1.Variavel(this.hashArquivo, this.simboloAnterior());
|
|
649
|
+
this.consumir(prisma_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
650
|
+
}
|
|
651
|
+
this.consumir(prisma_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo da classe.");
|
|
652
|
+
const metodos = [];
|
|
653
|
+
while (!this.estaNoFinal() &&
|
|
654
|
+
(this.verificarTipoSimboloAtual(prisma_1.default.CONSTRUTOR) ||
|
|
655
|
+
this.verificarTipoSimboloAtual(prisma_1.default.FUNCAO) ||
|
|
656
|
+
this.verificarTipoSimboloAtual(prisma_1.default.FUNÇÃO))) {
|
|
657
|
+
const ehConstrutor = this.verificarSeSimboloAtualEIgualA(prisma_1.default.CONSTRUTOR);
|
|
658
|
+
metodos.push(this.funcao('método'));
|
|
659
|
+
}
|
|
660
|
+
this.consumir(prisma_1.default.CHAVE_DIREITA, "Esperado '}' após métodos da classe.");
|
|
661
|
+
this.superclasseAtual = undefined;
|
|
662
|
+
const definicaoClasse = new declaracoes_1.Classe(simbolo, superClasse, metodos);
|
|
663
|
+
this.tiposDefinidosEmCodigo[definicaoClasse.simbolo.lexema] = definicaoClasse;
|
|
664
|
+
return definicaoClasse;
|
|
665
|
+
}
|
|
666
|
+
inicializarPilhaEscopos() {
|
|
667
|
+
this.pilhaEscopos = new pilha_escopos_1.PilhaEscopos();
|
|
668
|
+
this.pilhaEscopos.empilhar(new informacao_escopo_1.InformacaoEscopo());
|
|
669
|
+
// Funções nativas básicas
|
|
670
|
+
this.pilhaEscopos.definirInformacoesVariavel('aleatorio', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('aleatorio', 'número'));
|
|
671
|
+
this.pilhaEscopos.definirInformacoesVariavel('inteiro', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('inteiro', 'inteiro', true, [
|
|
672
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valor', 'qualquer'),
|
|
673
|
+
]));
|
|
674
|
+
this.pilhaEscopos.definirInformacoesVariavel('numero', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('número', 'número', true, [
|
|
675
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorParaConverter', 'qualquer'),
|
|
676
|
+
]));
|
|
677
|
+
this.pilhaEscopos.definirInformacoesVariavel('texto', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('texto', 'texto', true, [
|
|
678
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorParaConverter', 'qualquer'),
|
|
679
|
+
]));
|
|
680
|
+
this.pilhaEscopos.definirInformacoesVariavel('tamanho', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tamanho', 'inteiro', true, [
|
|
681
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('objeto', 'qualquer'),
|
|
682
|
+
]));
|
|
683
|
+
}
|
|
684
|
+
analisar(retornoLexador, hashArquivo) {
|
|
685
|
+
const inicioAnalise = (0, browser_process_hrtime_1.default)();
|
|
686
|
+
this.erros = [];
|
|
687
|
+
this.atual = 0;
|
|
688
|
+
this.blocos = 0;
|
|
689
|
+
this.inicializarPilhaEscopos();
|
|
690
|
+
this.tiposDefinidosEmCodigo = {};
|
|
691
|
+
this.hashArquivo = hashArquivo || 0;
|
|
692
|
+
this.simbolos = (retornoLexador === null || retornoLexador === void 0 ? void 0 : retornoLexador.simbolos) || [];
|
|
693
|
+
let declaracoes = [];
|
|
694
|
+
while (!this.estaNoFinal()) {
|
|
695
|
+
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
696
|
+
if (Array.isArray(retornoDeclaracao)) {
|
|
697
|
+
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
698
|
+
}
|
|
699
|
+
else if (retornoDeclaracao !== null) {
|
|
700
|
+
declaracoes.push(retornoDeclaracao);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (this.performance) {
|
|
704
|
+
const deltaAnalise = (0, browser_process_hrtime_1.default)(inicioAnalise);
|
|
705
|
+
console.log(`[Avaliador Sintático] Tempo para análise: ${deltaAnalise[0] * 1e9 + deltaAnalise[1]}ns`);
|
|
706
|
+
}
|
|
707
|
+
return {
|
|
708
|
+
declaracoes: declaracoes,
|
|
709
|
+
erros: this.erros,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
exports.AvaliadorSintaticoPrisma = AvaliadorSintaticoPrisma;
|
|
714
|
+
//# sourceMappingURL=avaliador-sintatico-prisma.js.map
|