@designliquido/delegua 0.2.4 → 0.2.7

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.
Files changed (83) hide show
  1. package/bin/package.json +4 -3
  2. package/fontes/avaliador-sintatico/avaliador-sintatico.d.ts +67 -0
  3. package/fontes/avaliador-sintatico/avaliador-sintatico.js +663 -0
  4. package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -0
  5. package/fontes/avaliador-sintatico/dialetos/{egua-classico.d.ts → avaliador-sintatico-egua-classico.d.ts} +2 -1
  6. package/fontes/avaliador-sintatico/dialetos/{egua-classico.js → avaliador-sintatico-egua-classico.js} +9 -9
  7. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -0
  8. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.d.ts +80 -0
  9. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +708 -0
  10. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -0
  11. package/fontes/avaliador-sintatico/dialetos/index.d.ts +1 -1
  12. package/fontes/avaliador-sintatico/dialetos/index.js +1 -1
  13. package/fontes/avaliador-sintatico/dialetos/index.js.map +1 -1
  14. package/fontes/avaliador-sintatico/index.d.ts +2 -66
  15. package/fontes/avaliador-sintatico/index.js +15 -659
  16. package/fontes/avaliador-sintatico/index.js.map +1 -1
  17. package/fontes/delegua.d.ts +4 -1
  18. package/fontes/delegua.js +26 -18
  19. package/fontes/delegua.js.map +1 -1
  20. package/fontes/interfaces/avaliador-sintatico-interface.d.ts +4 -3
  21. package/fontes/interfaces/lexador-interface.d.ts +1 -1
  22. package/fontes/interpretador/dialetos/egua-classico.js +1 -1
  23. package/fontes/interpretador/dialetos/egua-classico.js.map +1 -1
  24. package/fontes/interpretador/index.d.ts +3 -66
  25. package/fontes/interpretador/index.js +5 -685
  26. package/fontes/interpretador/index.js.map +1 -1
  27. package/fontes/interpretador/interpretador.d.ts +66 -0
  28. package/fontes/interpretador/interpretador.js +700 -0
  29. package/fontes/interpretador/interpretador.js.map +1 -0
  30. package/fontes/lexador/dialetos/index.d.ts +1 -1
  31. package/fontes/lexador/dialetos/index.js +1 -1
  32. package/fontes/lexador/dialetos/index.js.map +1 -1
  33. package/fontes/lexador/dialetos/{egua-classico.d.ts → lexador-egua-classico.d.ts} +2 -2
  34. package/fontes/lexador/dialetos/{egua-classico.js → lexador-egua-classico.js} +8 -49
  35. package/fontes/lexador/dialetos/lexador-egua-classico.js.map +1 -0
  36. package/fontes/lexador/dialetos/lexador-eguap.d.ts +51 -0
  37. package/fontes/lexador/dialetos/lexador-eguap.js +395 -0
  38. package/fontes/lexador/dialetos/lexador-eguap.js.map +1 -0
  39. package/fontes/lexador/dialetos/pragma.d.ts +8 -0
  40. package/fontes/lexador/dialetos/pragma.js +3 -0
  41. package/fontes/lexador/dialetos/pragma.js.map +1 -0
  42. package/fontes/lexador/dialetos/tipos-de-simbolos-eguap.d.ts +72 -0
  43. package/fontes/lexador/dialetos/tipos-de-simbolos-eguap.js +74 -0
  44. package/fontes/lexador/dialetos/tipos-de-simbolos-eguap.js.map +1 -0
  45. package/fontes/lexador/index.d.ts +2 -43
  46. package/fontes/lexador/index.js +15 -412
  47. package/fontes/lexador/index.js.map +1 -1
  48. package/fontes/lexador/lexador.d.ts +43 -0
  49. package/fontes/lexador/lexador.js +375 -0
  50. package/fontes/lexador/lexador.js.map +1 -0
  51. package/fontes/lexador/palavras-reservadas.d.ts +35 -0
  52. package/fontes/lexador/palavras-reservadas.js +41 -0
  53. package/fontes/lexador/palavras-reservadas.js.map +1 -0
  54. package/fontes/lexador/retorno-lexador.d.ts +4 -0
  55. package/fontes/lexador/simbolo.d.ts +9 -0
  56. package/fontes/lexador/simbolo.js +17 -0
  57. package/fontes/lexador/simbolo.js.map +1 -0
  58. package/fontes/lexador/tipos-de-simbolos.d.ts +72 -0
  59. package/fontes/lexador/tipos-de-simbolos.js +74 -0
  60. package/fontes/lexador/tipos-de-simbolos.js.map +1 -0
  61. package/fontes/tipos-de-simbolos.d.ts +1 -0
  62. package/fontes/tipos-de-simbolos.js +1 -0
  63. package/fontes/tipos-de-simbolos.js.map +1 -1
  64. package/package.json +4 -3
  65. package/testes/avaliador-sintatico.test.js +2 -2
  66. package/testes/avaliador-sintatico.test.js.map +1 -1
  67. package/testes/biblioteca-global.test.js +14 -14
  68. package/testes/biblioteca-global.test.js.map +1 -1
  69. package/testes/egua-classico/avaliador-sintatico.test.js +2 -2
  70. package/testes/egua-classico/avaliador-sintatico.test.js.map +1 -1
  71. package/testes/egua-classico/interpretador.test.js +20 -20
  72. package/testes/egua-classico/interpretador.test.js.map +1 -1
  73. package/testes/egua-classico/resolvedor.test.js +1 -1
  74. package/testes/egua-classico/resolvedor.test.js.map +1 -1
  75. package/testes/eguap/lexador.test.d.ts +1 -0
  76. package/testes/eguap/lexador.test.js +53 -0
  77. package/testes/eguap/lexador.test.js.map +1 -0
  78. package/testes/interpretador.test.js +20 -20
  79. package/testes/interpretador.test.js.map +1 -1
  80. package/testes/resolvedor.test.js +1 -1
  81. package/testes/resolvedor.test.js.map +1 -1
  82. package/fontes/avaliador-sintatico/dialetos/egua-classico.js.map +0 -1
  83. package/fontes/lexador/dialetos/egua-classico.js.map +0 -1
