@designliquido/delegua 0.7.6 → 0.8.0
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/bin/package.json +70 -65
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.d.ts +63 -0
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js +180 -0
- package/fontes/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -0
- package/fontes/avaliador-sintatico/avaliador-sintatico.js +188 -188
- package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +34 -32
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +154 -148
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.d.ts +7 -6
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +144 -142
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -1
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.d.ts +48 -0
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js +291 -0
- package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js.map +1 -0
- package/fontes/construtos/construto.d.ts +1 -0
- package/fontes/construtos/literal.d.ts +2 -2
- package/fontes/construtos/literal.js.map +1 -1
- package/fontes/construtos/super.d.ts +4 -4
- package/fontes/construtos/super.js.map +1 -1
- package/fontes/construtos/vetor.d.ts +3 -3
- package/fontes/construtos/vetor.js.map +1 -1
- package/fontes/declaracoes/bloco.d.ts +2 -2
- package/fontes/declaracoes/bloco.js.map +1 -1
- package/fontes/declaracoes/escolha.d.ts +5 -2
- package/fontes/declaracoes/escolha.js +6 -3
- package/fontes/declaracoes/escolha.js.map +1 -1
- package/fontes/declaracoes/escreva.d.ts +3 -3
- package/fontes/declaracoes/escreva.js.map +1 -1
- package/fontes/declaracoes/index.d.ts +1 -0
- package/fontes/declaracoes/index.js +1 -0
- package/fontes/declaracoes/index.js.map +1 -1
- package/fontes/declaracoes/leia.d.ts +12 -0
- package/fontes/declaracoes/leia.js +37 -0
- package/fontes/declaracoes/leia.js.map +1 -0
- package/fontes/declaracoes/var.d.ts +3 -2
- package/fontes/declaracoes/var.js.map +1 -1
- package/fontes/delegua.d.ts +2 -2
- package/fontes/delegua.js +37 -21
- package/fontes/delegua.js.map +1 -1
- package/fontes/interfaces/avaliador-sintatico-interface.d.ts +3 -5
- package/fontes/interfaces/interpretador-interface.d.ts +8 -7
- package/fontes/interfaces/lexador-interface.d.ts +2 -2
- package/fontes/interpretador/dialetos/egua-classico.d.ts +2 -1
- package/fontes/interpretador/dialetos/egua-classico.js +30 -27
- package/fontes/interpretador/dialetos/egua-classico.js.map +1 -1
- package/fontes/interpretador/interpretador.d.ts +9 -3
- package/fontes/interpretador/interpretador.js +38 -30
- package/fontes/interpretador/interpretador.js.map +1 -1
- package/fontes/lexador/dialetos/lexador-egua-classico.js +35 -35
- package/fontes/lexador/dialetos/lexador-egua-classico.js.map +1 -1
- package/fontes/lexador/dialetos/lexador-eguap.js +35 -35
- package/fontes/lexador/dialetos/lexador-eguap.js.map +1 -1
- package/fontes/lexador/dialetos/lexador-visualg.d.ts +16 -0
- package/fontes/lexador/dialetos/lexador-visualg.js +225 -0
- package/fontes/lexador/dialetos/lexador-visualg.js.map +1 -0
- package/fontes/lexador/dialetos/palavras-reservadas/visualg.d.ts +26 -0
- package/fontes/lexador/dialetos/palavras-reservadas/visualg.js +32 -0
- package/fontes/lexador/dialetos/palavras-reservadas/visualg.js.map +1 -0
- package/fontes/lexador/lexador-base-linha-unica.d.ts +33 -0
- package/fontes/lexador/lexador-base-linha-unica.js +92 -0
- package/fontes/lexador/lexador-base-linha-unica.js.map +1 -0
- package/fontes/lexador/lexador.d.ts +3 -3
- package/fontes/lexador/lexador.js +43 -43
- package/fontes/lexador/lexador.js.map +1 -1
- package/fontes/lexador/palavras-reservadas.js +33 -33
- package/fontes/lexador/palavras-reservadas.js.map +1 -1
- package/fontes/tipos/avaliador-sintatico-egua-e-eguap-classico-returno-tipo.d.ts +5 -0
- package/fontes/tipos/avaliador-sintatico-egua-e-eguap-classico-returno-tipo.js +3 -0
- package/fontes/tipos/avaliador-sintatico-egua-e-eguap-classico-returno-tipo.js.map +1 -0
- package/fontes/tipos-de-simbolos/comum.d.ts +18 -0
- package/fontes/tipos-de-simbolos/comum.js +20 -0
- package/fontes/tipos-de-simbolos/comum.js.map +1 -0
- package/fontes/{tipos-de-simbolos.d.ts → tipos-de-simbolos/delegua.d.ts} +0 -0
- package/fontes/{tipos-de-simbolos.js → tipos-de-simbolos/delegua.js} +1 -1
- package/fontes/tipos-de-simbolos/delegua.js.map +1 -0
- package/fontes/{lexador/dialetos/tipos-de-simbolos-eguap.d.ts → tipos-de-simbolos/eguap.d.ts} +0 -0
- package/fontes/{lexador/dialetos/tipos-de-simbolos-eguap.js → tipos-de-simbolos/eguap.js} +1 -1
- package/fontes/tipos-de-simbolos/eguap.js.map +1 -0
- package/fontes/tipos-de-simbolos/visualg.d.ts +47 -0
- package/fontes/tipos-de-simbolos/visualg.js +49 -0
- package/fontes/tipos-de-simbolos/visualg.js.map +1 -0
- package/package.json +70 -65
- package/testes/avaliador-sintatico.test.js.map +1 -1
- package/testes/egua-classico/avaliador-sintatico.test.js +4 -1
- package/testes/egua-classico/avaliador-sintatico.test.js.map +1 -1
- package/testes/lexador.test.js +45 -45
- package/testes/lexador.test.js.map +1 -1
- package/testes/visualg/avaliador-sintatico.test.d.ts +1 -0
- package/testes/visualg/avaliador-sintatico.test.js +113 -0
- package/testes/visualg/avaliador-sintatico.test.js.map +1 -0
- package/testes/visualg/lexador.test.d.ts +1 -0
- package/testes/visualg/lexador.test.js +67 -0
- package/testes/visualg/lexador.test.js.map +1 -0
- package/fontes/lexador/dialetos/tipos-de-simbolos-eguap.js.map +0 -1
- package/fontes/tipos-de-simbolos.js.map +0 -1
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.AvaliadorSintatico = void 0;
|
|
7
|
-
var
|
|
7
|
+
var delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
8
8
|
var browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime"));
|
|
9
9
|
var construtos_1 = require("../construtos");
|
|
10
10
|
var erro_avaliador_sintatico_1 = require("./erro-avaliador-sintatico");
|
|
@@ -31,12 +31,12 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
31
31
|
AvaliadorSintatico.prototype.consumir = function (tipo, mensagemDeErro) {
|
|
32
32
|
if (this.verificarTipoSimboloAtual(tipo))
|
|
33
33
|
return this.avancarEDevolverAnterior();
|
|
34
|
-
throw this.erro(this.
|
|
34
|
+
throw this.erro(this.simbolos[this.atual], mensagemDeErro);
|
|
35
35
|
};
|
|
36
36
|
AvaliadorSintatico.prototype.verificarTipoSimboloAtual = function (tipo) {
|
|
37
37
|
if (this.estaNoFinal())
|
|
38
38
|
return false;
|
|
39
|
-
return this.
|
|
39
|
+
return this.simbolos[this.atual].tipo === tipo;
|
|
40
40
|
};
|
|
41
41
|
AvaliadorSintatico.prototype.verificarTipoProximoSimbolo = function (tipo) {
|
|
42
42
|
return this.simbolos[this.atual + 1].tipo === tipo;
|
|
@@ -53,7 +53,7 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
53
53
|
AvaliadorSintatico.prototype.avancarEDevolverAnterior = function () {
|
|
54
54
|
if (!this.estaNoFinal())
|
|
55
55
|
this.atual += 1;
|
|
56
|
-
return this.
|
|
56
|
+
return this.simbolos[this.atual - 1];
|
|
57
57
|
};
|
|
58
58
|
AvaliadorSintatico.prototype.verificarSeSimboloAtualEIgualA = function () {
|
|
59
59
|
var argumentos = [];
|
|
@@ -70,98 +70,98 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
70
70
|
return false;
|
|
71
71
|
};
|
|
72
72
|
AvaliadorSintatico.prototype.primario = function () {
|
|
73
|
-
var simboloAtual = this.
|
|
74
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
75
|
-
var simboloChave = this.
|
|
76
|
-
this.consumir(
|
|
77
|
-
var metodo = this.consumir(
|
|
73
|
+
var simboloAtual = this.simbolos[this.atual];
|
|
74
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.SUPER)) {
|
|
75
|
+
var simboloChave = this.simbolos[this.atual - 1];
|
|
76
|
+
this.consumir(delegua_1.default.PONTO, "Esperado '.' após 'super'.");
|
|
77
|
+
var metodo = this.consumir(delegua_1.default.IDENTIFICADOR, 'Esperado nome do método da SuperClasse.');
|
|
78
78
|
return new construtos_1.Super(this.hashArquivo, simboloChave, metodo);
|
|
79
79
|
}
|
|
80
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
80
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.COLCHETE_ESQUERDO)) {
|
|
81
81
|
var valores = [];
|
|
82
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
82
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.COLCHETE_DIREITO)) {
|
|
83
83
|
return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), []);
|
|
84
84
|
}
|
|
85
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
85
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_1.default.COLCHETE_DIREITO)) {
|
|
86
86
|
var valor = this.atribuir();
|
|
87
87
|
valores.push(valor);
|
|
88
|
-
if (this.
|
|
89
|
-
|
|
90
|
-
this.consumir(
|
|
88
|
+
if (this.simbolos[this.atual].tipo !==
|
|
89
|
+
delegua_1.default.COLCHETE_DIREITO) {
|
|
90
|
+
this.consumir(delegua_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
return new construtos_1.Vetor(this.hashArquivo, Number(simboloAtual.linha), valores);
|
|
94
94
|
}
|
|
95
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
95
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.CHAVE_ESQUERDA)) {
|
|
96
96
|
var chaves = [];
|
|
97
97
|
var valores = [];
|
|
98
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
98
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.CHAVE_DIREITA)) {
|
|
99
99
|
return new construtos_1.Dicionario(this.hashArquivo, Number(simboloAtual.linha), [], []);
|
|
100
100
|
}
|
|
101
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
101
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_1.default.CHAVE_DIREITA)) {
|
|
102
102
|
var chave = this.atribuir();
|
|
103
|
-
this.consumir(
|
|
103
|
+
this.consumir(delegua_1.default.DOIS_PONTOS, "Esperado ':' entre chave e valor.");
|
|
104
104
|
var valor = this.atribuir();
|
|
105
105
|
chaves.push(chave);
|
|
106
106
|
valores.push(valor);
|
|
107
|
-
if (this.
|
|
108
|
-
this.consumir(
|
|
107
|
+
if (this.simbolos[this.atual].tipo !== delegua_1.default.CHAVE_DIREITA) {
|
|
108
|
+
this.consumir(delegua_1.default.VIRGULA, 'Esperado vírgula antes da próxima expressão.');
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
return new construtos_1.Dicionario(this.hashArquivo, Number(simboloAtual.linha), chaves, valores);
|
|
112
112
|
}
|
|
113
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
114
|
-
return this.corpoDaFuncao(this.
|
|
115
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
113
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.FUNÇÃO, delegua_1.default.FUNCAO))
|
|
114
|
+
return this.corpoDaFuncao(this.simbolos[this.atual - 1].lexema);
|
|
115
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.FALSO))
|
|
116
116
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), false);
|
|
117
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
117
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.VERDADEIRO))
|
|
118
118
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), true);
|
|
119
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
119
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.NULO))
|
|
120
120
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAtual.linha), null);
|
|
121
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
122
|
-
return new construtos_1.Isto(this.hashArquivo, Number(simboloAtual.linha), this.
|
|
123
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
124
|
-
var simboloAnterior = this.
|
|
121
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.ISTO))
|
|
122
|
+
return new construtos_1.Isto(this.hashArquivo, Number(simboloAtual.linha), this.simbolos[this.atual - 1]);
|
|
123
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.NUMERO, delegua_1.default.TEXTO)) {
|
|
124
|
+
var simboloAnterior = this.simbolos[this.atual - 1];
|
|
125
125
|
return new construtos_1.Literal(this.hashArquivo, Number(simboloAnterior.linha), simboloAnterior.literal);
|
|
126
126
|
}
|
|
127
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
128
|
-
return new construtos_1.Variavel(this.hashArquivo, this.
|
|
127
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.IDENTIFICADOR)) {
|
|
128
|
+
return new construtos_1.Variavel(this.hashArquivo, this.simbolos[this.atual - 1]);
|
|
129
129
|
}
|
|
130
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
130
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PARENTESE_ESQUERDO)) {
|
|
131
131
|
var expressao = this.expressao();
|
|
132
|
-
this.consumir(
|
|
132
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após a expressão.");
|
|
133
133
|
return new construtos_1.Agrupamento(this.hashArquivo, Number(simboloAtual.linha), expressao);
|
|
134
134
|
}
|
|
135
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
135
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.IMPORTAR))
|
|
136
136
|
return this.declaracaoImportar();
|
|
137
|
-
throw this.erro(this.
|
|
137
|
+
throw this.erro(this.simbolos[this.atual], 'Esperado expressão.');
|
|
138
138
|
};
|
|
139
139
|
AvaliadorSintatico.prototype.finalizarChamada = function (entidadeChamada) {
|
|
140
140
|
var argumentos = [];
|
|
141
|
-
if (!this.verificarTipoSimboloAtual(
|
|
141
|
+
if (!this.verificarTipoSimboloAtual(delegua_1.default.PARENTESE_DIREITO)) {
|
|
142
142
|
do {
|
|
143
143
|
if (argumentos.length >= 255) {
|
|
144
|
-
throw this.erro(this.
|
|
144
|
+
throw this.erro(this.simbolos[this.atual], 'Não pode haver mais de 255 argumentos.');
|
|
145
145
|
}
|
|
146
146
|
argumentos.push(this.expressao());
|
|
147
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
147
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.VIRGULA));
|
|
148
148
|
}
|
|
149
|
-
var parenteseDireito = this.consumir(
|
|
149
|
+
var parenteseDireito = this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após os argumentos.");
|
|
150
150
|
return new construtos_1.Chamada(this.hashArquivo, entidadeChamada, parenteseDireito, argumentos);
|
|
151
151
|
};
|
|
152
152
|
AvaliadorSintatico.prototype.chamar = function () {
|
|
153
153
|
var expressao = this.primario();
|
|
154
154
|
while (true) {
|
|
155
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
155
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PARENTESE_ESQUERDO)) {
|
|
156
156
|
expressao = this.finalizarChamada(expressao);
|
|
157
157
|
}
|
|
158
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
159
|
-
var nome = this.consumir(
|
|
158
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PONTO)) {
|
|
159
|
+
var nome = this.consumir(delegua_1.default.IDENTIFICADOR, "Esperado nome do método após '.'.");
|
|
160
160
|
expressao = new construtos_1.AcessoMetodo(this.hashArquivo, expressao, nome);
|
|
161
161
|
}
|
|
162
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
162
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.COLCHETE_ESQUERDO)) {
|
|
163
163
|
var indice = this.expressao();
|
|
164
|
-
var simboloFechamento = this.consumir(
|
|
164
|
+
var simboloFechamento = this.consumir(delegua_1.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
165
165
|
expressao = new construtos_1.AcessoIndiceVariavel(this.hashArquivo, expressao, indice, simboloFechamento);
|
|
166
166
|
}
|
|
167
167
|
else {
|
|
@@ -171,8 +171,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
171
171
|
return expressao;
|
|
172
172
|
};
|
|
173
173
|
AvaliadorSintatico.prototype.unario = function () {
|
|
174
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
175
|
-
var operador = this.
|
|
174
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.NEGACAO, delegua_1.default.SUBTRACAO, delegua_1.default.BIT_NOT)) {
|
|
175
|
+
var operador = this.simbolos[this.atual - 1];
|
|
176
176
|
var direito = this.unario();
|
|
177
177
|
return new construtos_1.Unario(this.hashArquivo, operador, direito);
|
|
178
178
|
}
|
|
@@ -180,8 +180,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
180
180
|
};
|
|
181
181
|
AvaliadorSintatico.prototype.exponenciacao = function () {
|
|
182
182
|
var expressao = this.unario();
|
|
183
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
184
|
-
var operador = this.
|
|
183
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.EXPONENCIACAO)) {
|
|
184
|
+
var operador = this.simbolos[this.atual - 1];
|
|
185
185
|
var direito = this.unario();
|
|
186
186
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
187
187
|
}
|
|
@@ -189,8 +189,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
189
189
|
};
|
|
190
190
|
AvaliadorSintatico.prototype.multiplicar = function () {
|
|
191
191
|
var expressao = this.exponenciacao();
|
|
192
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
193
|
-
var operador = this.
|
|
192
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.DIVISAO, delegua_1.default.MULTIPLICACAO, delegua_1.default.MODULO, delegua_1.default.DIVISAO_IGUAL, delegua_1.default.MULTIPLICACAO_IGUAL, delegua_1.default.MODULO_IGUAL)) {
|
|
193
|
+
var operador = this.simbolos[this.atual - 1];
|
|
194
194
|
var direito = this.exponenciacao();
|
|
195
195
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
196
196
|
}
|
|
@@ -203,8 +203,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
203
203
|
*/
|
|
204
204
|
AvaliadorSintatico.prototype.adicaoOuSubtracao = function () {
|
|
205
205
|
var expressao = this.multiplicar();
|
|
206
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
207
|
-
var operador = this.
|
|
206
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.SUBTRACAO, delegua_1.default.ADICAO, delegua_1.default.MAIS_IGUAL, delegua_1.default.MENOS_IGUAL)) {
|
|
207
|
+
var operador = this.simbolos[this.atual - 1];
|
|
208
208
|
var direito = this.multiplicar();
|
|
209
209
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
210
210
|
}
|
|
@@ -212,8 +212,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
212
212
|
};
|
|
213
213
|
AvaliadorSintatico.prototype.bitFill = function () {
|
|
214
214
|
var expressao = this.adicaoOuSubtracao();
|
|
215
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
216
|
-
var operador = this.
|
|
215
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.MENOR_MENOR, delegua_1.default.MAIOR_MAIOR)) {
|
|
216
|
+
var operador = this.simbolos[this.atual - 1];
|
|
217
217
|
var direito = this.adicaoOuSubtracao();
|
|
218
218
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
219
219
|
}
|
|
@@ -221,8 +221,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
221
221
|
};
|
|
222
222
|
AvaliadorSintatico.prototype.bitE = function () {
|
|
223
223
|
var expressao = this.bitFill();
|
|
224
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
225
|
-
var operador = this.
|
|
224
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.BIT_AND)) {
|
|
225
|
+
var operador = this.simbolos[this.atual - 1];
|
|
226
226
|
var direito = this.bitFill();
|
|
227
227
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
228
228
|
}
|
|
@@ -230,8 +230,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
230
230
|
};
|
|
231
231
|
AvaliadorSintatico.prototype.bitOu = function () {
|
|
232
232
|
var expressao = this.bitE();
|
|
233
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
234
|
-
var operador = this.
|
|
233
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.BIT_OR, delegua_1.default.BIT_XOR)) {
|
|
234
|
+
var operador = this.simbolos[this.atual - 1];
|
|
235
235
|
var direito = this.bitE();
|
|
236
236
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
237
237
|
}
|
|
@@ -239,8 +239,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
239
239
|
};
|
|
240
240
|
AvaliadorSintatico.prototype.comparar = function () {
|
|
241
241
|
var expressao = this.bitOu();
|
|
242
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
243
|
-
var operador = this.
|
|
242
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.MAIOR, delegua_1.default.MAIOR_IGUAL, delegua_1.default.MENOR, delegua_1.default.MENOR_IGUAL)) {
|
|
243
|
+
var operador = this.simbolos[this.atual - 1];
|
|
244
244
|
var direito = this.bitOu();
|
|
245
245
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
246
246
|
}
|
|
@@ -248,8 +248,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
248
248
|
};
|
|
249
249
|
AvaliadorSintatico.prototype.comparacaoIgualdade = function () {
|
|
250
250
|
var expressao = this.comparar();
|
|
251
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
252
|
-
var operador = this.
|
|
251
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.DIFERENTE, delegua_1.default.IGUAL_IGUAL)) {
|
|
252
|
+
var operador = this.simbolos[this.atual - 1];
|
|
253
253
|
var direito = this.comparar();
|
|
254
254
|
expressao = new construtos_1.Binario(this.hashArquivo, expressao, operador, direito);
|
|
255
255
|
}
|
|
@@ -257,8 +257,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
257
257
|
};
|
|
258
258
|
AvaliadorSintatico.prototype.em = function () {
|
|
259
259
|
var expressao = this.comparacaoIgualdade();
|
|
260
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
261
|
-
var operador = this.
|
|
260
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.EM)) {
|
|
261
|
+
var operador = this.simbolos[this.atual - 1];
|
|
262
262
|
var direito = this.comparacaoIgualdade();
|
|
263
263
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
264
264
|
}
|
|
@@ -266,8 +266,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
266
266
|
};
|
|
267
267
|
AvaliadorSintatico.prototype.e = function () {
|
|
268
268
|
var expressao = this.em();
|
|
269
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
270
|
-
var operador = this.
|
|
269
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.E)) {
|
|
270
|
+
var operador = this.simbolos[this.atual - 1];
|
|
271
271
|
var direito = this.em();
|
|
272
272
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
273
273
|
}
|
|
@@ -275,8 +275,8 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
275
275
|
};
|
|
276
276
|
AvaliadorSintatico.prototype.ou = function () {
|
|
277
277
|
var expressao = this.e();
|
|
278
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
279
|
-
var operador = this.
|
|
278
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.OU)) {
|
|
279
|
+
var operador = this.simbolos[this.atual - 1];
|
|
280
280
|
var direito = this.e();
|
|
281
281
|
expressao = new construtos_1.Logico(this.hashArquivo, expressao, operador, direito);
|
|
282
282
|
}
|
|
@@ -290,16 +290,16 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
290
290
|
var expressao = this.ou();
|
|
291
291
|
if (expressao instanceof construtos_1.Binario &&
|
|
292
292
|
[
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
delegua_1.default.MAIS_IGUAL,
|
|
294
|
+
delegua_1.default.MENOS_IGUAL,
|
|
295
|
+
delegua_1.default.MULTIPLICACAO_IGUAL,
|
|
296
|
+
delegua_1.default.DIVISAO_IGUAL,
|
|
297
|
+
delegua_1.default.MODULO_IGUAL,
|
|
298
298
|
].includes(expressao.operador.tipo)) {
|
|
299
299
|
return new construtos_1.Atribuir(this.hashArquivo, expressao.esquerda.simbolo, expressao);
|
|
300
300
|
}
|
|
301
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
302
|
-
var igual = this.
|
|
301
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.IGUAL)) {
|
|
302
|
+
var igual = this.simbolos[this.atual - 1];
|
|
303
303
|
var valor = this.atribuir();
|
|
304
304
|
if (expressao instanceof construtos_1.Variavel) {
|
|
305
305
|
var simbolo = expressao.simbolo;
|
|
@@ -320,13 +320,13 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
320
320
|
return this.atribuir();
|
|
321
321
|
};
|
|
322
322
|
AvaliadorSintatico.prototype.declaracaoEscreva = function () {
|
|
323
|
-
var simboloAtual = this.
|
|
324
|
-
this.consumir(
|
|
323
|
+
var simboloAtual = this.simbolos[this.atual];
|
|
324
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' antes dos valores em escreva.");
|
|
325
325
|
var argumentos = [];
|
|
326
326
|
do {
|
|
327
327
|
argumentos.push(this.expressao());
|
|
328
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
329
|
-
this.consumir(
|
|
328
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.VIRGULA));
|
|
329
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após os valores em escreva.");
|
|
330
330
|
return new declaracoes_1.Escreva(Number(simboloAtual.linha), simboloAtual.hashArquivo, argumentos);
|
|
331
331
|
};
|
|
332
332
|
AvaliadorSintatico.prototype.declaracaoExpressao = function () {
|
|
@@ -335,23 +335,23 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
335
335
|
};
|
|
336
336
|
AvaliadorSintatico.prototype.blocoEscopo = function () {
|
|
337
337
|
var declaracoes = [];
|
|
338
|
-
while (!this.verificarTipoSimboloAtual(
|
|
338
|
+
while (!this.verificarTipoSimboloAtual(delegua_1.default.CHAVE_DIREITA) &&
|
|
339
339
|
!this.estaNoFinal()) {
|
|
340
340
|
declaracoes.push(this.declaracao());
|
|
341
341
|
}
|
|
342
|
-
this.consumir(
|
|
342
|
+
this.consumir(delegua_1.default.CHAVE_DIREITA, "Esperado '}' após o bloco.");
|
|
343
343
|
return declaracoes;
|
|
344
344
|
};
|
|
345
345
|
AvaliadorSintatico.prototype.declaracaoSe = function () {
|
|
346
|
-
this.consumir(
|
|
346
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'se'.");
|
|
347
347
|
var condicao = this.expressao();
|
|
348
|
-
this.consumir(
|
|
348
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após condição do se.");
|
|
349
349
|
var caminhoEntao = this.resolverDeclaracao();
|
|
350
350
|
var caminhosSeSenao = [];
|
|
351
|
-
while (this.verificarSeSimboloAtualEIgualA(
|
|
352
|
-
this.consumir(
|
|
351
|
+
while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.SENAOSE, delegua_1.default.SENÃOSE)) {
|
|
352
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'senaose' ou 'senãose'.");
|
|
353
353
|
var condicaoSeSenao = this.expressao();
|
|
354
|
-
this.consumir(
|
|
354
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após codição do 'senaose' ou 'senãose'.");
|
|
355
355
|
var caminho = this.resolverDeclaracao();
|
|
356
356
|
caminhosSeSenao.push({
|
|
357
357
|
condicao: condicaoSeSenao,
|
|
@@ -359,7 +359,7 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
361
|
var caminhoSenao = null;
|
|
362
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
362
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.SENAO, delegua_1.default.SENÃO)) {
|
|
363
363
|
caminhoSenao = this.resolverDeclaracao();
|
|
364
364
|
}
|
|
365
365
|
return new declaracoes_1.Se(condicao, caminhoEntao, caminhosSeSenao, caminhoSenao);
|
|
@@ -367,9 +367,9 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
367
367
|
AvaliadorSintatico.prototype.declaracaoEnquanto = function () {
|
|
368
368
|
try {
|
|
369
369
|
this.ciclos += 1;
|
|
370
|
-
this.consumir(
|
|
370
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'enquanto'.");
|
|
371
371
|
var condicao = this.expressao();
|
|
372
|
-
this.consumir(
|
|
372
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após condicional.");
|
|
373
373
|
var corpo = this.resolverDeclaracao();
|
|
374
374
|
return new declaracoes_1.Enquanto(condicao, corpo);
|
|
375
375
|
}
|
|
@@ -379,28 +379,28 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
379
379
|
};
|
|
380
380
|
AvaliadorSintatico.prototype.declaracaoPara = function () {
|
|
381
381
|
try {
|
|
382
|
-
var simboloPara = this.
|
|
382
|
+
var simboloPara = this.simbolos[this.atual - 1];
|
|
383
383
|
this.ciclos += 1;
|
|
384
|
-
this.consumir(
|
|
384
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' após 'para'.");
|
|
385
385
|
var inicializador = void 0;
|
|
386
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
386
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PONTO_E_VIRGULA)) {
|
|
387
387
|
inicializador = null;
|
|
388
388
|
}
|
|
389
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
389
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.VARIAVEL)) {
|
|
390
390
|
inicializador = this.declaracaoDeVariavel();
|
|
391
391
|
}
|
|
392
392
|
else {
|
|
393
393
|
inicializador = this.declaracaoExpressao();
|
|
394
394
|
}
|
|
395
395
|
var condicao = null;
|
|
396
|
-
if (!this.verificarTipoSimboloAtual(
|
|
396
|
+
if (!this.verificarTipoSimboloAtual(delegua_1.default.PONTO_E_VIRGULA)) {
|
|
397
397
|
condicao = this.expressao();
|
|
398
398
|
}
|
|
399
399
|
var incrementar = null;
|
|
400
|
-
if (!this.verificarTipoSimboloAtual(
|
|
400
|
+
if (!this.verificarTipoSimboloAtual(delegua_1.default.PARENTESE_DIREITO)) {
|
|
401
401
|
incrementar = this.expressao();
|
|
402
402
|
}
|
|
403
|
-
this.consumir(
|
|
403
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após cláusulas");
|
|
404
404
|
var corpo = this.resolverDeclaracao();
|
|
405
405
|
return new declaracoes_1.Para(this.hashArquivo, Number(simboloPara.linha), inicializador, condicao, incrementar, corpo);
|
|
406
406
|
}
|
|
@@ -410,20 +410,20 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
410
410
|
};
|
|
411
411
|
AvaliadorSintatico.prototype.declaracaoSustar = function () {
|
|
412
412
|
if (this.ciclos < 1) {
|
|
413
|
-
this.erro(this.
|
|
413
|
+
this.erro(this.simbolos[this.atual - 1], "'sustar' ou 'pausa' deve estar dentro de um laço de repetição.");
|
|
414
414
|
}
|
|
415
|
-
return new declaracoes_1.Sustar(this.
|
|
415
|
+
return new declaracoes_1.Sustar(this.simbolos[this.atual]);
|
|
416
416
|
};
|
|
417
417
|
AvaliadorSintatico.prototype.declaracaoContinua = function () {
|
|
418
418
|
if (this.ciclos < 1) {
|
|
419
|
-
this.erro(this.
|
|
419
|
+
this.erro(this.simbolos[this.atual - 1], "'continua' precisa estar em um laço de repetição.");
|
|
420
420
|
}
|
|
421
|
-
return new declaracoes_1.Continua(this.
|
|
421
|
+
return new declaracoes_1.Continua(this.simbolos[this.atual]);
|
|
422
422
|
};
|
|
423
423
|
AvaliadorSintatico.prototype.declaracaoRetorna = function () {
|
|
424
|
-
var simboloChave = this.
|
|
424
|
+
var simboloChave = this.simbolos[this.atual - 1];
|
|
425
425
|
var valor = null;
|
|
426
|
-
if (!this.verificarTipoSimboloAtual(
|
|
426
|
+
if (!this.verificarTipoSimboloAtual(delegua_1.default.PONTO_E_VIRGULA)) {
|
|
427
427
|
valor = this.expressao();
|
|
428
428
|
}
|
|
429
429
|
return new declaracoes_1.Retorna(simboloChave, valor);
|
|
@@ -431,46 +431,46 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
431
431
|
AvaliadorSintatico.prototype.declaracaoEscolha = function () {
|
|
432
432
|
try {
|
|
433
433
|
this.ciclos += 1;
|
|
434
|
-
this.consumir(
|
|
434
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '{' após 'escolha'.");
|
|
435
435
|
var condicao = this.expressao();
|
|
436
|
-
this.consumir(
|
|
437
|
-
this.consumir(
|
|
436
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado '}' após a condição de 'escolha'.");
|
|
437
|
+
this.consumir(delegua_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo do 'escolha'.");
|
|
438
438
|
var caminhos = [];
|
|
439
439
|
var caminhoPadrao = null;
|
|
440
|
-
while (!this.verificarSeSimboloAtualEIgualA(
|
|
440
|
+
while (!this.verificarSeSimboloAtualEIgualA(delegua_1.default.CHAVE_DIREITA) &&
|
|
441
441
|
!this.estaNoFinal()) {
|
|
442
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
442
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.CASO)) {
|
|
443
443
|
var caminhoCondicoes = [this.expressao()];
|
|
444
|
-
this.consumir(
|
|
445
|
-
while (this.verificarTipoSimboloAtual(
|
|
446
|
-
this.consumir(
|
|
444
|
+
this.consumir(delegua_1.default.DOIS_PONTOS, "Esperado ':' após o 'caso'.");
|
|
445
|
+
while (this.verificarTipoSimboloAtual(delegua_1.default.CASO)) {
|
|
446
|
+
this.consumir(delegua_1.default.CASO, null);
|
|
447
447
|
caminhoCondicoes.push(this.expressao());
|
|
448
|
-
this.consumir(
|
|
448
|
+
this.consumir(delegua_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'caso'.");
|
|
449
449
|
}
|
|
450
450
|
var declaracoes = [];
|
|
451
451
|
do {
|
|
452
452
|
declaracoes.push(this.resolverDeclaracao());
|
|
453
|
-
} while (!this.verificarTipoSimboloAtual(
|
|
454
|
-
!this.verificarTipoSimboloAtual(
|
|
455
|
-
!this.verificarTipoSimboloAtual(
|
|
453
|
+
} while (!this.verificarTipoSimboloAtual(delegua_1.default.CASO) &&
|
|
454
|
+
!this.verificarTipoSimboloAtual(delegua_1.default.PADRAO) &&
|
|
455
|
+
!this.verificarTipoSimboloAtual(delegua_1.default.CHAVE_DIREITA));
|
|
456
456
|
caminhos.push({
|
|
457
457
|
condicoes: caminhoCondicoes,
|
|
458
458
|
declaracoes: declaracoes,
|
|
459
459
|
});
|
|
460
460
|
}
|
|
461
|
-
else if (this.verificarSeSimboloAtualEIgualA(
|
|
461
|
+
else if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PADRAO)) {
|
|
462
462
|
if (caminhoPadrao !== null) {
|
|
463
|
-
var excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.
|
|
463
|
+
var excecao = new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(this.simbolos[this.atual], "Você só pode ter um 'padrao' em cada declaração de 'escolha'.");
|
|
464
464
|
this.erros.push(excecao);
|
|
465
465
|
throw excecao;
|
|
466
466
|
}
|
|
467
|
-
this.consumir(
|
|
467
|
+
this.consumir(delegua_1.default.DOIS_PONTOS, "Esperado ':' após declaração do 'padrao'.");
|
|
468
468
|
var declaracoes = [];
|
|
469
469
|
do {
|
|
470
470
|
declaracoes.push(this.resolverDeclaracao());
|
|
471
|
-
} while (!this.verificarTipoSimboloAtual(
|
|
472
|
-
!this.verificarTipoSimboloAtual(
|
|
473
|
-
!this.verificarTipoSimboloAtual(
|
|
471
|
+
} while (!this.verificarTipoSimboloAtual(delegua_1.default.CASO) &&
|
|
472
|
+
!this.verificarTipoSimboloAtual(delegua_1.default.PADRAO) &&
|
|
473
|
+
!this.verificarTipoSimboloAtual(delegua_1.default.CHAVE_DIREITA));
|
|
474
474
|
caminhoPadrao = {
|
|
475
475
|
declaracoes: declaracoes,
|
|
476
476
|
};
|
|
@@ -483,41 +483,41 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
483
483
|
}
|
|
484
484
|
};
|
|
485
485
|
AvaliadorSintatico.prototype.declaracaoImportar = function () {
|
|
486
|
-
this.consumir(
|
|
486
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração.");
|
|
487
487
|
var caminho = this.expressao();
|
|
488
|
-
var simboloFechamento = this.consumir(
|
|
488
|
+
var simboloFechamento = this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração.");
|
|
489
489
|
return new declaracoes_1.Importar(caminho, simboloFechamento);
|
|
490
490
|
};
|
|
491
491
|
AvaliadorSintatico.prototype.declaracaoTente = function () {
|
|
492
|
-
var simboloTente = this.
|
|
493
|
-
this.consumir(
|
|
492
|
+
var simboloTente = this.simbolos[this.atual - 1];
|
|
493
|
+
this.consumir(delegua_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'tente'.");
|
|
494
494
|
var blocoTente = this.blocoEscopo();
|
|
495
495
|
var blocoPegue = null;
|
|
496
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
497
|
-
this.consumir(
|
|
496
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PEGUE)) {
|
|
497
|
+
this.consumir(delegua_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
|
|
498
498
|
blocoPegue = this.blocoEscopo();
|
|
499
499
|
}
|
|
500
500
|
var blocoSenao = null;
|
|
501
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
502
|
-
this.consumir(
|
|
501
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.SENAO, delegua_1.default.SENÃO)) {
|
|
502
|
+
this.consumir(delegua_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
|
|
503
503
|
blocoSenao = this.blocoEscopo();
|
|
504
504
|
}
|
|
505
505
|
var blocoFinalmente = null;
|
|
506
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
507
|
-
this.consumir(
|
|
506
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.FINALMENTE)) {
|
|
507
|
+
this.consumir(delegua_1.default.CHAVE_ESQUERDA, "Esperado '{' após a declaração 'pegue'.");
|
|
508
508
|
blocoFinalmente = this.blocoEscopo();
|
|
509
509
|
}
|
|
510
510
|
return new declaracoes_1.Tente(simboloTente.hashArquivo, Number(simboloTente.linha), blocoTente, blocoPegue, blocoSenao, blocoFinalmente);
|
|
511
511
|
};
|
|
512
512
|
AvaliadorSintatico.prototype.declaracaoFazer = function () {
|
|
513
|
-
var simboloFazer = this.
|
|
513
|
+
var simboloFazer = this.simbolos[this.atual - 1];
|
|
514
514
|
try {
|
|
515
515
|
this.ciclos += 1;
|
|
516
516
|
var caminhoFazer = this.resolverDeclaracao();
|
|
517
|
-
this.consumir(
|
|
518
|
-
this.consumir(
|
|
517
|
+
this.consumir(delegua_1.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo do 'fazer'.");
|
|
518
|
+
this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' após declaração 'enquanto'.");
|
|
519
519
|
var condicaoEnquanto = this.expressao();
|
|
520
|
-
this.consumir(
|
|
520
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após declaração do 'enquanto'.");
|
|
521
521
|
return new declaracoes_1.Fazer(simboloFazer.hashArquivo, Number(simboloFazer.linha), caminhoFazer, condicaoEnquanto);
|
|
522
522
|
}
|
|
523
523
|
finally {
|
|
@@ -525,40 +525,40 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
525
525
|
}
|
|
526
526
|
};
|
|
527
527
|
AvaliadorSintatico.prototype.resolverDeclaracao = function () {
|
|
528
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
528
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.FAZER))
|
|
529
529
|
return this.declaracaoFazer();
|
|
530
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
530
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.TENTE))
|
|
531
531
|
return this.declaracaoTente();
|
|
532
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
532
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.ESCOLHA))
|
|
533
533
|
return this.declaracaoEscolha();
|
|
534
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
534
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.RETORNA))
|
|
535
535
|
return this.declaracaoRetorna();
|
|
536
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
536
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.CONTINUA))
|
|
537
537
|
return this.declaracaoContinua();
|
|
538
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
538
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PAUSA))
|
|
539
539
|
return this.declaracaoSustar();
|
|
540
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
540
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.PARA))
|
|
541
541
|
return this.declaracaoPara();
|
|
542
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
542
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.ENQUANTO))
|
|
543
543
|
return this.declaracaoEnquanto();
|
|
544
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
544
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.SE))
|
|
545
545
|
return this.declaracaoSe();
|
|
546
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
546
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.ESCREVA))
|
|
547
547
|
return this.declaracaoEscreva();
|
|
548
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
549
|
-
var simboloInicioBloco = this.
|
|
548
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.CHAVE_ESQUERDA)) {
|
|
549
|
+
var simboloInicioBloco = this.simbolos[this.atual - 1];
|
|
550
550
|
return new declaracoes_1.Bloco(simboloInicioBloco.hashArquivo, Number(simboloInicioBloco.linha), this.blocoEscopo());
|
|
551
551
|
}
|
|
552
|
-
var simboloAtual = this.
|
|
553
|
-
if (simboloAtual.tipo ===
|
|
552
|
+
var simboloAtual = this.simbolos[this.atual];
|
|
553
|
+
if (simboloAtual.tipo === delegua_1.default.IDENTIFICADOR) {
|
|
554
554
|
// Pela gramática, a seguinte situação não pode ocorrer:
|
|
555
555
|
// 1. O símbolo anterior ser um identificador; e
|
|
556
556
|
// 2. O símbolo anterior estar na mesma linha do identificador atual.
|
|
557
|
-
var simboloAnterior = this.
|
|
557
|
+
var simboloAnterior = this.simbolos[this.atual - 1];
|
|
558
558
|
if (!!simboloAnterior &&
|
|
559
|
-
simboloAnterior.tipo ===
|
|
559
|
+
simboloAnterior.tipo === delegua_1.default.IDENTIFICADOR &&
|
|
560
560
|
simboloAnterior.linha === simboloAtual.linha) {
|
|
561
|
-
this.erro(this.
|
|
561
|
+
this.erro(this.simbolos[this.atual], 'Não é permitido ter dois identificadores seguidos na mesma linha.');
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
return this.declaracaoExpressao();
|
|
@@ -568,81 +568,81 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
568
568
|
* @returns Um Construto do tipo Var.
|
|
569
569
|
*/
|
|
570
570
|
AvaliadorSintatico.prototype.declaracaoDeVariavel = function () {
|
|
571
|
-
var simbolo = this.consumir(
|
|
571
|
+
var simbolo = this.consumir(delegua_1.default.IDENTIFICADOR, 'Esperado nome de variável.');
|
|
572
572
|
var inicializador = null;
|
|
573
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
573
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.IGUAL)) {
|
|
574
574
|
inicializador = this.expressao();
|
|
575
575
|
}
|
|
576
576
|
return new declaracoes_1.Var(simbolo, inicializador);
|
|
577
577
|
};
|
|
578
578
|
AvaliadorSintatico.prototype.funcao = function (tipo) {
|
|
579
|
-
var simbolo = this.consumir(
|
|
579
|
+
var simbolo = this.consumir(delegua_1.default.IDENTIFICADOR, "Esperado nome ".concat(tipo, "."));
|
|
580
580
|
return new declaracoes_1.Funcao(simbolo, this.corpoDaFuncao(tipo));
|
|
581
581
|
};
|
|
582
582
|
AvaliadorSintatico.prototype.logicaComumParametros = function () {
|
|
583
583
|
var parametros = [];
|
|
584
584
|
do {
|
|
585
585
|
if (parametros.length >= 255) {
|
|
586
|
-
this.erro(this.
|
|
586
|
+
this.erro(this.simbolos[this.atual], 'Não pode haver mais de 255 parâmetros');
|
|
587
587
|
}
|
|
588
588
|
var parametro = {};
|
|
589
|
-
if (this.
|
|
590
|
-
this.consumir(
|
|
589
|
+
if (this.simbolos[this.atual].tipo === delegua_1.default.MULTIPLICACAO) {
|
|
590
|
+
this.consumir(delegua_1.default.MULTIPLICACAO, null);
|
|
591
591
|
parametro.tipo = 'estrela';
|
|
592
592
|
}
|
|
593
593
|
else {
|
|
594
594
|
parametro.tipo = 'padrao';
|
|
595
595
|
}
|
|
596
|
-
parametro.nome = this.consumir(
|
|
597
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
596
|
+
parametro.nome = this.consumir(delegua_1.default.IDENTIFICADOR, 'Esperado nome do parâmetro.');
|
|
597
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.IGUAL)) {
|
|
598
598
|
parametro.valorPadrao = this.primario();
|
|
599
599
|
}
|
|
600
600
|
parametros.push(parametro);
|
|
601
601
|
if (parametro.tipo === 'estrela')
|
|
602
602
|
break;
|
|
603
|
-
} while (this.verificarSeSimboloAtualEIgualA(
|
|
603
|
+
} while (this.verificarSeSimboloAtualEIgualA(delegua_1.default.VIRGULA));
|
|
604
604
|
return parametros;
|
|
605
605
|
};
|
|
606
606
|
AvaliadorSintatico.prototype.corpoDaFuncao = function (tipo) {
|
|
607
607
|
// O parêntese esquerdo é considerado o símbolo inicial para
|
|
608
608
|
// fins de pragma.
|
|
609
|
-
var parenteseEsquerdo = this.consumir(
|
|
609
|
+
var parenteseEsquerdo = this.consumir(delegua_1.default.PARENTESE_ESQUERDO, "Esperado '(' ap\u00F3s o nome ".concat(tipo, "."));
|
|
610
610
|
var parametros = [];
|
|
611
|
-
if (!this.verificarTipoSimboloAtual(
|
|
611
|
+
if (!this.verificarTipoSimboloAtual(delegua_1.default.PARENTESE_DIREITO)) {
|
|
612
612
|
parametros = this.logicaComumParametros();
|
|
613
613
|
}
|
|
614
|
-
this.consumir(
|
|
615
|
-
this.consumir(
|
|
614
|
+
this.consumir(delegua_1.default.PARENTESE_DIREITO, "Esperado ')' após parâmetros.");
|
|
615
|
+
this.consumir(delegua_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo do ".concat(tipo, "."));
|
|
616
616
|
var corpo = this.blocoEscopo();
|
|
617
617
|
return new construtos_1.Funcao(this.hashArquivo, Number(parenteseEsquerdo.linha), parametros, corpo);
|
|
618
618
|
};
|
|
619
619
|
AvaliadorSintatico.prototype.declaracaoDeClasse = function () {
|
|
620
|
-
var simbolo = this.consumir(
|
|
620
|
+
var simbolo = this.consumir(delegua_1.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
621
621
|
var superClasse = null;
|
|
622
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
623
|
-
this.consumir(
|
|
624
|
-
superClasse = new construtos_1.Variavel(this.hashArquivo, this.
|
|
622
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.HERDA)) {
|
|
623
|
+
this.consumir(delegua_1.default.IDENTIFICADOR, 'Esperado nome da SuperClasse.');
|
|
624
|
+
superClasse = new construtos_1.Variavel(this.hashArquivo, this.simbolos[this.atual - 1]);
|
|
625
625
|
}
|
|
626
|
-
this.consumir(
|
|
626
|
+
this.consumir(delegua_1.default.CHAVE_ESQUERDA, "Esperado '{' antes do escopo da classe.");
|
|
627
627
|
var metodos = [];
|
|
628
|
-
while (!this.verificarTipoSimboloAtual(
|
|
628
|
+
while (!this.verificarTipoSimboloAtual(delegua_1.default.CHAVE_DIREITA) &&
|
|
629
629
|
!this.estaNoFinal()) {
|
|
630
630
|
metodos.push(this.funcao('método'));
|
|
631
631
|
}
|
|
632
|
-
this.consumir(
|
|
632
|
+
this.consumir(delegua_1.default.CHAVE_DIREITA, "Esperado '}' após o escopo da classe.");
|
|
633
633
|
return new declaracoes_1.Classe(simbolo, superClasse, metodos);
|
|
634
634
|
};
|
|
635
635
|
AvaliadorSintatico.prototype.declaracao = function () {
|
|
636
636
|
try {
|
|
637
|
-
if ((this.verificarTipoSimboloAtual(
|
|
638
|
-
this.verificarTipoSimboloAtual(
|
|
639
|
-
this.verificarTipoProximoSimbolo(
|
|
637
|
+
if ((this.verificarTipoSimboloAtual(delegua_1.default.FUNCAO) ||
|
|
638
|
+
this.verificarTipoSimboloAtual(delegua_1.default.FUNÇÃO)) &&
|
|
639
|
+
this.verificarTipoProximoSimbolo(delegua_1.default.IDENTIFICADOR)) {
|
|
640
640
|
this.avancarEDevolverAnterior();
|
|
641
641
|
return this.funcao('funcao');
|
|
642
642
|
}
|
|
643
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
643
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.VARIAVEL))
|
|
644
644
|
return this.declaracaoDeVariavel();
|
|
645
|
-
if (this.verificarSeSimboloAtualEIgualA(
|
|
645
|
+
if (this.verificarSeSimboloAtualEIgualA(delegua_1.default.CLASSE))
|
|
646
646
|
return this.declaracaoDeClasse();
|
|
647
647
|
return this.resolverDeclaracao();
|
|
648
648
|
}
|
|
@@ -659,19 +659,19 @@ var AvaliadorSintatico = /** @class */ (function () {
|
|
|
659
659
|
AvaliadorSintatico.prototype.sincronizar = function () {
|
|
660
660
|
this.avancarEDevolverAnterior();
|
|
661
661
|
while (!this.estaNoFinal()) {
|
|
662
|
-
var tipoSimboloAtual = this.
|
|
663
|
-
if (tipoSimboloAtual ===
|
|
662
|
+
var tipoSimboloAtual = this.simbolos[this.atual - 1].tipo;
|
|
663
|
+
if (tipoSimboloAtual === delegua_1.default.PONTO_E_VIRGULA)
|
|
664
664
|
return;
|
|
665
665
|
switch (tipoSimboloAtual) {
|
|
666
|
-
case
|
|
667
|
-
case
|
|
668
|
-
case
|
|
669
|
-
case
|
|
670
|
-
case
|
|
671
|
-
case
|
|
672
|
-
case
|
|
673
|
-
case
|
|
674
|
-
case
|
|
666
|
+
case delegua_1.default.CLASSE:
|
|
667
|
+
case delegua_1.default.FUNCAO:
|
|
668
|
+
case delegua_1.default.FUNÇÃO:
|
|
669
|
+
case delegua_1.default.VARIAVEL:
|
|
670
|
+
case delegua_1.default.PARA:
|
|
671
|
+
case delegua_1.default.SE:
|
|
672
|
+
case delegua_1.default.ENQUANTO:
|
|
673
|
+
case delegua_1.default.ESCREVA:
|
|
674
|
+
case delegua_1.default.RETORNA:
|
|
675
675
|
return;
|
|
676
676
|
}
|
|
677
677
|
this.avancarEDevolverAnterior();
|