@designliquido/delegua 0.35.1 → 0.35.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 +3 -0
- package/analisador-semantico/analisador-semantico-base.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico-base.js +10 -0
- package/analisador-semantico/analisador-semantico-base.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts +3 -3
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +236 -231
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/atribuir.d.ts +3 -1
- package/construtos/atribuir.d.ts.map +1 -1
- package/construtos/atribuir.js +7 -1
- package/construtos/atribuir.js.map +1 -1
- package/construtos/binario.d.ts +18 -7
- package/construtos/binario.d.ts.map +1 -1
- package/construtos/binario.js +18 -7
- package/construtos/binario.js.map +1 -1
- package/construtos/expressao-regular.d.ts +1 -1
- package/construtos/expressao-regular.d.ts.map +1 -1
- package/construtos/index.d.ts +0 -1
- package/construtos/index.d.ts.map +1 -1
- package/construtos/index.js +0 -1
- package/construtos/index.js.map +1 -1
- package/construtos/vetor.d.ts +2 -1
- package/construtos/vetor.d.ts.map +1 -1
- package/construtos/vetor.js +7 -1
- package/construtos/vetor.js.map +1 -1
- package/estruturas/delegua-funcao.d.ts +1 -0
- package/estruturas/delegua-funcao.d.ts.map +1 -1
- package/estruturas/delegua-funcao.js +14 -7
- package/estruturas/delegua-funcao.js.map +1 -1
- package/interfaces/formatador-comum-interface.d.ts +12 -0
- package/interfaces/formatador-comum-interface.d.ts.map +1 -0
- package/interfaces/formatador-comum-interface.js +3 -0
- package/interfaces/formatador-comum-interface.js.map +1 -0
- package/interfaces/index.d.ts +1 -0
- package/interfaces/index.d.ts.map +1 -1
- package/interfaces/index.js +1 -0
- package/interfaces/index.js.map +1 -1
- package/interfaces/pilha-escopos-execucao-interface.d.ts +1 -1
- package/interfaces/pilha-escopos-execucao-interface.d.ts.map +1 -1
- package/interfaces/variavel-hipotetica-interface.d.ts +1 -0
- package/interfaces/variavel-hipotetica-interface.d.ts.map +1 -1
- package/interfaces/visitante-comum-interface.d.ts +21 -21
- package/interfaces/visitante-comum-interface.d.ts.map +1 -1
- package/interpretador/interpretador-base.d.ts +9 -2
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +22 -10
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts.map +1 -1
- package/interpretador/pilha-escopos-execucao.js +16 -6
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/package.json +1 -1
- package/tradutores/tradutor-javascript.d.ts +1 -1
- package/tradutores/tradutor-javascript.d.ts.map +1 -1
- package/tradutores/tradutor-javascript.js +8 -4
- package/tradutores/tradutor-javascript.js.map +1 -1
- package/umd/delegua.js +436 -398
- package/construtos/constante-ou-variavel.d.ts +0 -20
- package/construtos/constante-ou-variavel.d.ts.map +0 -1
- package/construtos/constante-ou-variavel.js +0 -26
- package/construtos/constante-ou-variavel.js.map +0 -1
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.AvaliadorSintatico = void 0;
|
|
7
|
-
const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
8
|
-
const delegua_2 = __importDefault(require("../tipos-de-dados/delegua"));
|
|
9
7
|
const browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime"));
|
|
8
|
+
const delegua_1 = __importDefault(require("../tipos-de-dados/delegua"));
|
|
9
|
+
const delegua_2 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
10
10
|
const construtos_1 = require("../construtos");
|
|
11
11
|
const erro_avaliador_sintatico_1 = require("./erro-avaliador-sintatico");
|
|
12
|
+
const tuplas_1 = require("../construtos/tuplas");
|
|
12
13
|
const declaracoes_1 = require("../declaracoes");
|
|
13
14
|
const lexador_1 = require("../lexador");
|
|
14
|
-
const tuplas_1 = require("../construtos/tuplas");
|
|
15
15
|
/**
|
|
16
16
|
* O avaliador sintático (_Parser_) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
|
|
17
17
|
* Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
|
|
@@ -47,13 +47,13 @@ class AvaliadorSintatico {
|
|
|
47
47
|
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
48
48
|
}
|
|
49
49
|
verificarDefinicaoTipoAtual() {
|
|
50
|
-
const tipos = [...Object.values(
|
|
50
|
+
const tipos = [...Object.values(delegua_1.default)];
|
|
51
51
|
const lexema = this.simboloAtual().lexema.toLowerCase();
|
|
52
52
|
const contemTipo = tipos.find((tipo) => tipo === lexema);
|
|
53
|
-
if (contemTipo && this.verificarTipoProximoSimbolo(
|
|
53
|
+
if (contemTipo && this.verificarTipoProximoSimbolo(delegua_2.default.COLCHETE_ESQUERDO)) {
|
|
54
54
|
const tiposVetores = ['inteiro[]', 'numero[]', 'número[]', 'qualquer[]', 'real[]', 'texto[]'];
|
|
55
55
|
this.avancarEDevolverAnterior();
|
|
56
|
-
if (!this.verificarTipoProximoSimbolo(
|
|
56
|
+
if (!this.verificarTipoProximoSimbolo(delegua_2.default.COLCHETE_DIREITO)) {
|
|
57
57
|
throw this.erro(this.simbolos[this.atual], "Esperado símbolo de fechamento do vetor ']'.");
|
|
58
58
|
}
|
|
59
59
|
const contemTipoVetor = tiposVetores.find((tipo) => tipo === `${lexema}[]`);
|
|
@@ -90,124 +90,124 @@ class AvaliadorSintatico {
|
|
|
90
90
|
const simboloAtual = this.simbolos[this.atual];
|
|
91
91
|
let valores = [];
|
|
92
92
|
switch (simboloAtual.tipo) {
|
|
93
|
-
case
|
|
93
|
+
case delegua_2.default.CHAVE_ESQUERDA:
|
|
94
94
|
this.avancarEDevolverAnterior();
|
|
95
95
|
const chaves = [];
|
|
96
96
|
valores = [];
|
|
97
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
97
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_DIREITA)) {
|
|
98
98
|
return new construtos_1.Dicionario(this.hashArquivo, Number(simboloAtual.linha), [], []);
|
|
99
99
|
}
|
|
100
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
100
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_DIREITA)) {
|
|
101
101
|
const chave = this.atribuir();
|
|
102
|
-
this.consumir(
|
|
102
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' entre chave e valor.");
|
|
103
103
|
const valor = this.atribuir();
|
|
104
104
|
chaves.push(chave);
|
|
105
105
|
valores.push(valor);
|
|
106
|
-
if (this.simbolos[this.atual].tipo !==
|
|
107
|
-
this.consumir(
|
|
106
|
+
if (this.simbolos[this.atual].tipo !== delegua_2.default.CHAVE_DIREITA) {
|
|
107
|
+
this.consumir(delegua_2.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
return new construtos_1.Dicionario(this.hashArquivo, Number(simboloAtual.linha), chaves, valores);
|
|
111
|
-
case
|
|
111
|
+
case delegua_2.default.COLCHETE_ESQUERDO:
|
|
112
112
|
this.avancarEDevolverAnterior();
|
|
113
113
|
valores = [];
|
|
114
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
114
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.COLCHETE_DIREITO)) {
|
|
115
115
|
return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), []);
|
|
116
116
|
}
|
|
117
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
117
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.COLCHETE_DIREITO)) {
|
|
118
118
|
let valor = null;
|
|
119
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
119
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO)) {
|
|
120
120
|
const expressao = this.expressao();
|
|
121
121
|
const argumentos = [expressao];
|
|
122
|
-
while (this.simbolos[this.atual].tipo ===
|
|
122
|
+
while (this.simbolos[this.atual].tipo === delegua_2.default.VIRGULA) {
|
|
123
123
|
this.avancarEDevolverAnterior();
|
|
124
124
|
argumentos.push(this.expressao());
|
|
125
125
|
}
|
|
126
|
-
this.consumir(
|
|
127
|
-
this.consumir(
|
|
126
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
127
|
+
this.consumir(delegua_2.default.COLCHETE_DIREITO, "Esperado ']' após a expressão.");
|
|
128
128
|
return new tuplas_1.SeletorTuplas(...argumentos);
|
|
129
129
|
}
|
|
130
130
|
valor = this.atribuir();
|
|
131
131
|
valores.push(valor);
|
|
132
|
-
if (this.simbolos[this.atual].tipo !==
|
|
133
|
-
this.consumir(
|
|
132
|
+
if (this.simbolos[this.atual].tipo !== delegua_2.default.COLCHETE_DIREITO) {
|
|
133
|
+
this.consumir(delegua_2.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), valores);
|
|
137
|
-
case
|
|
137
|
+
case delegua_2.default.FALSO:
|
|
138
138
|
this.avancarEDevolverAnterior();
|
|
139
139
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), false);
|
|
140
|
-
case
|
|
141
|
-
case
|
|
140
|
+
case delegua_2.default.FUNCAO:
|
|
141
|
+
case delegua_2.default.FUNÇÃO:
|
|
142
142
|
const simboloFuncao = this.avancarEDevolverAnterior();
|
|
143
143
|
return this.corpoDaFuncao(simboloFuncao.lexema);
|
|
144
|
-
case
|
|
144
|
+
case delegua_2.default.IDENTIFICADOR:
|
|
145
145
|
const simboloIdentificador = this.avancarEDevolverAnterior();
|
|
146
146
|
// Se o próximo símbolo é um incremento ou um decremento,
|
|
147
147
|
// aqui deve retornar um unário correspondente.
|
|
148
148
|
// Caso contrário, apenas retornar um construto de variável.
|
|
149
149
|
if (this.simbolos[this.atual] &&
|
|
150
|
-
[
|
|
150
|
+
[delegua_2.default.INCREMENTAR, delegua_2.default.DECREMENTAR].includes(this.simbolos[this.atual].tipo)) {
|
|
151
151
|
const simboloIncrementoDecremento = this.avancarEDevolverAnterior();
|
|
152
152
|
return new construtos_1.Unario(this.hashArquivo, simboloIncrementoDecremento, new construtos_1.Variavel(this.hashArquivo, simboloIdentificador), 'DEPOIS');
|
|
153
153
|
}
|
|
154
154
|
return new construtos_1.Variavel(this.hashArquivo, simboloIdentificador);
|
|
155
|
-
case
|
|
155
|
+
case delegua_2.default.IMPORTAR:
|
|
156
156
|
this.avancarEDevolverAnterior();
|
|
157
157
|
return this.declaracaoImportar();
|
|
158
|
-
case
|
|
158
|
+
case delegua_2.default.ISTO:
|
|
159
159
|
this.avancarEDevolverAnterior();
|
|
160
160
|
return new construtos_1.Isto(this.hashArquivo, Number(simboloAtual.linha), simboloAtual);
|
|
161
|
-
case
|
|
161
|
+
case delegua_2.default.NULO:
|
|
162
162
|
this.avancarEDevolverAnterior();
|
|
163
163
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), null);
|
|
164
|
-
case
|
|
165
|
-
case
|
|
164
|
+
case delegua_2.default.NUMERO:
|
|
165
|
+
case delegua_2.default.TEXTO:
|
|
166
166
|
const simboloNumeroTexto = this.avancarEDevolverAnterior();
|
|
167
167
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloNumeroTexto.linha), simboloNumeroTexto.literal);
|
|
168
|
-
case
|
|
168
|
+
case delegua_2.default.PARENTESE_ESQUERDO:
|
|
169
169
|
this.avancarEDevolverAnterior();
|
|
170
170
|
const expressao = this.expressao();
|
|
171
|
-
this.consumir(
|
|
171
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
172
172
|
return new construtos_1.Agrupamento(this.hashArquivo, Number(simboloAtual.linha), expressao);
|
|
173
|
-
case
|
|
173
|
+
case delegua_2.default.SUPER:
|
|
174
174
|
const simboloSuper = this.avancarEDevolverAnterior();
|
|
175
175
|
// Se o próximo símbolo for uma abertura de parênteses, significa que
|
|
176
176
|
// é uma chamada ao construtor da classe ancestral (superclasse).
|
|
177
177
|
// Se o próximo símbolo for um ponto, significa que é uma chamada
|
|
178
178
|
// a um método da superclasse.
|
|
179
179
|
switch (this.simbolos[this.atual].tipo) {
|
|
180
|
-
case
|
|
181
|
-
return new construtos_1.Super(this.hashArquivo, simboloSuper, new lexador_1.Simbolo(
|
|
180
|
+
case delegua_2.default.PARENTESE_ESQUERDO:
|
|
181
|
+
return new construtos_1.Super(this.hashArquivo, simboloSuper, new lexador_1.Simbolo(delegua_2.default.IDENTIFICADOR, 'construtor', null, simboloSuper.linha, this.hashArquivo));
|
|
182
182
|
default:
|
|
183
|
-
this.consumir(
|
|
184
|
-
const metodoSuperclasse = this.consumir(
|
|
183
|
+
this.consumir(delegua_2.default.PONTO, "Esperado '.' após 'super'.");
|
|
184
|
+
const metodoSuperclasse = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome do método da Superclasse.');
|
|
185
185
|
return new construtos_1.Super(this.hashArquivo, simboloSuper, metodoSuperclasse);
|
|
186
186
|
}
|
|
187
|
-
case
|
|
187
|
+
case delegua_2.default.VERDADEIRO:
|
|
188
188
|
this.avancarEDevolverAnterior();
|
|
189
189
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), true);
|
|
190
|
-
case
|
|
190
|
+
case delegua_2.default.TIPO:
|
|
191
191
|
this.avancarEDevolverAnterior();
|
|
192
|
-
this.consumir(
|
|
192
|
+
this.consumir(delegua_2.default.DE, "Esperado 'de' após 'tipo'.");
|
|
193
193
|
let _expressao;
|
|
194
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
194
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.ESCREVA, delegua_2.default.LEIA, delegua_2.default.FUNCAO, delegua_2.default.FUNÇÃO, delegua_2.default.SE, delegua_2.default.ENQUANTO, delegua_2.default.PARA, delegua_2.default.RETORNA, delegua_1.default.INTEIRO, delegua_1.default.TEXTO, delegua_1.default.VETOR, delegua_1.default.LOGICO, delegua_1.default.LÓGICO, delegua_1.default.VAZIO)) {
|
|
195
195
|
_expressao = this.simboloAnterior();
|
|
196
196
|
}
|
|
197
197
|
else {
|
|
198
198
|
_expressao = this.expressao();
|
|
199
199
|
}
|
|
200
200
|
return new construtos_1.TipoDe(this.hashArquivo, simboloAtual, _expressao instanceof construtos_1.Literal ? _expressao.valor : _expressao);
|
|
201
|
-
case
|
|
201
|
+
case delegua_2.default.EXPRESSAO_REGULAR:
|
|
202
202
|
let valor = '';
|
|
203
203
|
let linhaAtual = this.simbolos[this.atual].linha;
|
|
204
|
-
let eParExpressaoRegular = this.simbolos.filter((l) => l.linha === linhaAtual && l.tipo ===
|
|
204
|
+
let eParExpressaoRegular = this.simbolos.filter((l) => l.linha === linhaAtual && l.tipo === delegua_2.default.EXPRESSAO_REGULAR)
|
|
205
205
|
.length %
|
|
206
206
|
2 ===
|
|
207
207
|
0;
|
|
208
208
|
if (eParExpressaoRegular) {
|
|
209
209
|
this.avancarEDevolverAnterior();
|
|
210
|
-
while (!this.verificarTipoSimboloAtual(
|
|
210
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.EXPRESSAO_REGULAR)) {
|
|
211
211
|
valor += this.simboloAtual().lexema || '';
|
|
212
212
|
this.avancarEDevolverAnterior();
|
|
213
213
|
}
|
|
@@ -219,30 +219,30 @@ class AvaliadorSintatico {
|
|
|
219
219
|
}
|
|
220
220
|
finalizarChamada(entidadeChamada) {
|
|
221
221
|
const argumentos = [];
|
|
222
|
-
if (!this.verificarTipoSimboloAtual(
|
|
222
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
223
223
|
do {
|
|
224
224
|
if (argumentos.length >= 255) {
|
|
225
225
|
throw this.erro(this.simbolos[this.atual], 'Não pode haver mais de 255 argumentos.');
|
|
226
226
|
}
|
|
227
227
|
argumentos.push(this.expressao());
|
|
228
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
228
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
229
229
|
}
|
|
230
|
-
const parenteseDireito = this.consumir(
|
|
230
|
+
const parenteseDireito = this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos.");
|
|
231
231
|
return new construtos_1.Chamada(this.hashArquivo, entidadeChamada, parenteseDireito, argumentos);
|
|
232
232
|
}
|
|
233
233
|
chamar() {
|
|
234
234
|
let expressao = this.primario();
|
|
235
235
|
while (true) {
|
|
236
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
236
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO)) {
|
|
237
237
|
expressao = this.finalizarChamada(expressao);
|
|
238
238
|
}
|
|
239
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
240
|
-
const nome = this.consumir(
|
|
239
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO)) {
|
|
240
|
+
const nome = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado nome de método ou propriedade após '.'.");
|
|
241
241
|
expressao = new construtos_1.AcessoMetodoOuPropriedade(this.hashArquivo, expressao, nome);
|
|
242
242
|
}
|
|
243
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
243
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.COLCHETE_ESQUERDO)) {
|
|
244
244
|
const indice = this.expressao();
|
|
245
|
-
const simboloFechamento = this.consumir(
|
|
245
|
+
const simboloFechamento = this.consumir(delegua_2.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
246
246
|
expressao = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, expressao, indice, simboloFechamento);
|
|
247
247
|
}
|
|
248
248
|
else {
|
|
@@ -252,7 +252,7 @@ class AvaliadorSintatico {
|
|
|
252
252
|
return expressao;
|
|
253
253
|
}
|
|
254
254
|
unario() {
|
|
255
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
255
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.NEGACAO, delegua_2.default.SUBTRACAO, delegua_2.default.BIT_NOT, delegua_2.default.INCREMENTAR, delegua_2.default.DECREMENTAR)) {
|
|
256
256
|
const operador = this.simbolos[this.atual - 1];
|
|
257
257
|
const direito = this.unario();
|
|
258
258
|
return new construtos_1.Unario(this.hashArquivo, operador, direito, 'ANTES');
|
|
@@ -261,7 +261,7 @@ class AvaliadorSintatico {
|
|
|
261
261
|
}
|
|
262
262
|
exponenciacao() {
|
|
263
263
|
let expressao = this.unario();
|
|
264
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
264
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.EXPONENCIACAO)) {
|
|
265
265
|
const operador = this.simbolos[this.atual - 1];
|
|
266
266
|
const direito = this.unario();
|
|
267
267
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -270,7 +270,7 @@ class AvaliadorSintatico {
|
|
|
270
270
|
}
|
|
271
271
|
multiplicar() {
|
|
272
272
|
let expressao = this.exponenciacao();
|
|
273
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
273
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DIVISAO, delegua_2.default.DIVISAO_IGUAL, delegua_2.default.DIVISAO_INTEIRA, delegua_2.default.DIVISAO_INTEIRA_IGUAL, delegua_2.default.MODULO, delegua_2.default.MODULO_IGUAL, delegua_2.default.MULTIPLICACAO, delegua_2.default.MULTIPLICACAO_IGUAL)) {
|
|
274
274
|
const operador = this.simbolos[this.atual - 1];
|
|
275
275
|
const direito = this.exponenciacao();
|
|
276
276
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -284,7 +284,7 @@ class AvaliadorSintatico {
|
|
|
284
284
|
*/
|
|
285
285
|
adicaoOuSubtracao() {
|
|
286
286
|
let expressao = this.multiplicar();
|
|
287
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
287
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SUBTRACAO, delegua_2.default.ADICAO, delegua_2.default.MAIS_IGUAL, delegua_2.default.MENOS_IGUAL)) {
|
|
288
288
|
const operador = this.simbolos[this.atual - 1];
|
|
289
289
|
const direito = this.multiplicar();
|
|
290
290
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -293,7 +293,7 @@ class AvaliadorSintatico {
|
|
|
293
293
|
}
|
|
294
294
|
bitShift() {
|
|
295
295
|
let expressao = this.adicaoOuSubtracao();
|
|
296
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
296
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.MENOR_MENOR, delegua_2.default.MAIOR_MAIOR)) {
|
|
297
297
|
const operador = this.simbolos[this.atual - 1];
|
|
298
298
|
const direito = this.adicaoOuSubtracao();
|
|
299
299
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -302,7 +302,7 @@ class AvaliadorSintatico {
|
|
|
302
302
|
}
|
|
303
303
|
bitE() {
|
|
304
304
|
let expressao = this.bitShift();
|
|
305
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
305
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.BIT_AND)) {
|
|
306
306
|
const operador = this.simbolos[this.atual - 1];
|
|
307
307
|
const direito = this.bitShift();
|
|
308
308
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -311,7 +311,7 @@ class AvaliadorSintatico {
|
|
|
311
311
|
}
|
|
312
312
|
bitOu() {
|
|
313
313
|
let expressao = this.bitE();
|
|
314
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
314
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.BIT_OR, delegua_2.default.BIT_XOR)) {
|
|
315
315
|
const operador = this.simbolos[this.atual - 1];
|
|
316
316
|
const direito = this.bitE();
|
|
317
317
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -320,7 +320,7 @@ class AvaliadorSintatico {
|
|
|
320
320
|
}
|
|
321
321
|
comparar() {
|
|
322
322
|
let expressao = this.bitOu();
|
|
323
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
323
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.MAIOR, delegua_2.default.MAIOR_IGUAL, delegua_2.default.MENOR, delegua_2.default.MENOR_IGUAL)) {
|
|
324
324
|
const operador = this.simbolos[this.atual - 1];
|
|
325
325
|
const direito = this.bitOu();
|
|
326
326
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -329,7 +329,7 @@ class AvaliadorSintatico {
|
|
|
329
329
|
}
|
|
330
330
|
comparacaoIgualdade() {
|
|
331
331
|
let expressao = this.comparar();
|
|
332
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
332
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DIFERENTE, delegua_2.default.IGUAL_IGUAL)) {
|
|
333
333
|
const operador = this.simbolos[this.atual - 1];
|
|
334
334
|
const direito = this.comparar();
|
|
335
335
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
@@ -338,7 +338,7 @@ class AvaliadorSintatico {
|
|
|
338
338
|
}
|
|
339
339
|
em() {
|
|
340
340
|
let expressao = this.comparacaoIgualdade();
|
|
341
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
341
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.EM)) {
|
|
342
342
|
const operador = this.simbolos[this.atual - 1];
|
|
343
343
|
const direito = this.comparacaoIgualdade();
|
|
344
344
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
@@ -347,7 +347,7 @@ class AvaliadorSintatico {
|
|
|
347
347
|
}
|
|
348
348
|
e() {
|
|
349
349
|
let expressao = this.em();
|
|
350
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
350
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.E)) {
|
|
351
351
|
const operador = this.simbolos[this.atual - 1];
|
|
352
352
|
const direito = this.em();
|
|
353
353
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
@@ -356,7 +356,7 @@ class AvaliadorSintatico {
|
|
|
356
356
|
}
|
|
357
357
|
ou() {
|
|
358
358
|
let expressao = this.e();
|
|
359
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
359
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.OU)) {
|
|
360
360
|
const operador = this.simbolos[this.atual - 1];
|
|
361
361
|
const direito = this.e();
|
|
362
362
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
@@ -371,16 +371,21 @@ class AvaliadorSintatico {
|
|
|
371
371
|
const expressao = this.ou();
|
|
372
372
|
if (expressao instanceof construtos_1.Binario &&
|
|
373
373
|
[
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
374
|
+
delegua_2.default.MAIS_IGUAL,
|
|
375
|
+
delegua_2.default.MENOS_IGUAL,
|
|
376
|
+
delegua_2.default.MULTIPLICACAO_IGUAL,
|
|
377
|
+
delegua_2.default.DIVISAO_IGUAL,
|
|
378
|
+
delegua_2.default.DIVISAO_INTEIRA_IGUAL,
|
|
379
|
+
delegua_2.default.MODULO_IGUAL,
|
|
380
380
|
].includes(expressao.operador.tipo)) {
|
|
381
|
-
|
|
381
|
+
let simbolo = expressao.esquerda.simbolo;
|
|
382
|
+
if (expressao.esquerda instanceof construtos_1.AcessoIndiceVariavel) {
|
|
383
|
+
simbolo = expressao.esquerda.entidadeChamada.simbolo;
|
|
384
|
+
return new construtos_1.Atribuir(this.hashArquivo, simbolo, expressao, expressao.esquerda.indice);
|
|
385
|
+
}
|
|
386
|
+
return new construtos_1.Atribuir(this.hashArquivo, simbolo, expressao);
|
|
382
387
|
}
|
|
383
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
388
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL)) {
|
|
384
389
|
const igual = this.simbolos[this.atual - 1];
|
|
385
390
|
const valor = this.expressao();
|
|
386
391
|
if (expressao instanceof construtos_1.Variavel) {
|
|
@@ -399,13 +404,13 @@ class AvaliadorSintatico {
|
|
|
399
404
|
return expressao;
|
|
400
405
|
}
|
|
401
406
|
expressao() {
|
|
402
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
407
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.LEIA))
|
|
403
408
|
return this.declaracaoLeia();
|
|
404
409
|
return this.atribuir();
|
|
405
410
|
}
|
|
406
411
|
blocoEscopo() {
|
|
407
412
|
let declaracoes = [];
|
|
408
|
-
while (!this.verificarTipoSimboloAtual(
|
|
413
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) && !this.estaNoFinal()) {
|
|
409
414
|
const retornoDeclaracao = this.resolverDeclaracaoForaDeBloco();
|
|
410
415
|
if (Array.isArray(retornoDeclaracao)) {
|
|
411
416
|
declaracoes = declaracoes.concat(retornoDeclaracao);
|
|
@@ -414,8 +419,8 @@ class AvaliadorSintatico {
|
|
|
414
419
|
declaracoes.push(retornoDeclaracao);
|
|
415
420
|
}
|
|
416
421
|
}
|
|
417
|
-
this.consumir(
|
|
418
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
422
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' após o bloco.");
|
|
423
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
419
424
|
return declaracoes;
|
|
420
425
|
}
|
|
421
426
|
declaracaoEnquanto() {
|
|
@@ -431,22 +436,22 @@ class AvaliadorSintatico {
|
|
|
431
436
|
}
|
|
432
437
|
declaracaoEscreva() {
|
|
433
438
|
const simboloAtual = this.simbolos[this.atual];
|
|
434
|
-
this.consumir(
|
|
439
|
+
this.consumir(delegua_2.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em escreva.");
|
|
435
440
|
const argumentos = [];
|
|
436
|
-
if (!this.verificarTipoSimboloAtual(
|
|
441
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
437
442
|
do {
|
|
438
443
|
argumentos.push(this.expressao());
|
|
439
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
444
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
440
445
|
}
|
|
441
|
-
this.consumir(
|
|
446
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após os valores em escreva.");
|
|
442
447
|
// Ponto-e-vírgula é opcional aqui.
|
|
443
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
448
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
444
449
|
return new declaracoes_1.Escreva(Number(simboloAtual.linha), simboloAtual.hashArquivo, argumentos);
|
|
445
450
|
}
|
|
446
451
|
declaracaoExpressao() {
|
|
447
452
|
const expressao = this.expressao();
|
|
448
453
|
// Ponto-e-vírgula é opcional aqui.
|
|
449
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
454
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
450
455
|
return new declaracoes_1.Expressao(expressao);
|
|
451
456
|
}
|
|
452
457
|
declaracaoComentarioMultilinha() {
|
|
@@ -455,7 +460,7 @@ class AvaliadorSintatico {
|
|
|
455
460
|
do {
|
|
456
461
|
simboloComentario = this.avancarEDevolverAnterior();
|
|
457
462
|
conteudos.push(simboloComentario.literal);
|
|
458
|
-
} while (simboloComentario.tipo ===
|
|
463
|
+
} while (simboloComentario.tipo === delegua_2.default.LINHA_COMENTARIO);
|
|
459
464
|
return new construtos_1.Comentario(simboloComentario.hashArquivo, simboloComentario.linha, conteudos, true);
|
|
460
465
|
}
|
|
461
466
|
declaracaoComentarioUmaLinha() {
|
|
@@ -467,24 +472,24 @@ class AvaliadorSintatico {
|
|
|
467
472
|
this.erro(this.simbolos[this.atual - 1], "'continua' precisa estar em um laço de repetição.");
|
|
468
473
|
}
|
|
469
474
|
// Ponto-e-vírgula é opcional aqui.
|
|
470
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
475
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
471
476
|
return new declaracoes_1.Continua(this.simbolos[this.atual - 1]);
|
|
472
477
|
}
|
|
473
478
|
declaracaoEscolha() {
|
|
474
479
|
try {
|
|
475
480
|
this.blocos += 1;
|
|
476
481
|
const condicao = this.expressao();
|
|
477
|
-
this.consumir(
|
|
482
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo do 'escolha'.");
|
|
478
483
|
const caminhos = [];
|
|
479
484
|
let caminhoPadrao = null;
|
|
480
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
481
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
485
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_DIREITA) && !this.estaNoFinal()) {
|
|
486
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CASO)) {
|
|
482
487
|
const caminhoCondicoes = [this.expressao()];
|
|
483
|
-
this.consumir(
|
|
484
|
-
while (this.verificarTipoSimboloAtual(
|
|
485
|
-
this.consumir(
|
|
488
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' após o 'caso'.");
|
|
489
|
+
while (this.verificarTipoSimboloAtual(delegua_2.default.CASO)) {
|
|
490
|
+
this.consumir(delegua_2.default.CASO, null);
|
|
486
491
|
caminhoCondicoes.push(this.expressao());
|
|
487
|
-
this.consumir(
|
|
492
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' após declaração do 'caso'.");
|
|
488
493
|
}
|
|
489
494
|
let declaracoes = [];
|
|
490
495
|
do {
|
|
@@ -495,27 +500,27 @@ class AvaliadorSintatico {
|
|
|
495
500
|
else {
|
|
496
501
|
declaracoes.push(retornoDeclaracao);
|
|
497
502
|
}
|
|
498
|
-
} while (!this.verificarTipoSimboloAtual(
|
|
499
|
-
!this.verificarTipoSimboloAtual(
|
|
500
|
-
!this.verificarTipoSimboloAtual(
|
|
503
|
+
} while (!this.verificarTipoSimboloAtual(delegua_2.default.CASO) &&
|
|
504
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.PADRAO) &&
|
|
505
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA));
|
|
501
506
|
caminhos.push({
|
|
502
507
|
condicoes: caminhoCondicoes,
|
|
503
508
|
declaracoes,
|
|
504
509
|
});
|
|
505
510
|
}
|
|
506
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
511
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PADRAO)) {
|
|
507
512
|
if (caminhoPadrao !== null) {
|
|
508
513
|
const excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.simbolos[this.atual], "Você só pode ter um 'padrao' em cada declaração de 'escolha'.");
|
|
509
514
|
this.erros.push(excecao);
|
|
510
515
|
throw excecao;
|
|
511
516
|
}
|
|
512
|
-
this.consumir(
|
|
517
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, "Esperado ':' após declaração do 'padrao'.");
|
|
513
518
|
const declaracoes = [];
|
|
514
519
|
do {
|
|
515
520
|
declaracoes.push(this.resolverDeclaracao());
|
|
516
|
-
} while (!this.verificarTipoSimboloAtual(
|
|
517
|
-
!this.verificarTipoSimboloAtual(
|
|
518
|
-
!this.verificarTipoSimboloAtual(
|
|
521
|
+
} while (!this.verificarTipoSimboloAtual(delegua_2.default.CASO) &&
|
|
522
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.PADRAO) &&
|
|
523
|
+
!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA));
|
|
519
524
|
caminhoPadrao = {
|
|
520
525
|
declaracoes,
|
|
521
526
|
};
|
|
@@ -536,7 +541,7 @@ class AvaliadorSintatico {
|
|
|
536
541
|
try {
|
|
537
542
|
this.blocos += 1;
|
|
538
543
|
const caminhoFazer = this.resolverDeclaracao();
|
|
539
|
-
this.consumir(
|
|
544
|
+
this.consumir(delegua_2.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo do 'fazer'.");
|
|
540
545
|
const condicaoEnquanto = this.expressao();
|
|
541
546
|
return new declaracoes_1.Fazer(simboloFazer.hashArquivo, Number(simboloFazer.linha), caminhoFazer, condicaoEnquanto);
|
|
542
547
|
}
|
|
@@ -545,9 +550,9 @@ class AvaliadorSintatico {
|
|
|
545
550
|
}
|
|
546
551
|
}
|
|
547
552
|
declaracaoImportar() {
|
|
548
|
-
this.consumir(
|
|
553
|
+
this.consumir(delegua_2.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
|
|
549
554
|
const caminho = this.expressao();
|
|
550
|
-
const simboloFechamento = this.consumir(
|
|
555
|
+
const simboloFechamento = this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
551
556
|
return new declaracoes_1.Importar(caminho, simboloFechamento);
|
|
552
557
|
}
|
|
553
558
|
/**
|
|
@@ -556,21 +561,21 @@ class AvaliadorSintatico {
|
|
|
556
561
|
*/
|
|
557
562
|
declaracaoLeia() {
|
|
558
563
|
const simboloLeia = this.simbolos[this.atual];
|
|
559
|
-
this.consumir(
|
|
564
|
+
this.consumir(delegua_2.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos argumentos em instrução `leia`.");
|
|
560
565
|
const argumentos = [];
|
|
561
|
-
if (this.simbolos[this.atual].tipo !==
|
|
566
|
+
if (this.simbolos[this.atual].tipo !== delegua_2.default.PARENTESE_DIREITO) {
|
|
562
567
|
do {
|
|
563
568
|
argumentos.push(this.expressao());
|
|
564
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
569
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
565
570
|
}
|
|
566
|
-
this.consumir(
|
|
571
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos em instrução `leia`.");
|
|
567
572
|
return new declaracoes_1.Leia(simboloLeia, argumentos);
|
|
568
573
|
}
|
|
569
574
|
declaracaoPara() {
|
|
570
575
|
try {
|
|
571
576
|
const simboloPara = this.simbolos[this.atual - 1];
|
|
572
577
|
this.blocos += 1;
|
|
573
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
578
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CADA)) {
|
|
574
579
|
return this.declaracaoParaCada(simboloPara);
|
|
575
580
|
}
|
|
576
581
|
return this.declaracaoParaTradicional(simboloPara);
|
|
@@ -580,8 +585,8 @@ class AvaliadorSintatico {
|
|
|
580
585
|
}
|
|
581
586
|
}
|
|
582
587
|
declaracaoParaCada(simboloPara) {
|
|
583
|
-
const nomeVariavelIteracao = this.consumir(
|
|
584
|
-
if (!this.verificarSeSimboloAtualEIgualA(
|
|
588
|
+
const nomeVariavelIteracao = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado identificador de variável de iteração para instrução 'para cada'.");
|
|
589
|
+
if (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.DE, delegua_2.default.EM)) {
|
|
585
590
|
throw this.erro(this.simbolos[this.atual], "Esperado palavras reservadas 'em' ou 'de' após variável de iteração em instrução 'para cada'.");
|
|
586
591
|
}
|
|
587
592
|
const vetor = this.expressao();
|
|
@@ -589,33 +594,33 @@ class AvaliadorSintatico {
|
|
|
589
594
|
return new declaracoes_1.ParaCada(this.hashArquivo, Number(simboloPara.linha), nomeVariavelIteracao.lexema, vetor, corpo);
|
|
590
595
|
}
|
|
591
596
|
declaracaoParaTradicional(simboloPara) {
|
|
592
|
-
const comParenteses = this.verificarSeSimboloAtualEIgualA(
|
|
597
|
+
const comParenteses = this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO);
|
|
593
598
|
let inicializador;
|
|
594
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
599
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA)) {
|
|
595
600
|
inicializador = null;
|
|
596
601
|
}
|
|
597
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
602
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VARIAVEL)) {
|
|
598
603
|
inicializador = this.declaracaoDeVariaveis();
|
|
599
604
|
}
|
|
600
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
605
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CONSTANTE)) {
|
|
601
606
|
inicializador = this.declaracaoDeConstantes();
|
|
602
607
|
}
|
|
603
608
|
else {
|
|
604
609
|
inicializador = this.declaracaoExpressao();
|
|
605
610
|
}
|
|
606
611
|
let condicao = null;
|
|
607
|
-
if (!this.verificarTipoSimboloAtual(
|
|
612
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PONTO_E_VIRGULA)) {
|
|
608
613
|
condicao = this.expressao();
|
|
609
614
|
}
|
|
610
615
|
// Ponto-e-vírgula é opcional aqui.
|
|
611
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
616
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
612
617
|
let incrementar = null;
|
|
613
|
-
if (!this.verificarTipoSimboloAtual(
|
|
618
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
614
619
|
incrementar = this.expressao();
|
|
615
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
620
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.INCREMENTAR, delegua_2.default.DECREMENTAR);
|
|
616
621
|
}
|
|
617
622
|
if (comParenteses) {
|
|
618
|
-
this.consumir(
|
|
623
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após cláusulas de inicialização, condição e incremento.");
|
|
619
624
|
}
|
|
620
625
|
const corpo = this.resolverDeclaracao();
|
|
621
626
|
return new declaracoes_1.Para(this.hashArquivo, Number(simboloPara.linha), inicializador, condicao, incrementar, corpo);
|
|
@@ -624,30 +629,30 @@ class AvaliadorSintatico {
|
|
|
624
629
|
const simboloChave = this.simbolos[this.atual - 1];
|
|
625
630
|
let valor = null;
|
|
626
631
|
if ([
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
632
|
+
delegua_2.default.CHAVE_ESQUERDA,
|
|
633
|
+
delegua_2.default.COLCHETE_ESQUERDO,
|
|
634
|
+
delegua_2.default.FALSO,
|
|
635
|
+
delegua_2.default.IDENTIFICADOR,
|
|
636
|
+
delegua_2.default.ISTO,
|
|
637
|
+
delegua_2.default.NEGACAO,
|
|
638
|
+
delegua_2.default.NUMERO,
|
|
639
|
+
delegua_2.default.NULO,
|
|
640
|
+
delegua_2.default.PARENTESE_ESQUERDO,
|
|
641
|
+
delegua_2.default.SUPER,
|
|
642
|
+
delegua_2.default.TEXTO,
|
|
643
|
+
delegua_2.default.VERDADEIRO,
|
|
639
644
|
].includes(this.simbolos[this.atual].tipo)) {
|
|
640
645
|
valor = this.expressao();
|
|
641
646
|
}
|
|
642
647
|
// Ponto-e-vírgula é opcional aqui.
|
|
643
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
648
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
644
649
|
return new declaracoes_1.Retorna(simboloChave, valor);
|
|
645
650
|
}
|
|
646
651
|
declaracaoSe() {
|
|
647
652
|
const condicao = this.expressao();
|
|
648
653
|
const caminhoEntao = this.resolverDeclaracao();
|
|
649
654
|
let caminhoSenao = null;
|
|
650
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
655
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SENAO, delegua_2.default.SENÃO)) {
|
|
651
656
|
caminhoSenao = this.resolverDeclaracao();
|
|
652
657
|
}
|
|
653
658
|
return new declaracoes_1.Se(condicao, caminhoEntao, [], caminhoSenao);
|
|
@@ -657,16 +662,16 @@ class AvaliadorSintatico {
|
|
|
657
662
|
this.erro(this.simbolos[this.atual - 1], "'sustar' ou 'pausa' deve estar dentro de um laço de repetição.");
|
|
658
663
|
}
|
|
659
664
|
// Ponto-e-vírgula é opcional aqui.
|
|
660
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
665
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
661
666
|
return new declaracoes_1.Sustar(this.simbolos[this.atual - 1]);
|
|
662
667
|
}
|
|
663
668
|
declaracaoTente() {
|
|
664
669
|
const simboloTente = this.simbolos[this.atual - 1];
|
|
665
|
-
this.consumir(
|
|
670
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'tente'.");
|
|
666
671
|
const blocoTente = this.blocoEscopo();
|
|
667
672
|
let blocoPegue = null;
|
|
668
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
669
|
-
if (this.verificarTipoSimboloAtual(
|
|
673
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.PEGUE)) {
|
|
674
|
+
if (this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_ESQUERDO)) {
|
|
670
675
|
// Caso 1: com parâmetro de erro.
|
|
671
676
|
// `pegue` recebe um `FuncaoConstruto`.
|
|
672
677
|
blocoPegue = this.corpoDaFuncao('bloco `pegue`');
|
|
@@ -674,25 +679,25 @@ class AvaliadorSintatico {
|
|
|
674
679
|
else {
|
|
675
680
|
// Caso 2: sem parâmetro de erro.
|
|
676
681
|
// `pegue` recebe um bloco.
|
|
677
|
-
this.consumir(
|
|
682
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
|
|
678
683
|
blocoPegue = this.blocoEscopo();
|
|
679
684
|
}
|
|
680
685
|
}
|
|
681
686
|
let blocoSenao = null;
|
|
682
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
683
|
-
this.consumir(
|
|
687
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SENAO, delegua_2.default.SENÃO)) {
|
|
688
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'senão'.");
|
|
684
689
|
blocoSenao = this.blocoEscopo();
|
|
685
690
|
}
|
|
686
691
|
let blocoFinalmente = null;
|
|
687
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
688
|
-
this.consumir(
|
|
692
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.FINALMENTE)) {
|
|
693
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'finalmente'.");
|
|
689
694
|
blocoFinalmente = this.blocoEscopo();
|
|
690
695
|
}
|
|
691
696
|
return new declaracoes_1.Tente(simboloTente.hashArquivo, Number(simboloTente.linha), blocoTente, blocoPegue, blocoSenao, blocoFinalmente);
|
|
692
697
|
}
|
|
693
698
|
resolverDecorador() {
|
|
694
699
|
this.pilhaDecoradores = [];
|
|
695
|
-
while (this.verificarTipoSimboloAtual(
|
|
700
|
+
while (this.verificarTipoSimboloAtual(delegua_2.default.ARROBA)) {
|
|
696
701
|
let nomeDecorador = '';
|
|
697
702
|
let linha;
|
|
698
703
|
let parametros = [];
|
|
@@ -700,12 +705,12 @@ class AvaliadorSintatico {
|
|
|
700
705
|
linha = this.simbolos[this.atual].linha;
|
|
701
706
|
let simbolosLinhaAtual = this.simbolos.filter((l) => l.linha === linha);
|
|
702
707
|
for (let simbolo of simbolosLinhaAtual) {
|
|
703
|
-
parenteseEsquerdo = this.verificarSeSimboloAtualEIgualA(
|
|
708
|
+
parenteseEsquerdo = this.verificarSeSimboloAtualEIgualA(delegua_2.default.PARENTESE_ESQUERDO);
|
|
704
709
|
if (parenteseEsquerdo) {
|
|
705
|
-
if (!this.verificarTipoSimboloAtual(
|
|
710
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
706
711
|
parametros = this.logicaComumParametros();
|
|
707
712
|
}
|
|
708
|
-
this.consumir(
|
|
713
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
709
714
|
break;
|
|
710
715
|
}
|
|
711
716
|
this.avancarEDevolverAnterior();
|
|
@@ -724,65 +729,65 @@ class AvaliadorSintatico {
|
|
|
724
729
|
*/
|
|
725
730
|
resolverDeclaracao() {
|
|
726
731
|
switch (this.simbolos[this.atual].tipo) {
|
|
727
|
-
case
|
|
732
|
+
case delegua_2.default.CHAVE_ESQUERDA:
|
|
728
733
|
const simboloInicioBloco = this.avancarEDevolverAnterior();
|
|
729
734
|
return new declaracoes_1.Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
730
|
-
case
|
|
735
|
+
case delegua_2.default.COMENTARIO:
|
|
731
736
|
return this.declaracaoComentarioUmaLinha();
|
|
732
|
-
case
|
|
737
|
+
case delegua_2.default.CONSTANTE:
|
|
733
738
|
this.avancarEDevolverAnterior();
|
|
734
739
|
return this.declaracaoDeConstantes();
|
|
735
|
-
case
|
|
740
|
+
case delegua_2.default.CONTINUA:
|
|
736
741
|
this.avancarEDevolverAnterior();
|
|
737
742
|
return this.declaracaoContinua();
|
|
738
|
-
case
|
|
743
|
+
case delegua_2.default.ENQUANTO:
|
|
739
744
|
this.avancarEDevolverAnterior();
|
|
740
745
|
return this.declaracaoEnquanto();
|
|
741
|
-
case
|
|
746
|
+
case delegua_2.default.ESCOLHA:
|
|
742
747
|
this.avancarEDevolverAnterior();
|
|
743
748
|
return this.declaracaoEscolha();
|
|
744
|
-
case
|
|
749
|
+
case delegua_2.default.ESCREVA:
|
|
745
750
|
this.avancarEDevolverAnterior();
|
|
746
751
|
return this.declaracaoEscreva();
|
|
747
|
-
case
|
|
752
|
+
case delegua_2.default.FALHAR:
|
|
748
753
|
this.avancarEDevolverAnterior();
|
|
749
754
|
return this.declaracaoFalhar();
|
|
750
|
-
case
|
|
755
|
+
case delegua_2.default.FAZER:
|
|
751
756
|
this.avancarEDevolverAnterior();
|
|
752
757
|
return this.declaracaoFazer();
|
|
753
|
-
case
|
|
758
|
+
case delegua_2.default.LINHA_COMENTARIO:
|
|
754
759
|
return this.declaracaoComentarioMultilinha();
|
|
755
|
-
case
|
|
760
|
+
case delegua_2.default.PARA:
|
|
756
761
|
this.avancarEDevolverAnterior();
|
|
757
762
|
return this.declaracaoPara();
|
|
758
|
-
case
|
|
759
|
-
case
|
|
763
|
+
case delegua_2.default.PAUSA:
|
|
764
|
+
case delegua_2.default.SUSTAR:
|
|
760
765
|
this.avancarEDevolverAnterior();
|
|
761
766
|
return this.declaracaoSustar();
|
|
762
|
-
case
|
|
767
|
+
case delegua_2.default.SE:
|
|
763
768
|
this.avancarEDevolverAnterior();
|
|
764
769
|
return this.declaracaoSe();
|
|
765
|
-
case
|
|
770
|
+
case delegua_2.default.RETORNA:
|
|
766
771
|
this.avancarEDevolverAnterior();
|
|
767
772
|
return this.declaracaoRetorna();
|
|
768
|
-
case
|
|
773
|
+
case delegua_2.default.TENDO:
|
|
769
774
|
this.avancarEDevolverAnterior();
|
|
770
775
|
return this.declaracaoTendoComo();
|
|
771
|
-
case
|
|
776
|
+
case delegua_2.default.TENTE:
|
|
772
777
|
this.avancarEDevolverAnterior();
|
|
773
778
|
return this.declaracaoTente();
|
|
774
|
-
case
|
|
779
|
+
case delegua_2.default.VARIAVEL:
|
|
775
780
|
this.avancarEDevolverAnterior();
|
|
776
781
|
return this.declaracaoDeVariaveis();
|
|
777
782
|
}
|
|
778
783
|
const simboloAtual = this.simbolos[this.atual];
|
|
779
|
-
if (simboloAtual.tipo ===
|
|
784
|
+
if (simboloAtual.tipo === delegua_2.default.IDENTIFICADOR) {
|
|
780
785
|
// Pela gramática, a seguinte situação não pode ocorrer:
|
|
781
786
|
// 1. O símbolo anterior ser um identificador; e
|
|
782
787
|
// 2. O símbolo anterior estar na mesma linha do identificador atual.
|
|
783
788
|
const simboloAnterior = this.simbolos[this.atual - 1];
|
|
784
789
|
if (!!simboloAnterior &&
|
|
785
|
-
simboloAnterior.tipo ===
|
|
790
|
+
simboloAnterior.tipo === delegua_2.default.IDENTIFICADOR &&
|
|
786
791
|
simboloAnterior.linha === simboloAtual.linha) {
|
|
787
792
|
this.erro(this.simbolos[this.atual], 'Não é permitido ter dois identificadores seguidos na mesma linha.');
|
|
788
793
|
}
|
|
@@ -792,19 +797,19 @@ class AvaliadorSintatico {
|
|
|
792
797
|
declaracaoTendoComo() {
|
|
793
798
|
const simboloTendo = this.simbolos[this.atual - 1];
|
|
794
799
|
const expressaoInicializacao = this.expressao();
|
|
795
|
-
this.consumir(
|
|
796
|
-
const simboloNomeVariavel = this.consumir(
|
|
797
|
-
this.consumir(
|
|
800
|
+
this.consumir(delegua_2.default.COMO, "Esperado palavra reservada 'como' após expressão de inicialização de variável, em declaração 'tendo'.");
|
|
801
|
+
const simboloNomeVariavel = this.consumir(delegua_2.default.IDENTIFICADOR, "Esperado nome do identificador em declaração 'tendo'.");
|
|
802
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado chave esquerda para abertura de bloco em declaração 'tendo'.");
|
|
798
803
|
const blocoCorpo = this.blocoEscopo();
|
|
799
804
|
return new declaracoes_1.TendoComo(simboloTendo.linha, simboloTendo.hashArquivo, simboloNomeVariavel, expressaoInicializacao, new declaracoes_1.Bloco(simboloTendo.linha, simboloTendo.hashArquivo, blocoCorpo));
|
|
800
805
|
}
|
|
801
806
|
declaracaoDesestruturacaoVariavel() {
|
|
802
807
|
const identificadores = [];
|
|
803
808
|
do {
|
|
804
|
-
identificadores.push(this.consumir(
|
|
805
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
806
|
-
this.consumir(
|
|
807
|
-
this.consumir(
|
|
809
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
810
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
811
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, 'Esperado chave direita para concluir relação de variáveis a serem desestruturadas.');
|
|
812
|
+
this.consumir(delegua_2.default.IGUAL, 'Esperado igual após relação de propriedades da desestruturação.');
|
|
808
813
|
const inicializador = this.expressao();
|
|
809
814
|
// TODO: Para cada variável dos identificadores, emitir um `AcessoMetodoOuPropriedade` usando
|
|
810
815
|
// como prefixo o nome do inicializador, e o sufixo o nome de cada propriedade.
|
|
@@ -822,45 +827,45 @@ class AvaliadorSintatico {
|
|
|
822
827
|
const identificadores = [];
|
|
823
828
|
let retorno = [];
|
|
824
829
|
let tipo = null;
|
|
825
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
830
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_ESQUERDA)) {
|
|
826
831
|
return this.declaracaoDesestruturacaoVariavel();
|
|
827
832
|
}
|
|
828
833
|
do {
|
|
829
|
-
identificadores.push(this.consumir(
|
|
830
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
831
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
834
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
835
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
836
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
832
837
|
tipo = this.verificarDefinicaoTipoAtual();
|
|
833
838
|
this.avancarEDevolverAnterior();
|
|
834
839
|
}
|
|
835
|
-
if (!this.verificarSeSimboloAtualEIgualA(
|
|
840
|
+
if (!this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL)) {
|
|
836
841
|
// Inicialização de variáveis sem valor.
|
|
837
842
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
838
843
|
retorno.push(new declaracoes_1.Var(identificador, null, tipo));
|
|
839
844
|
}
|
|
840
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
845
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
841
846
|
return retorno;
|
|
842
847
|
}
|
|
843
848
|
const inicializadores = [];
|
|
844
849
|
do {
|
|
845
850
|
inicializadores.push(this.expressao());
|
|
846
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
851
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
847
852
|
if (identificadores.length !== inicializadores.length) {
|
|
848
853
|
throw this.erro(this.simboloAtual(), 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
849
854
|
}
|
|
850
855
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
851
|
-
tipo = inicializadores[indice] instanceof tuplas_1.Tupla ?
|
|
856
|
+
tipo = inicializadores[indice] instanceof tuplas_1.Tupla ? delegua_1.default.TUPLA : tipo;
|
|
852
857
|
retorno.push(new declaracoes_1.Var(identificador, inicializadores[indice], tipo));
|
|
853
858
|
}
|
|
854
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
859
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
855
860
|
return retorno;
|
|
856
861
|
}
|
|
857
862
|
declaracaoDesestruturacaoConstante() {
|
|
858
863
|
const identificadores = [];
|
|
859
864
|
do {
|
|
860
|
-
identificadores.push(this.consumir(
|
|
861
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
862
|
-
this.consumir(
|
|
863
|
-
this.consumir(
|
|
865
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da variável.'));
|
|
866
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
867
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, 'Esperado chave direita para concluir relação de variáveis a serem desestruturadas.');
|
|
868
|
+
this.consumir(delegua_2.default.IGUAL, 'Esperado igual após relação de propriedades da desestruturação.');
|
|
864
869
|
const inicializador = this.expressao();
|
|
865
870
|
// TODO: Para cada variável dos identificadores, emitir um `AcessoMetodoOuPropriedade` usando
|
|
866
871
|
// como prefixo o nome do inicializador, e o sufixo o nome de cada propriedade.
|
|
@@ -877,21 +882,21 @@ class AvaliadorSintatico {
|
|
|
877
882
|
declaracaoDeConstantes() {
|
|
878
883
|
const identificadores = [];
|
|
879
884
|
let tipo = null;
|
|
880
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
885
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CHAVE_ESQUERDA)) {
|
|
881
886
|
return this.declaracaoDesestruturacaoConstante();
|
|
882
887
|
}
|
|
883
888
|
do {
|
|
884
|
-
identificadores.push(this.consumir(
|
|
885
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
886
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
889
|
+
identificadores.push(this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da constante.'));
|
|
890
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
891
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
887
892
|
tipo = this.verificarDefinicaoTipoAtual();
|
|
888
893
|
this.avancarEDevolverAnterior();
|
|
889
894
|
}
|
|
890
|
-
this.consumir(
|
|
895
|
+
this.consumir(delegua_2.default.IGUAL, "Esperado '=' após identificador em instrução 'constante'.");
|
|
891
896
|
const inicializadores = [];
|
|
892
897
|
do {
|
|
893
898
|
inicializadores.push(this.expressao());
|
|
894
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
899
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
895
900
|
if (identificadores.length !== inicializadores.length) {
|
|
896
901
|
throw this.erro(this.simboloAtual(), 'Quantidade de identificadores à esquerda do igual é diferente da quantidade de valores à direita.');
|
|
897
902
|
}
|
|
@@ -899,18 +904,18 @@ class AvaliadorSintatico {
|
|
|
899
904
|
for (let [indice, identificador] of identificadores.entries()) {
|
|
900
905
|
retorno.push(new declaracoes_1.Const(identificador, inicializadores[indice], tipo));
|
|
901
906
|
}
|
|
902
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
907
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
903
908
|
return retorno;
|
|
904
909
|
}
|
|
905
910
|
funcao(tipo) {
|
|
906
911
|
let simbolo;
|
|
907
912
|
switch (this.simbolos[this.atual].tipo) {
|
|
908
|
-
case
|
|
913
|
+
case delegua_2.default.CONSTRUTOR:
|
|
909
914
|
simbolo = this.avancarEDevolverAnterior();
|
|
910
915
|
this.pilhaDecoradores = [];
|
|
911
916
|
break;
|
|
912
917
|
default:
|
|
913
|
-
simbolo = this.consumir(
|
|
918
|
+
simbolo = this.consumir(delegua_2.default.IDENTIFICADOR, `Esperado nome de ${tipo}.`);
|
|
914
919
|
break;
|
|
915
920
|
}
|
|
916
921
|
return new declaracoes_1.FuncaoDeclaracao(simbolo, this.corpoDaFuncao(tipo), null, this.pilhaDecoradores);
|
|
@@ -919,18 +924,18 @@ class AvaliadorSintatico {
|
|
|
919
924
|
const parametros = [];
|
|
920
925
|
do {
|
|
921
926
|
const parametro = {};
|
|
922
|
-
if (this.simbolos[this.atual].tipo ===
|
|
923
|
-
this.consumir(
|
|
927
|
+
if (this.simbolos[this.atual].tipo === delegua_2.default.MULTIPLICACAO) {
|
|
928
|
+
this.consumir(delegua_2.default.MULTIPLICACAO, null);
|
|
924
929
|
parametro.abrangencia = 'multiplo';
|
|
925
930
|
}
|
|
926
931
|
else {
|
|
927
932
|
parametro.abrangencia = 'padrao';
|
|
928
933
|
}
|
|
929
|
-
parametro.nome = this.consumir(
|
|
930
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
934
|
+
parametro.nome = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome do parâmetro.');
|
|
935
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.IGUAL)) {
|
|
931
936
|
parametro.valorPadrao = this.primario();
|
|
932
937
|
}
|
|
933
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
938
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
934
939
|
let tipoDadoParametro = this.verificarDefinicaoTipoAtual();
|
|
935
940
|
parametro.tipoDado = {
|
|
936
941
|
nome: this.simbolos[this.atual - 2].lexema,
|
|
@@ -942,43 +947,43 @@ class AvaliadorSintatico {
|
|
|
942
947
|
parametros.push(parametro);
|
|
943
948
|
if (parametro.abrangencia === 'multiplo')
|
|
944
949
|
break;
|
|
945
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
950
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_2.default.VIRGULA));
|
|
946
951
|
return parametros;
|
|
947
952
|
}
|
|
948
953
|
corpoDaFuncao(tipo) {
|
|
949
954
|
// O parêntese esquerdo é considerado o símbolo inicial para
|
|
950
955
|
// fins de pragma.
|
|
951
|
-
const parenteseEsquerdo = this.consumir(
|
|
956
|
+
const parenteseEsquerdo = this.consumir(delegua_2.default.PARENTESE_ESQUERDO, `Esperado '(' após o nome ${tipo}.`);
|
|
952
957
|
let parametros = [];
|
|
953
|
-
if (!this.verificarTipoSimboloAtual(
|
|
958
|
+
if (!this.verificarTipoSimboloAtual(delegua_2.default.PARENTESE_DIREITO)) {
|
|
954
959
|
parametros = this.logicaComumParametros();
|
|
955
960
|
}
|
|
956
|
-
this.consumir(
|
|
961
|
+
this.consumir(delegua_2.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
957
962
|
let tipoRetorno = null;
|
|
958
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
963
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.DOIS_PONTOS)) {
|
|
959
964
|
tipoRetorno = this.verificarDefinicaoTipoAtual();
|
|
960
965
|
this.avancarEDevolverAnterior();
|
|
961
966
|
}
|
|
962
|
-
this.consumir(
|
|
967
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, `Esperado '{' antes do escopo do ${tipo}.`);
|
|
963
968
|
const corpo = this.blocoEscopo();
|
|
964
969
|
return new construtos_1.FuncaoConstruto(this.hashArquivo, Number(parenteseEsquerdo.linha), parametros, corpo, tipoRetorno);
|
|
965
970
|
}
|
|
966
971
|
declaracaoDeClasse() {
|
|
967
|
-
const simbolo = this.consumir(
|
|
972
|
+
const simbolo = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
968
973
|
const pilhaDecoradoresClasse = this.pilhaDecoradores;
|
|
969
974
|
let superClasse = null;
|
|
970
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
971
|
-
this.consumir(
|
|
975
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.HERDA)) {
|
|
976
|
+
this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da Superclasse.');
|
|
972
977
|
superClasse = new construtos_1.Variavel(this.hashArquivo, this.simbolos[this.atual - 1]);
|
|
973
978
|
}
|
|
974
|
-
this.consumir(
|
|
979
|
+
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo da classe.");
|
|
975
980
|
this.pilhaDecoradores = [];
|
|
976
981
|
const metodos = [];
|
|
977
982
|
const propriedades = [];
|
|
978
|
-
while (!this.verificarTipoSimboloAtual(
|
|
983
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) && !this.estaNoFinal()) {
|
|
979
984
|
// Se o símbolo atual é arroba, é um decorador.
|
|
980
985
|
// Caso contrário, verificamos o próximo símbolo.
|
|
981
|
-
if (this.simbolos[this.atual].tipo ===
|
|
986
|
+
if (this.simbolos[this.atual].tipo === delegua_2.default.ARROBA) {
|
|
982
987
|
this.resolverDecorador();
|
|
983
988
|
continue;
|
|
984
989
|
}
|
|
@@ -986,15 +991,15 @@ class AvaliadorSintatico {
|
|
|
986
991
|
// Caso contrário, é uma propriedade.
|
|
987
992
|
const proximoSimbolo = this.simbolos[this.atual + 1];
|
|
988
993
|
switch (proximoSimbolo.tipo) {
|
|
989
|
-
case
|
|
994
|
+
case delegua_2.default.PARENTESE_ESQUERDO:
|
|
990
995
|
metodos.push(this.funcao('método'));
|
|
991
996
|
this.pilhaDecoradores = [];
|
|
992
997
|
break;
|
|
993
|
-
case
|
|
994
|
-
const nomePropriedade = this.consumir(
|
|
995
|
-
this.consumir(
|
|
998
|
+
case delegua_2.default.DOIS_PONTOS:
|
|
999
|
+
const nomePropriedade = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado identificador para nome de propriedade.');
|
|
1000
|
+
this.consumir(delegua_2.default.DOIS_PONTOS, 'Esperado dois-pontos após nome de propriedade.');
|
|
996
1001
|
const tipoPropriedade = this.avancarEDevolverAnterior();
|
|
997
|
-
this.verificarSeSimboloAtualEIgualA(
|
|
1002
|
+
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
998
1003
|
propriedades.push(new declaracoes_1.PropriedadeClasse(nomePropriedade, tipoPropriedade.lexema, this.pilhaDecoradores));
|
|
999
1004
|
this.pilhaDecoradores = [];
|
|
1000
1005
|
break;
|
|
@@ -1002,7 +1007,7 @@ class AvaliadorSintatico {
|
|
|
1002
1007
|
throw this.erro(this.simbolos[this.atual], 'Esperado definição de método ou propriedade.');
|
|
1003
1008
|
}
|
|
1004
1009
|
}
|
|
1005
|
-
this.consumir(
|
|
1010
|
+
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' após o escopo da classe.");
|
|
1006
1011
|
return new declaracoes_1.Classe(simbolo, superClasse, metodos, propriedades, pilhaDecoradoresClasse);
|
|
1007
1012
|
}
|
|
1008
1013
|
/**
|
|
@@ -1015,13 +1020,13 @@ class AvaliadorSintatico {
|
|
|
1015
1020
|
*/
|
|
1016
1021
|
resolverDeclaracaoForaDeBloco() {
|
|
1017
1022
|
try {
|
|
1018
|
-
if ((this.verificarTipoSimboloAtual(
|
|
1019
|
-
this.verificarTipoSimboloAtual(
|
|
1020
|
-
this.verificarTipoProximoSimbolo(
|
|
1023
|
+
if ((this.verificarTipoSimboloAtual(delegua_2.default.FUNCAO) ||
|
|
1024
|
+
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO)) &&
|
|
1025
|
+
this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
1021
1026
|
this.avancarEDevolverAnterior();
|
|
1022
1027
|
return this.funcao('funcao');
|
|
1023
1028
|
}
|
|
1024
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
1029
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.CLASSE)) {
|
|
1025
1030
|
return this.declaracaoDeClasse();
|
|
1026
1031
|
}
|
|
1027
1032
|
return this.resolverDeclaracao();
|
|
@@ -1042,15 +1047,15 @@ class AvaliadorSintatico {
|
|
|
1042
1047
|
while (!this.estaNoFinal()) {
|
|
1043
1048
|
const tipoSimboloAtual = this.simbolos[this.atual - 1].tipo;
|
|
1044
1049
|
switch (tipoSimboloAtual) {
|
|
1045
|
-
case
|
|
1046
|
-
case
|
|
1047
|
-
case
|
|
1048
|
-
case
|
|
1049
|
-
case
|
|
1050
|
-
case
|
|
1051
|
-
case
|
|
1052
|
-
case
|
|
1053
|
-
case
|
|
1050
|
+
case delegua_2.default.CLASSE:
|
|
1051
|
+
case delegua_2.default.FUNCAO:
|
|
1052
|
+
case delegua_2.default.FUNÇÃO:
|
|
1053
|
+
case delegua_2.default.VARIAVEL:
|
|
1054
|
+
case delegua_2.default.PARA:
|
|
1055
|
+
case delegua_2.default.SE:
|
|
1056
|
+
case delegua_2.default.ENQUANTO:
|
|
1057
|
+
case delegua_2.default.ESCREVA:
|
|
1058
|
+
case delegua_2.default.RETORNA:
|
|
1054
1059
|
return;
|
|
1055
1060
|
}
|
|
1056
1061
|
this.avancarEDevolverAnterior();
|