@@ -1,663 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AvaliadorSintatico = void 0;
7
- var tipos_de_simbolos_1 = __importDefault(require("../tipos-de-simbolos"));
8
- var perf_hooks_1 = require("perf_hooks");
9
- var construtos_1 = require("../construtos");
10
- var erro_avaliador_sintatico_1 = require("./erro-avaliador-sintatico");
11
- var declaracoes_1 = require("../declaracoes");
12
- /**
13
- * O avaliador sintático (Parser) é responsável por transformar os símbolos do Lexador em estruturas de alto nível.
14
- * Essas estruturas de alto nível são as partes que executam lógica de programação de fato.
15
- * Há dois grupos de estruturas de alto nível: Construtos e Declarações.
16
- */
17
- var AvaliadorSintatico = /** @class */ (function () {
18
- function AvaliadorSintatico(performance) {
19
- if (performance === void 0) { performance = false; }
20
- this.atual = 0;
21
- this.ciclos = 0;
22
- this.erros = [];
23
- this.performance = performance;
24
- }
25
- AvaliadorSintatico.prototype.sincronizar = function () {
26
- this.avancarEDevolverAnterior();
27
- while (!this.estaNoFinal()) {
28
- if (this.simboloAnterior().tipo === tipos_de_simbolos_1.default.PONTO_E_VIRGULA)
29
- return;
30
- switch (this.simboloAtual().tipo) {
31
- case tipos_de_simbolos_1.default.CLASSE:
32
- case tipos_de_simbolos_1.default.FUNCAO:
33
- case tipos_de_simbolos_1.default.FUNÇÃO:
34
- case tipos_de_simbolos_1.default.VARIAVEL:
35
- case tipos_de_simbolos_1.default.PARA:
36
- case tipos_de_simbolos_1.default.SE:
37
- case tipos_de_simbolos_1.default.ENQUANTO:
38
- case tipos_de_simbolos_1.default.ESCREVA:
39
- case tipos_de_simbolos_1.default.RETORNA:
40
- return;
41
- }
42
- this.avancarEDevolverAnterior();
43
- }
44
- };
45
- AvaliadorSintatico.prototype.erro = function (simbolo, mensagemDeErro) {
46
- var excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(simbolo, mensagemDeErro);
47
- this.erros.push(excecao);
48
- return excecao;
49
- };
50
- AvaliadorSintatico.prototype.consumir = function (tipo, mensagemDeErro) {
51
- if (this.verificarTipoSimboloAtual(tipo))
52
- return this.avancarEDevolverAnterior();
53
- throw this.erro(this.simboloAtual(), mensagemDeErro);
54
- };
55
- AvaliadorSintatico.prototype.verificarTipoSimboloAtual = function (tipo) {
56
- if (this.estaNoFinal())
57
- return false;
58
- return this.simboloAtual().tipo === tipo;
59
- };
60
- AvaliadorSintatico.prototype.verificarTipoProximoSimbolo = function (tipo) {
61
- if (this.estaNoFinal())
62
- return false;
63
- return this.simbolos[this.atual + 1].tipo === tipo;
64
- };
65
- AvaliadorSintatico.prototype.simboloAtual = function () {
66
- return this.simbolos[this.atual];
67
- };
68
- AvaliadorSintatico.prototype.simboloAnterior = function () {
69
- return this.simbolos[this.atual - 1];
70
- };
71
- AvaliadorSintatico.prototype.simboloNaPosicao = function (posicao) {
72
- return this.simbolos[this.atual + posicao];
73
- };
74
- AvaliadorSintatico.prototype.estaNoFinal = function () {
75
- var simboloAtual = this.simboloAtual();
76
- if (simboloAtual &&
77
- simboloAtual.tipo === tipos_de_simbolos_1.default.PONTO_E_VIRGULA) {
78
- return true;
79
- }
80
- return this.atual === this.simbolos.length;
81
- };
82
- AvaliadorSintatico.prototype.avancarEDevolverAnterior = function () {
83
- if (!this.estaNoFinal())
84
- this.atual += 1;
85
- return this.simboloAnterior();
86
- };
87
- AvaliadorSintatico.prototype.verificarSeSimboloAtualEIgualA = function () {
88
- var argumentos = [];
89
- for (var _i = 0; _i < arguments.length; _i++) {
90
- argumentos[_i] = arguments[_i];
91
- }
92
- for (var i = 0; i < argumentos.length; i++) {
93
- var tipoAtual = argumentos[i];
94
- if (this.verificarTipoSimboloAtual(tipoAtual)) {
95
- this.avancarEDevolverAnterior();
96
- return true;
97
- }
98
- }
99
- return false;
100
- };
101
- AvaliadorSintatico.prototype.primario = function () {
102
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.SUPER)) {
103
- var palavraChave = this.simboloAnterior();
104
- this.consumir(tipos_de_simbolos_1.default.PONTO, "Esperado '.' após 'super'.");
105
- var metodo = this.consumir(tipos_de_simbolos_1.default.IDENTIFICADOR, 'Esperado nome do método da SuperClasse.');
106
- return new construtos_1.Super(0, palavraChave, metodo);
107
- }
108
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.COLCHETE_ESQUERDO)) {
109
- var valores = [];
110
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.COLCHETE_DIREITO)) {
111
- return new construtos_1.Vetor(0, []);
112
- }
113
- while (!this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.COLCHETE_DIREITO)) {
114
- var valor = this.atribuir();
115
- valores.push(valor);
116
- if (this.simboloAtual().tipo !==
117
- tipos_de_simbolos_1.default.COLCHETE_DIREITO) {
118
- this.consumir(tipos_de_simbolos_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
119
- }
120
- }
121
- return new construtos_1.Vetor(0, valores);
122
- }
123
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CHAVE_ESQUERDA)) {
124
- var chaves = [];
125
- var valores = [];
126
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CHAVE_DIREITA)) {
127
- return new construtos_1.Dicionario(0, [], []);
128
- }
129
- while (!this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CHAVE_DIREITA)) {
130
- var chave = this.atribuir();
131
- this.consumir(tipos_de_simbolos_1.default.DOIS_PONTOS, "Esperado ':' entre chave e valor.");
132
- var valor = this.atribuir();
133
- chaves.push(chave);
134
- valores.push(valor);
135
- if (this.simboloAtual().tipo !== tipos_de_simbolos_1.default.CHAVE_DIREITA) {
136
- this.consumir(tipos_de_simbolos_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
137
- }
138
- }
139
- return new construtos_1.Dicionario(0, chaves, valores);
140
- }
141
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.FUNÇÃO))
142
- return this.corpoDaFuncao('função');
143
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.FUNCAO))
144
- return this.corpoDaFuncao('funcao');
145
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.FALSO))
146
- return new construtos_1.Literal(0, false);
147
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.VERDADEIRO))
148
- return new construtos_1.Literal(0, true);
149
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.NULO))
150
- return new construtos_1.Literal(0, null);
151
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.ISTO))
152
- return new construtos_1.Isto(0, this.simboloAnterior());
153
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.NUMERO, tipos_de_simbolos_1.default.TEXTO)) {
154
- var simboloAnterior = this.simboloAnterior();
155
- return new construtos_1.Literal(Number(simboloAnterior.linha), simboloAnterior.literal);
156
- }
157
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.IDENTIFICADOR)) {
158
- return new construtos_1.Variavel(this.simboloAnterior());
159
- }
160
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO)) {
161
- var expr = this.expressao();
162
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
163
- return new construtos_1.Agrupamento(0, expr);
164
- }
165
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.IMPORTAR))
166
- return this.declaracaoImportar();
167
- throw this.erro(this.simboloAtual(), 'Esperado expressão.');
168
- };
169
- AvaliadorSintatico.prototype.finalizarChamada = function (entidadeChamada) {
170
- var argumentos = [];
171
- if (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.PARENTESE_DIREITO)) {
172
- do {
173
- if (argumentos.length >= 255) {
174
- throw this.erro(this.simboloAtual(), 'Não pode haver mais de 255 argumentos.');
175
- }
176
- argumentos.push(this.expressao());
177
- } while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.VIRGULA));
178
- }
179
- var parenteseDireito = this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos.");
180
- return new construtos_1.Chamada(entidadeChamada, parenteseDireito, argumentos);
181
- };
182
- AvaliadorSintatico.prototype.chamar = function () {
183
- var expressao = this.primario();
184
- while (true) {
185
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO)) {
186
- expressao = this.finalizarChamada(expressao);
187
- }
188
- else if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PONTO)) {
189
- var nome = this.consumir(tipos_de_simbolos_1.default.IDENTIFICADOR, "Esperado nome do método após '.'.");
190
- expressao = new construtos_1.AcessoMetodo(expressao, nome);
191
- }
192
- else if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.COLCHETE_ESQUERDO)) {
193
- var indice = this.expressao();
194
- var simboloFechamento = this.consumir(tipos_de_simbolos_1.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
195
- expressao = new construtos_1.AcessoIndiceVariavel(expressao, indice, simboloFechamento);
196
- }
197
- else {
198
- break;
199
- }
200
- }
201
- return expressao;
202
- };
203
- AvaliadorSintatico.prototype.unario = function () {
204
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.NEGACAO, tipos_de_simbolos_1.default.SUBTRACAO, tipos_de_simbolos_1.default.BIT_NOT)) {
205
- var operador = this.simboloAnterior();
206
- var direito = this.unario();
207
- return new construtos_1.Unario(operador, direito);
208
- }
209
- return this.chamar();
210
- };
211
- AvaliadorSintatico.prototype.exponenciacao = function () {
212
- var expressao = this.unario();
213
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.EXPONENCIACAO)) {
214
- var operador = this.simboloAnterior();
215
- var direito = this.unario();
216
- expressao = new construtos_1.Binario(expressao, operador, direito);
217
- }
218
- return expressao;
219
- };
220
- AvaliadorSintatico.prototype.multiplicar = function () {
221
- var expressao = this.exponenciacao();
222
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.DIVISAO, tipos_de_simbolos_1.default.MULTIPLICACAO, tipos_de_simbolos_1.default.MODULO)) {
223
- var operador = this.simboloAnterior();
224
- var direito = this.exponenciacao();
225
- expressao = new construtos_1.Binario(expressao, operador, direito);
226
- }
227
- return expressao;
228
- };
229
- AvaliadorSintatico.prototype.adicionar = function () {
230
- var expressao = this.multiplicar();
231
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.SUBTRACAO, tipos_de_simbolos_1.default.ADICAO)) {
232
- var operador = this.simboloAnterior();
233
- var direito = this.multiplicar();
234
- expressao = new construtos_1.Binario(expressao, operador, direito);
235
- }
236
- return expressao;
237
- };
238
- AvaliadorSintatico.prototype.bitFill = function () {
239
- var expressao = this.adicionar();
240
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.MENOR_MENOR, tipos_de_simbolos_1.default.MAIOR_MAIOR)) {
241
- var operador = this.simboloAnterior();
242
- var direito = this.adicionar();
243
- expressao = new construtos_1.Binario(expressao, operador, direito);
244
- }
245
- return expressao;
246
- };
247
- AvaliadorSintatico.prototype.bitE = function () {
248
- var expressao = this.bitFill();
249
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.BIT_AND)) {
250
- var operador = this.simboloAnterior();
251
- var direito = this.bitFill();
252
- expressao = new construtos_1.Binario(expressao, operador, direito);
253
- }
254
- return expressao;
255
- };
256
- AvaliadorSintatico.prototype.bitOu = function () {
257
- var expressao = this.bitE();
258
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.BIT_OR, tipos_de_simbolos_1.default.BIT_XOR)) {
259
- var operador = this.simboloAnterior();
260
- var direito = this.bitE();
261
- expressao = new construtos_1.Binario(expressao, operador, direito);
262
- }
263
- return expressao;
264
- };
265
- AvaliadorSintatico.prototype.comparar = function () {
266
- var expressao = this.bitOu();
267
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.MAIOR, tipos_de_simbolos_1.default.MAIOR_IGUAL, tipos_de_simbolos_1.default.MENOR, tipos_de_simbolos_1.default.MENOR_IGUAL)) {
268
- var operador = this.simboloAnterior();
269
- var direito = this.bitOu();
270
- expressao = new construtos_1.Binario(expressao, operador, direito);
271
- }
272
- return expressao;
273
- };
274
- AvaliadorSintatico.prototype.comparacaoIgualdade = function () {
275
- var expressao = this.comparar();
276
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.DIFERENTE, tipos_de_simbolos_1.default.IGUAL_IGUAL)) {
277
- var operador = this.simboloAnterior();
278
- var direito = this.comparar();
279
- expressao = new construtos_1.Binario(expressao, operador, direito);
280
- }
281
- return expressao;
282
- };
283
- AvaliadorSintatico.prototype.em = function () {
284
- var expressao = this.comparacaoIgualdade();
285
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.EM)) {
286
- var operador = this.simboloAnterior();
287
- var direito = this.comparacaoIgualdade();
288
- expressao = new construtos_1.Logico(expressao, operador, direito);
289
- }
290
- return expressao;
291
- };
292
- AvaliadorSintatico.prototype.e = function () {
293
- var expressao = this.em();
294
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.E)) {
295
- var operador = this.simboloAnterior();
296
- var direito = this.em();
297
- expressao = new construtos_1.Logico(expressao, operador, direito);
298
- }
299
- return expressao;
300
- };
301
- AvaliadorSintatico.prototype.ou = function () {
302
- var expressao = this.e();
303
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.OU)) {
304
- var operador = this.simboloAnterior();
305
- var direito = this.e();
306
- expressao = new construtos_1.Logico(expressao, operador, direito);
307
- }
308
- return expressao;
309
- };
310
- AvaliadorSintatico.prototype.atribuir = function () {
311
- var expressao = this.ou();
312
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.IGUAL) ||
313
- this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.MAIS_IGUAL)) {
314
- var igual = this.simboloAnterior();
315
- var valor = this.atribuir();
316
- if (expressao instanceof construtos_1.Variavel) {
317
- var simbolo = expressao.simbolo;
318
- return new construtos_1.Atribuir(simbolo, valor);
319
- }
320
- else if (expressao instanceof construtos_1.AcessoMetodo) {
321
- var get = expressao;
322
- return new construtos_1.Conjunto(0, get.objeto, get.simbolo, valor);
323
- }
324
- else if (expressao instanceof construtos_1.AcessoIndiceVariavel) {
325
- return new construtos_1.AtribuicaoSobrescrita(0, expressao.entidadeChamada, expressao.indice, valor);
326
- }
327
- this.erro(igual, 'Tarefa de atribuição inválida');
328
- }
329
- return expressao;
330
- };
331
- AvaliadorSintatico.prototype.expressao = function () {
332
- return this.atribuir();
333
- };
334
- AvaliadorSintatico.prototype.declaracaoEscreva = function () {
335
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em escreva.");
336
- var simbolo = this.expressao();
337
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em escreva.");
338
- return new declaracoes_1.Escreva(simbolo);
339
- };
340
- AvaliadorSintatico.prototype.declaracaoExpressao = function () {
341
- var expressao = this.expressao();
342
- return new declaracoes_1.Expressao(expressao);
343
- };
344
- AvaliadorSintatico.prototype.blocoEscopo = function () {
345
- var declaracoes = [];
346
- while (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.CHAVE_DIREITA) &&
347
- !this.estaNoFinal()) {
348
- declaracoes.push(this.declaracao());
349
- }
350
- this.consumir(tipos_de_simbolos_1.default.CHAVE_DIREITA, "Esperado '}' após o bloco.");
351
- return declaracoes;
352
- };
353
- AvaliadorSintatico.prototype.declaracaoSe = function () {
354
- var simboloSe = this.simboloAnterior();
355
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'se'.");
356
- var condicao = this.expressao();
357
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após condição do se.");
358
- var caminhoEntao = this.resolverDeclaracao();
359
- var caminhosSeSenao = [];
360
- while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.SENAOSE, tipos_de_simbolos_1.default.SENÃOSE)) {
361
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'senaose' ou 'senãose'.");
362
- var condicaoSeSenao = this.expressao();
363
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após codição do 'senaose' ou 'senãose'.");
364
- var caminho = this.resolverDeclaracao();
365
- caminhosSeSenao.push({
366
- condicao: condicaoSeSenao,
367
- caminho: caminho,
368
- });
369
- }
370
- var caminhoSenao = null;
371
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.SENAO, tipos_de_simbolos_1.default.SENÃO)) {
372
- caminhoSenao = this.resolverDeclaracao();
373
- }
374
- return new declaracoes_1.Se(Number(simboloSe.linha), condicao, caminhoEntao, caminhosSeSenao, caminhoSenao);
375
- };
376
- AvaliadorSintatico.prototype.declaracaoEnquanto = function () {
377
- try {
378
- this.ciclos += 1;
379
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'enquanto'.");
380
- var condicao = this.expressao();
381
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após condicional.");
382
- var corpo = this.resolverDeclaracao();
383
- return new declaracoes_1.Enquanto(condicao, corpo);
384
- }
385
- finally {
386
- this.ciclos -= 1;
387
- }
388
- };
389
- AvaliadorSintatico.prototype.declaracaoPara = function () {
390
- try {
391
- var simboloPara = this.simboloAnterior();
392
- this.ciclos += 1;
393
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'para'.");
394
- var inicializador = void 0;
395
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PONTO_E_VIRGULA)) {
396
- inicializador = null;
397
- }
398
- else if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.VARIAVEL)) {
399
- inicializador = this.declaracaoDeVariavel();
400
- }
401
- else {
402
- inicializador = this.declaracaoExpressao();
403
- }
404
- var condicao = null;
405
- if (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.PONTO_E_VIRGULA)) {
406
- condicao = this.expressao();
407
- }
408
- var incrementar = null;
409
- if (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.PARENTESE_DIREITO)) {
410
- incrementar = this.expressao();
411
- }
412
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após cláusulas");
413
- var corpo = this.resolverDeclaracao();
414
- return new declaracoes_1.Para(Number(simboloPara.linha), inicializador, condicao, incrementar, corpo);
415
- }
416
- finally {
417
- this.ciclos -= 1;
418
- }
419
- };
420
- AvaliadorSintatico.prototype.declaracaoSustar = function () {
421
- if (this.ciclos < 1) {
422
- this.erro(this.simboloAnterior(), "'sustar' ou 'pausa' deve estar dentro de um loop.");
423
- }
424
- return new declaracoes_1.Sustar();
425
- };
426
- AvaliadorSintatico.prototype.declaracaoContinua = function () {
427
- if (this.ciclos < 1) {
428
- this.erro(this.simboloAnterior(), "'continua' precisa estar em um laço de repetição.");
429
- }
430
- return new declaracoes_1.Continua();
431
- };
432
- AvaliadorSintatico.prototype.declaracaoRetorna = function () {
433
- var palavraChave = this.simboloAnterior();
434
- var valor = null;
435
- if (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.PONTO_E_VIRGULA)) {
436
- valor = this.expressao();
437
- }
438
- return new declaracoes_1.Retorna(palavraChave, valor);
439
- };
440
- AvaliadorSintatico.prototype.declaracaoEscolha = function () {
441
- try {
442
- this.ciclos += 1;
443
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '{' após 'escolha'.");
444
- var condicao = this.expressao();
445
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado '}' após a condição de 'escolha'.");
446
- this.consumir(tipos_de_simbolos_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo do 'escolha'.");
447
- var caminhos = [];
448
- var caminhoPadrao = null;
449
- while (!this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CHAVE_DIREITA) &&
450
- !this.estaNoFinal()) {
451
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CASO)) {
452
- var branchConditions = [this.expressao()];
453
- this.consumir(tipos_de_simbolos_1.default.DOIS_PONTOS, "Esperado ':' após o 'caso'.");
454
- while (this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.CASO)) {
455
- this.consumir(tipos_de_simbolos_1.default.CASO, null);
456
- branchConditions.push(this.expressao());
457
- this.consumir(tipos_de_simbolos_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'caso'.");
458
- }
459
- var declaracoes = [];
460
- do {
461
- declaracoes.push(this.resolverDeclaracao());
462
- } while (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.CASO) &&
463
- !this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.PADRAO) &&
464
- !this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.CHAVE_DIREITA));
465
- caminhos.push({
466
- conditions: branchConditions,
467
- declaracoes: declaracoes,
468
- });
469
- }
470
- else if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PADRAO)) {
471
- if (caminhoPadrao !== null) {
472
- var excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.simboloAtual(), "Você só pode ter um 'padrao' em cada declaração de 'escolha'.");
473
- this.erros.push(excecao);
474
- throw excecao;
475
- }
476
- this.consumir(tipos_de_simbolos_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'padrao'.");
477
- var declaracoes = [];
478
- do {
479
- declaracoes.push(this.resolverDeclaracao());
480
- } while (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.CASO) &&
481
- !this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.PADRAO) &&
482
- !this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.CHAVE_DIREITA));
483
- caminhoPadrao = {
484
- declaracoes: declaracoes,
485
- };
486
- }
487
- }
488
- return new declaracoes_1.Escolha(condicao, caminhos, caminhoPadrao);
489
- }
490
- finally {
491
- this.ciclos -= 1;
492
- }
493
- };
494
- AvaliadorSintatico.prototype.declaracaoImportar = function () {
495
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
496
- var caminho = this.expressao();
497
- var simboloFechamento = this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
498
- return new declaracoes_1.Importar(caminho, simboloFechamento);
499
- };
500
- AvaliadorSintatico.prototype.declaracaoTente = function () {
501
- this.consumir(tipos_de_simbolos_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'tente'.");
502
- var blocoTente = this.blocoEscopo();
503
- var blocoPegue = null;
504
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PEGUE)) {
505
- this.consumir(tipos_de_simbolos_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
506
- blocoPegue = this.blocoEscopo();
507
- }
508
- var blocoSenao = null;
509
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.SENAO, tipos_de_simbolos_1.default.SENÃO)) {
510
- this.consumir(tipos_de_simbolos_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
511
- blocoSenao = this.blocoEscopo();
512
- }
513
- var blocoFinalmente = null;
514
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.FINALMENTE)) {
515
- this.consumir(tipos_de_simbolos_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
516
- blocoFinalmente = this.blocoEscopo();
517
- }
518
- return new declaracoes_1.Tente(blocoTente, blocoPegue, blocoSenao, blocoFinalmente);
519
- };
520
- AvaliadorSintatico.prototype.declaracaoFazer = function () {
521
- try {
522
- this.ciclos += 1;
523
- var caminhoFazer = this.resolverDeclaracao();
524
- this.consumir(tipos_de_simbolos_1.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo do 'fazer'.");
525
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração 'enquanto'.");
526
- var condicaoEnquanto = this.expressao();
527
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração do 'enquanto'.");
528
- return new declaracoes_1.Fazer(caminhoFazer, condicaoEnquanto);
529
- }
530
- finally {
531
- this.ciclos -= 1;
532
- }
533
- };
534
- AvaliadorSintatico.prototype.resolverDeclaracao = function () {
535
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.FAZER))
536
- return this.declaracaoFazer();
537
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.TENTE))
538
- return this.declaracaoTente();
539
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.ESCOLHA))
540
- return this.declaracaoEscolha();
541
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.RETORNA))
542
- return this.declaracaoRetorna();
543
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CONTINUA))
544
- return this.declaracaoContinua();
545
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PAUSA))
546
- return this.declaracaoSustar();
547
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.PARA))
548
- return this.declaracaoPara();
549
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.ENQUANTO))
550
- return this.declaracaoEnquanto();
551
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.SE))
552
- return this.declaracaoSe();
553
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.ESCREVA))
554
- return this.declaracaoEscreva();
555
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CHAVE_ESQUERDA))
556
- return new declaracoes_1.Bloco(this.blocoEscopo());
557
- return this.declaracaoExpressao();
558
- };
559
- AvaliadorSintatico.prototype.declaracaoDeVariavel = function () {
560
- var simbolo = this.consumir(tipos_de_simbolos_1.default.IDENTIFICADOR, 'Esperado nome de variável.');
561
- var inicializador = null;
562
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.IGUAL) ||
563
- this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.MAIS_IGUAL)) {
564
- inicializador = this.expressao();
565
- }
566
- return new declaracoes_1.Var(simbolo, inicializador);
567
- };
568
- AvaliadorSintatico.prototype.funcao = function (tipo) {
569
- var simbolo = this.consumir(tipos_de_simbolos_1.default.IDENTIFICADOR, "Esperado nome ".concat(tipo, "."));
570
- return new declaracoes_1.Funcao(simbolo, this.corpoDaFuncao(tipo));
571
- };
572
- AvaliadorSintatico.prototype.corpoDaFuncao = function (tipo) {
573
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_ESQUERDO, "Esperado '(' ap\u00F3s o nome ".concat(tipo, "."));
574
- var parametros = [];
575
- if (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.PARENTESE_DIREITO)) {
576
- do {
577
- if (parametros.length >= 255) {
578
- this.erro(this.simboloAtual(), 'Não pode haver mais de 255 parâmetros');
579
- }
580
- var paramObj = {};
581
- if (this.simboloAtual().tipo === tipos_de_simbolos_1.default.MULTIPLICACAO) {
582
- this.consumir(tipos_de_simbolos_1.default.MULTIPLICACAO, null);
583
- paramObj['tipo'] = 'wildcard';
584
- }
585
- else {
586
- paramObj['tipo'] = 'standard';
587
- }
588
- paramObj['nome'] = this.consumir(tipos_de_simbolos_1.default.IDENTIFICADOR, 'Esperado nome do parâmetro.');
589
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.IGUAL)) {
590
- paramObj['default'] = this.primario();
591
- }
592
- parametros.push(paramObj);
593
- if (paramObj['tipo'] === 'wildcard')
594
- break;
595
- } while (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.VIRGULA));
596
- }
597
- this.consumir(tipos_de_simbolos_1.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
598
- this.consumir(tipos_de_simbolos_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo do ".concat(tipo, "."));
599
- var corpo = this.blocoEscopo();
600
- return new construtos_1.Funcao(0, parametros, corpo);
601
- };
602
- AvaliadorSintatico.prototype.declaracaoDeClasse = function () {
603
- var simbolo = this.consumir(tipos_de_simbolos_1.default.IDENTIFICADOR, 'Esperado nome da classe.');
604
- var superClasse = null;
605
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.HERDA)) {
606
- this.consumir(tipos_de_simbolos_1.default.IDENTIFICADOR, 'Esperado nome da SuperClasse.');
607
- superClasse = new construtos_1.Variavel(this.simboloAnterior());
608
- }
609
- this.consumir(tipos_de_simbolos_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo da classe.");
610
- var metodos = [];
611
- while (!this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.CHAVE_DIREITA) &&
612
- !this.estaNoFinal()) {
613
- metodos.push(this.funcao('método'));
614
- }
615
- this.consumir(tipos_de_simbolos_1.default.CHAVE_DIREITA, "Esperado '}' após o escopo da classe.");
616
- return new declaracoes_1.Classe(simbolo, superClasse, metodos);
617
- };
618
- AvaliadorSintatico.prototype.declaracao = function () {
619
- try {
620
- if (this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.FUNÇÃO) &&
621
- this.verificarTipoProximoSimbolo(tipos_de_simbolos_1.default.IDENTIFICADOR)) {
622
- this.consumir(tipos_de_simbolos_1.default.FUNÇÃO, null);
623
- return this.funcao('função');
624
- }
625
- if (this.verificarTipoSimboloAtual(tipos_de_simbolos_1.default.FUNCAO) &&
626
- this.verificarTipoProximoSimbolo(tipos_de_simbolos_1.default.IDENTIFICADOR)) {
627
- this.consumir(tipos_de_simbolos_1.default.FUNCAO, null);
628
- return this.funcao('funcao');
629
- }
630
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.VARIAVEL))
631
- return this.declaracaoDeVariavel();
632
- if (this.verificarSeSimboloAtualEIgualA(tipos_de_simbolos_1.default.CLASSE))
633
- return this.declaracaoDeClasse();
634
- return this.resolverDeclaracao();
635
- }
636
- catch (erro) {
637
- this.sincronizar();
638
- return null;
639
- }
640
- };
641
- AvaliadorSintatico.prototype.analisar = function (simbolos) {
642
- var inicioAnalise = perf_hooks_1.performance.now();
643
- this.erros = [];
644
- this.atual = 0;
645
- this.ciclos = 0;
646
- this.simbolos = simbolos || [];
647
- var declaracoes = [];
648
- while (!this.estaNoFinal()) {
649
- declaracoes.push(this.declaracao());
650
- }
651
- var fimAnalise = perf_hooks_1.performance.now();
652
- if (this.performance) {
653
- console.log("[Avaliador Sint\u00E1tico] Tempo para an\u00E1lise: ".concat(fimAnalise - inicioAnalise, "ms"));
654
- }
655
- return {
656
- declaracoes: declaracoes,
657
- erros: this.erros
658
- };
659
- };
660
- return AvaliadorSintatico;
661
- }());
662
- exports.AvaliadorSintatico = AvaliadorSintatico;
17
+ __exportStar(require("./avaliador-sintatico"), exports);
18
+ __exportStar(require("./erro-avaliador-sintatico"), exports);
663
19
  //# sourceMappingURL=index.js.map