@designliquido/delegua 0.0.2 → 0.1.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/README.md +9 -1
- package/bin/delegua +1 -1
- package/bin/delegua.cmd +1 -1
- package/bin/package.json +51 -0
- package/index.js +27 -0
- package/index.js.map +1 -0
- package/package.json +10 -5
- package/src/ambiente.js +34 -38
- package/src/ambiente.js.map +1 -0
- package/src/avaliador-sintatico/dialetos/egua-classico.js +635 -0
- package/src/avaliador-sintatico/dialetos/egua-classico.js.map +1 -0
- package/src/avaliador-sintatico/dialetos/index.js +14 -0
- package/src/avaliador-sintatico/dialetos/index.js.map +1 -0
- package/src/avaliador-sintatico/index.js +635 -0
- package/src/avaliador-sintatico/index.js.map +1 -0
- package/src/avaliador-sintatico/parser-error.js +27 -0
- package/src/avaliador-sintatico/parser-error.js.map +1 -0
- package/src/bibliotecas/bibliotecaGlobal.js +97 -0
- package/src/bibliotecas/bibliotecaGlobal.js.map +1 -0
- package/src/bibliotecas/importarBiblioteca.js +32 -0
- package/src/bibliotecas/importarBiblioteca.js.map +1 -0
- package/src/construtos/assign-subscript.js +35 -0
- package/src/construtos/assign-subscript.js.map +1 -0
- package/src/construtos/atribuir.js +34 -0
- package/src/construtos/atribuir.js.map +1 -0
- package/src/construtos/binario.js +35 -0
- package/src/construtos/binario.js.map +1 -0
- package/src/construtos/call.js +35 -0
- package/src/construtos/call.js.map +1 -0
- package/src/construtos/conjunto.js +35 -0
- package/src/construtos/conjunto.js.map +1 -0
- package/src/construtos/dicionario.js +34 -0
- package/src/construtos/dicionario.js.map +1 -0
- package/src/construtos/expr.js +11 -0
- package/src/construtos/expr.js.map +1 -0
- package/src/construtos/funcao.js +34 -0
- package/src/construtos/funcao.js.map +1 -0
- package/src/construtos/get.js +34 -0
- package/src/construtos/get.js.map +1 -0
- package/src/construtos/grouping.js +33 -0
- package/src/construtos/grouping.js.map +1 -0
- package/src/construtos/index.js +31 -0
- package/src/construtos/index.js.map +1 -0
- package/src/construtos/isto.js +33 -0
- package/src/construtos/isto.js.map +1 -0
- package/src/construtos/literal.js +33 -0
- package/src/construtos/literal.js.map +1 -0
- package/src/construtos/logical.js +35 -0
- package/src/construtos/logical.js.map +1 -0
- package/src/construtos/subscript.js +35 -0
- package/src/construtos/subscript.js.map +1 -0
- package/src/construtos/super.js +34 -0
- package/src/construtos/super.js.map +1 -0
- package/src/construtos/unario.js +34 -0
- package/src/construtos/unario.js.map +1 -0
- package/src/construtos/variavel.js +33 -0
- package/src/construtos/variavel.js.map +1 -0
- package/src/construtos/vetor.js +33 -0
- package/src/construtos/vetor.js.map +1 -0
- package/src/declaracoes/index.js +249 -0
- package/src/declaracoes/index.js.map +1 -0
- package/src/delegua.js +110 -83
- package/src/delegua.js.map +1 -0
- package/src/estruturas/callable.js +15 -4
- package/src/estruturas/callable.js.map +1 -0
- package/src/estruturas/classe.js +44 -30
- package/src/estruturas/classe.js.map +1 -0
- package/src/estruturas/funcao-padrao.js +38 -0
- package/src/estruturas/funcao-padrao.js.map +1 -0
- package/src/estruturas/funcao.js +71 -52
- package/src/estruturas/funcao.js.map +1 -0
- package/src/estruturas/index.js +19 -0
- package/src/estruturas/index.js.map +1 -0
- package/src/estruturas/instancia.js +23 -22
- package/src/estruturas/instancia.js.map +1 -0
- package/src/estruturas/modulo.js +14 -8
- package/src/estruturas/modulo.js.map +1 -0
- package/src/excecoes/break-exception.js +27 -0
- package/src/excecoes/break-exception.js.map +1 -0
- package/src/excecoes/continue-exception.js +27 -0
- package/src/excecoes/continue-exception.js.map +1 -0
- package/src/excecoes/erro-em-tempo-de-execucao.js +31 -0
- package/src/excecoes/erro-em-tempo-de-execucao.js.map +1 -0
- package/src/excecoes/index.js +17 -0
- package/src/excecoes/index.js.map +1 -0
- package/src/excecoes/return-exception.js +30 -0
- package/src/excecoes/return-exception.js.map +1 -0
- package/src/interfaces/avaliador-sintatico-interface.js +3 -0
- package/src/interfaces/avaliador-sintatico-interface.js.map +1 -0
- package/src/interfaces/index.js +19 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/interfaces/interpretador-interface.js +3 -0
- package/src/interfaces/interpretador-interface.js.map +1 -0
- package/src/interfaces/lexador-interface.js +3 -0
- package/src/interfaces/lexador-interface.js.map +1 -0
- package/src/interfaces/pilha-interface.js +3 -0
- package/src/interfaces/pilha-interface.js.map +1 -0
- package/src/interfaces/resolvedor-interface.js +3 -0
- package/src/interfaces/resolvedor-interface.js.map +1 -0
- package/src/interfaces/simbolo-interface.js +3 -0
- package/src/interfaces/simbolo-interface.js.map +1 -0
- package/src/interpretador/dialetos/egua-classico.js +656 -0
- package/src/interpretador/dialetos/egua-classico.js.map +1 -0
- package/src/interpretador/dialetos/index.js +14 -0
- package/src/interpretador/dialetos/index.js.map +1 -0
- package/src/interpretador/index.js +665 -0
- package/src/interpretador/index.js.map +1 -0
- package/src/lexador/dialetos/egua-classico.js +287 -0
- package/src/lexador/dialetos/egua-classico.js.map +1 -0
- package/src/lexador/dialetos/index.js +14 -0
- package/src/lexador/dialetos/index.js.map +1 -0
- package/src/lexador/index.js +287 -0
- package/src/lexador/index.js.map +1 -0
- package/src/resolvedor/Pilha.js +27 -0
- package/src/resolvedor/Pilha.js.map +1 -0
- package/src/resolvedor/ResolverError.js +29 -0
- package/src/resolvedor/ResolverError.js.map +1 -0
- package/src/resolvedor/dialetos/egua-classico.js +331 -0
- package/src/resolvedor/dialetos/egua-classico.js.map +1 -0
- package/src/resolvedor/dialetos/index.js +14 -0
- package/src/resolvedor/dialetos/index.js.map +1 -0
- package/src/resolvedor/index.js +331 -0
- package/src/resolvedor/index.js.map +1 -0
- package/src/tiposDeSimbolos.js +25 -23
- package/src/tiposDeSimbolos.js.map +1 -0
- package/src/web.js +64 -68
- package/src/web.js.map +1 -0
- package/.github/CONTRIBUTING.md +0 -0
- package/.github/workflows/principal.yml +0 -20
- package/.release-it.json +0 -8
- package/.vscode/launch.json +0 -29
- package/.vscode/settings.json +0 -3
- package/LICENSE +0 -21
- package/babel.config.js +0 -1
- package/indice.js +0 -14
- package/src/erro.js +0 -18
- package/src/estruturas/funcaoPadrao.js +0 -18
- package/src/expr.js +0 -228
- package/src/interpretador.js +0 -802
- package/src/lexer.js +0 -316
- package/src/lib/globalLib.js +0 -171
- package/src/lib/importStdlib.js +0 -32
- package/src/parser.js +0 -822
- package/src/resolver.js +0 -425
- package/src/stmt.js +0 -215
- package/testes/testes.egua +0 -630
package/src/resolver.js
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
class ResolverError extends Error {
|
|
2
|
-
constructor(mensagem) {
|
|
3
|
-
super(mensagem);
|
|
4
|
-
this.mensagem = mensagem;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class Stack {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.stack = [];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
push(item) {
|
|
14
|
-
this.stack.push(item);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
isEmpty() {
|
|
18
|
-
return this.stack.length === 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
peek() {
|
|
22
|
-
if (this.isEmpty()) throw new Error("Pilha vazia.");
|
|
23
|
-
return this.stack[this.stack.length - 1];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
pop() {
|
|
27
|
-
if (this.isEmpty()) throw new Error("Pilha vazia.");
|
|
28
|
-
return this.stack.pop();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const FunctionType = {
|
|
33
|
-
NONE: "NONE",
|
|
34
|
-
FUNCAO: "FUNCAO",
|
|
35
|
-
CONSTRUTOR: "CONSTRUTOR",
|
|
36
|
-
METHOD: "METHOD"
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const ClassType = {
|
|
40
|
-
NONE: "NONE",
|
|
41
|
-
CLASSE: "CLASSE",
|
|
42
|
-
SUBCLASS: "SUBCLASS"
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const LoopType = {
|
|
46
|
-
NONE: "NONE",
|
|
47
|
-
ENQUANTO: "ENQUANTO",
|
|
48
|
-
ESCOLHA: "ESCOLHA",
|
|
49
|
-
PARA: "PARA",
|
|
50
|
-
FAZER: "FAZER"
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* O Resolvedor (Resolver) é responsável por catalogar todos os identificadores complexos, como por exemplo: funções, classes, variáveis,
|
|
55
|
-
* e delimitar os escopos onde esses identificadores existem.
|
|
56
|
-
* Exemplo: uma classe A declara dois métodos chamados M e N. Todas as variáveis declaradas dentro de M não podem ser vistas por N, e vice-versa.
|
|
57
|
-
* No entanto, todas as variáveis declaradas dentro da classe A podem ser vistas tanto por M quanto por N.
|
|
58
|
-
*/
|
|
59
|
-
module.exports = class Resolver {
|
|
60
|
-
constructor(interpretador, Delegua) {
|
|
61
|
-
this.interpretador = interpretador;
|
|
62
|
-
this.Delegua = Delegua;
|
|
63
|
-
this.escopos = new Stack();
|
|
64
|
-
|
|
65
|
-
this.FuncaoAtual = FunctionType.NONE;
|
|
66
|
-
this.ClasseAtual = ClassType.NONE;
|
|
67
|
-
this.cicloAtual = ClassType.NONE;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
definir(nome) {
|
|
71
|
-
if (this.escopos.isEmpty()) return;
|
|
72
|
-
this.escopos.peek()[nome.lexeme] = true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
declarar(nome) {
|
|
76
|
-
if (this.escopos.isEmpty()) return;
|
|
77
|
-
let escopo = this.escopos.peek();
|
|
78
|
-
if (escopo.hasOwnProperty(nome.lexeme))
|
|
79
|
-
this.Delegua.erro(
|
|
80
|
-
nome,
|
|
81
|
-
"Variável com esse nome já declarada neste escopo."
|
|
82
|
-
);
|
|
83
|
-
escopo[nome.lexeme] = false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
inicioDoEscopo() {
|
|
87
|
-
this.escopos.push({});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
finalDoEscopo() {
|
|
91
|
-
this.escopos.pop();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
resolver(declaracoes) {
|
|
95
|
-
if (Array.isArray(declaracoes)) {
|
|
96
|
-
for (let i = 0; i < declaracoes.length; i++) {
|
|
97
|
-
declaracoes[i].aceitar(this);
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
declaracoes.aceitar(this);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
resolverLocal(expr, nome) {
|
|
105
|
-
for (let i = this.escopos.stack.length - 1; i >= 0; i--) {
|
|
106
|
-
if (this.escopos.stack[i].hasOwnProperty(nome.lexeme)) {
|
|
107
|
-
this.interpretador.resolver(expr, this.escopos.stack.length - 1 - i);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
visitBlockStmt(stmt) {
|
|
113
|
-
this.inicioDoEscopo();
|
|
114
|
-
this.resolver(stmt.declaracoes);
|
|
115
|
-
this.finalDoEscopo();
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
visitVariableExpr(expr) {
|
|
120
|
-
if (
|
|
121
|
-
!this.escopos.isEmpty() &&
|
|
122
|
-
this.escopos.peek()[expr.nome.lexeme] === false
|
|
123
|
-
) {
|
|
124
|
-
throw new ResolverError(
|
|
125
|
-
"Não é possível ler a variável local em seu próprio inicializador."
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
this.resolverLocal(expr, expr.nome);
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
visitVarStmt(stmt) {
|
|
133
|
-
this.declarar(stmt.nome);
|
|
134
|
-
if (stmt.inicializador !== null) {
|
|
135
|
-
this.resolver(stmt.inicializador);
|
|
136
|
-
}
|
|
137
|
-
this.definir(stmt.nome);
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
visitAssignExpr(expr) {
|
|
142
|
-
this.resolver(expr.valor);
|
|
143
|
-
this.resolverLocal(expr, expr.nome);
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
resolverFuncao(funcao, funcType) {
|
|
148
|
-
let enclosingFunc = this.FuncaoAtual;
|
|
149
|
-
this.FuncaoAtual = funcType;
|
|
150
|
-
|
|
151
|
-
this.inicioDoEscopo();
|
|
152
|
-
let parametros = funcao.parametros;
|
|
153
|
-
for (let i = 0; i < parametros.length; i++) {
|
|
154
|
-
this.declarar(parametros[i]["nome"]);
|
|
155
|
-
this.definir(parametros[i]["nome"]);
|
|
156
|
-
}
|
|
157
|
-
this.resolver(funcao.corpo);
|
|
158
|
-
this.finalDoEscopo();
|
|
159
|
-
|
|
160
|
-
this.FuncaoAtual = enclosingFunc;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
visitFunctionStmt(stmt) {
|
|
164
|
-
this.declarar(stmt.nome);
|
|
165
|
-
this.definir(stmt.nome);
|
|
166
|
-
|
|
167
|
-
this.resolverFuncao(stmt.funcao, FunctionType.FUNCAO);
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
visitFunctionExpr(stmt) {
|
|
172
|
-
this.resolverFuncao(stmt, FunctionType.FUNCAO);
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
visitTryStmt(stmt) {
|
|
177
|
-
this.resolver(stmt.tryBranch);
|
|
178
|
-
|
|
179
|
-
if (stmt.catchBranch !== null) this.resolver(stmt.catchBranch);
|
|
180
|
-
if (stmt.elseBranch !== null) this.resolver(stmt.elseBranch);
|
|
181
|
-
if (stmt.finallyBranch !== null) this.resolver(stmt.finallyBranch);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
visitClassStmt(stmt) {
|
|
185
|
-
let enclosingClass = this.ClasseAtual;
|
|
186
|
-
this.ClasseAtual = ClassType.CLASSE;
|
|
187
|
-
|
|
188
|
-
this.declarar(stmt.nome);
|
|
189
|
-
this.definir(stmt.nome);
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
stmt.superClasse !== null &&
|
|
193
|
-
stmt.nome.lexeme === stmt.superClasse.nome.lexeme
|
|
194
|
-
) {
|
|
195
|
-
this.Delegua.error("Uma classe não pode herdar de si mesma.");
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (stmt.superClasse !== null) {
|
|
199
|
-
this.ClasseAtual = ClassType.SUBCLASS;
|
|
200
|
-
this.resolver(stmt.superClasse);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (stmt.superClasse !== null) {
|
|
204
|
-
this.inicioDoEscopo();
|
|
205
|
-
this.escopos.peek()["super"] = true;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
this.inicioDoEscopo();
|
|
209
|
-
this.escopos.peek()["isto"] = true;
|
|
210
|
-
|
|
211
|
-
let metodos = stmt.metodos;
|
|
212
|
-
for (let i = 0; i < metodos.length; i++) {
|
|
213
|
-
let declaracao = FunctionType.METHOD;
|
|
214
|
-
|
|
215
|
-
if (metodos[i].nome.lexeme === "isto") {
|
|
216
|
-
declaracao = FunctionType.CONSTRUTOR;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
this.resolverFuncao(metodos[i].funcao, declaracao);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
this.finalDoEscopo();
|
|
223
|
-
|
|
224
|
-
if (stmt.superClasse !== null) this.finalDoEscopo();
|
|
225
|
-
|
|
226
|
-
this.ClasseAtual = enclosingClass;
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
visitSuperExpr(expr) {
|
|
231
|
-
if (this.ClasseAtual === ClassType.NONE) {
|
|
232
|
-
this.Delegua.error(expr.palavraChave, "Não pode usar 'super' fora de uma classe.");
|
|
233
|
-
} else if (this.ClasseAtual !== ClassType.SUBCLASS) {
|
|
234
|
-
this.Delegua.error(
|
|
235
|
-
expr.palavraChave,
|
|
236
|
-
"Não se usa 'super' numa classe sem SuperClasse."
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
this.resolverLocal(expr, expr.palavraChave);
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
visitGetExpr(expr) {
|
|
245
|
-
this.resolver(expr.objeto);
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
visitExpressionStmt(stmt) {
|
|
250
|
-
this.resolver(stmt.expressao);
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
visitIfStmt(stmt) {
|
|
255
|
-
this.resolver(stmt.condicao);
|
|
256
|
-
this.resolver(stmt.thenBranch);
|
|
257
|
-
|
|
258
|
-
for (let i = 0; i < stmt.elifBranches.length; i++) {
|
|
259
|
-
this.resolver(stmt.elifBranches[i].condicao);
|
|
260
|
-
this.resolver(stmt.elifBranches[i].branch);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (stmt.elseBranch !== null) this.resolver(stmt.elseBranch);
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
visitImportStmt(stmt) {
|
|
268
|
-
this.resolver(stmt.caminho);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
visitPrintStmt(stmt) {
|
|
272
|
-
this.resolver(stmt.expressao);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
visitReturnStmt(stmt) {
|
|
276
|
-
if (this.FuncaoAtual === FunctionType.NONE) {
|
|
277
|
-
this.Delegua.error(stmt.palavraChave, "Não é possível retornar do código do escopo superior.");
|
|
278
|
-
}
|
|
279
|
-
if (stmt.valor !== null) {
|
|
280
|
-
if (this.FuncaoAtual === FunctionType.CONSTRUTOR) {
|
|
281
|
-
this.Delegua.error(
|
|
282
|
-
stmt.palavraChave,
|
|
283
|
-
"Não pode retornar o valor do construtor."
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
this.resolver(stmt.valor);
|
|
287
|
-
}
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
visitSwitchStmt(stmt) {
|
|
292
|
-
let enclosingType = this.cicloAtual;
|
|
293
|
-
this.cicloAtual = LoopType.ESCOLHA;
|
|
294
|
-
|
|
295
|
-
let branches = stmt.branches;
|
|
296
|
-
let defaultBranch = stmt.defaultBranch;
|
|
297
|
-
|
|
298
|
-
for (let i = 0; i < branches.length; i++) {
|
|
299
|
-
this.resolver(branches[i]["stmts"]);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (defaultBranch !== null) this.resolver(defaultBranch["stmts"]);
|
|
303
|
-
|
|
304
|
-
this.cicloAtual = enclosingType;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
visitWhileStmt(stmt) {
|
|
308
|
-
this.resolver(stmt.condicao);
|
|
309
|
-
this.resolver(stmt.corpo);
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
visitForStmt(stmt) {
|
|
314
|
-
if (stmt.inicializador !== null) {
|
|
315
|
-
this.resolver(stmt.inicializador);
|
|
316
|
-
}
|
|
317
|
-
if (stmt.condicao !== null) {
|
|
318
|
-
this.resolver(stmt.condicao);
|
|
319
|
-
}
|
|
320
|
-
if (stmt.incrementar !== null) {
|
|
321
|
-
this.resolver(stmt.incrementar);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
let enclosingType = this.cicloAtual;
|
|
325
|
-
this.cicloAtual = LoopType.ENQUANTO;
|
|
326
|
-
this.resolver(stmt.corpo);
|
|
327
|
-
this.cicloAtual = enclosingType;
|
|
328
|
-
|
|
329
|
-
return null;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
visitDoStmt(stmt) {
|
|
333
|
-
this.resolver(stmt.whileCondition);
|
|
334
|
-
|
|
335
|
-
let enclosingType = this.cicloAtual;
|
|
336
|
-
this.cicloAtual = LoopType.FAZER;
|
|
337
|
-
this.resolver(stmt.doBranch);
|
|
338
|
-
this.cicloAtual = enclosingType;
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
visitBinaryExpr(expr) {
|
|
343
|
-
this.resolver(expr.esquerda);
|
|
344
|
-
this.resolver(expr.direita);
|
|
345
|
-
return null;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
visitCallExpr(expr) {
|
|
349
|
-
this.resolver(expr.callee);
|
|
350
|
-
|
|
351
|
-
let argumentos = expr.argumentos;
|
|
352
|
-
for (let i = 0; i < argumentos.length; i++) {
|
|
353
|
-
this.resolver(argumentos[i]);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
return null;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
visitGroupingExpr(expr) {
|
|
360
|
-
this.resolver(expr.expressao);
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
visitDictionaryExpr(expr) {
|
|
365
|
-
for (let i = 0; i < expr.chaves.length; i++) {
|
|
366
|
-
this.resolver(expr.chaves[i]);
|
|
367
|
-
this.resolver(expr.valores[i]);
|
|
368
|
-
}
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
visitArrayExpr(expr) {
|
|
373
|
-
for (let i = 0; i < expr.valores.length; i++) {
|
|
374
|
-
this.resolver(expr.valores[i]);
|
|
375
|
-
}
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
visitSubscriptExpr(expr) {
|
|
380
|
-
this.resolver(expr.callee);
|
|
381
|
-
this.resolver(expr.indice);
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
visitContinueStmt(stmt) {
|
|
386
|
-
return null;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
visitBreakStmt(stmt) {
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
visitAssignsubscriptExpr(expr) {
|
|
394
|
-
return null;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
visitLiteralExpr(expr) {
|
|
398
|
-
return null;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
visitLogicalExpr(expr) {
|
|
402
|
-
this.resolver(expr.esquerda);
|
|
403
|
-
this.resolver(expr.direita);
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
visitUnaryExpr(expr) {
|
|
408
|
-
this.resolver(expr.direita);
|
|
409
|
-
return null;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
visitSetExpr(expr) {
|
|
413
|
-
this.resolver(expr.valor);
|
|
414
|
-
this.resolver(expr.objeto);
|
|
415
|
-
return null;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
visitThisExpr(expr) {
|
|
419
|
-
if (this.ClasseAtual == ClassType.NONE) {
|
|
420
|
-
this.Delegua.error(expr.palavraChave, "Não pode usar 'isto' fora da classe.");
|
|
421
|
-
}
|
|
422
|
-
this.resolverLocal(expr, expr.palavraChave);
|
|
423
|
-
return null;
|
|
424
|
-
}
|
|
425
|
-
};
|
package/src/stmt.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
class Stmt {
|
|
2
|
-
aceitar(visitor) { }
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
class Expressao extends Stmt {
|
|
6
|
-
constructor(expressao) {
|
|
7
|
-
super();
|
|
8
|
-
this.expressao = expressao;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
aceitar(visitor) {
|
|
12
|
-
return visitor.visitExpressionStmt(this)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class Funcao extends Stmt {
|
|
17
|
-
constructor(nome, funcao) {
|
|
18
|
-
super();
|
|
19
|
-
this.nome = nome;
|
|
20
|
-
this.funcao = funcao;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
aceitar(visitor) {
|
|
24
|
-
return visitor.visitFunctionStmt(this);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
class Retorna extends Stmt {
|
|
29
|
-
constructor(palavraChave, valor) {
|
|
30
|
-
super();
|
|
31
|
-
this.palavraChave = palavraChave;
|
|
32
|
-
this.valor = valor;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
aceitar(visitor) {
|
|
36
|
-
return visitor.visitReturnStmt(this);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class Classe extends Stmt {
|
|
41
|
-
constructor(nome, superClasse, metodos) {
|
|
42
|
-
super();
|
|
43
|
-
this.nome = nome;
|
|
44
|
-
this.superClasse = superClasse;
|
|
45
|
-
this.metodos = metodos;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
aceitar(visitor) {
|
|
49
|
-
return visitor.visitClassStmt(this);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class Block extends Stmt {
|
|
54
|
-
constructor(declaracoes) {
|
|
55
|
-
super();
|
|
56
|
-
this.declaracoes = declaracoes;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
aceitar(visitor) {
|
|
60
|
-
return visitor.visitBlockStmt(this);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
class Escreva extends Stmt {
|
|
65
|
-
constructor(expressao) {
|
|
66
|
-
super();
|
|
67
|
-
this.expressao = expressao;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
aceitar(visitor) {
|
|
71
|
-
return visitor.visitPrintStmt(this);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
class Importar extends Stmt {
|
|
76
|
-
constructor(caminho, closeBracket) {
|
|
77
|
-
super();
|
|
78
|
-
this.caminho = caminho;
|
|
79
|
-
this.closeBracket = closeBracket;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
aceitar(visitor) {
|
|
83
|
-
return visitor.visitImportStmt(this);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
class Fazer extends Stmt {
|
|
88
|
-
constructor(doBranch, whileCondition) {
|
|
89
|
-
super();
|
|
90
|
-
this.doBranch = doBranch;
|
|
91
|
-
this.whileCondition = whileCondition;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
aceitar(visitor) {
|
|
95
|
-
return visitor.visitDoStmt(this);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
class Enquanto extends Stmt {
|
|
100
|
-
constructor(condicao, corpo) {
|
|
101
|
-
super();
|
|
102
|
-
this.condicao = condicao;
|
|
103
|
-
this.corpo = corpo;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
aceitar(visitor) {
|
|
107
|
-
return visitor.visitWhileStmt(this);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
class Para extends Stmt {
|
|
112
|
-
constructor(inicializador, condicao, incrementar, corpo) {
|
|
113
|
-
super();
|
|
114
|
-
this.inicializador = inicializador;
|
|
115
|
-
this.condicao = condicao;
|
|
116
|
-
this.incrementar = incrementar;
|
|
117
|
-
this.corpo = corpo;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
aceitar(visitor) {
|
|
121
|
-
return visitor.visitForStmt(this);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
class Tente extends Stmt {
|
|
126
|
-
constructor(tryBranch, catchBranch, elseBranch, finallyBranch) {
|
|
127
|
-
super();
|
|
128
|
-
this.tryBranch = tryBranch;
|
|
129
|
-
this.catchBranch = catchBranch;
|
|
130
|
-
this.elseBranch = elseBranch;
|
|
131
|
-
this.finallyBranch = finallyBranch;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
aceitar(visitor) {
|
|
135
|
-
return visitor.visitTryStmt(this);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
class Se extends Stmt {
|
|
140
|
-
constructor(condicao, thenBranch, elifBranches, elseBranch) {
|
|
141
|
-
super();
|
|
142
|
-
this.condicao = condicao;
|
|
143
|
-
this.thenBranch = thenBranch;
|
|
144
|
-
this.elifBranches = elifBranches;
|
|
145
|
-
this.elseBranch = elseBranch;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
aceitar(visitor) {
|
|
149
|
-
return visitor.visitIfStmt(this);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
class Escolha extends Stmt {
|
|
154
|
-
constructor(condicao, branches, defaultBranch) {
|
|
155
|
-
super();
|
|
156
|
-
this.condicao = condicao;
|
|
157
|
-
this.branches = branches;
|
|
158
|
-
this.defaultBranch = defaultBranch;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
aceitar(visitor) {
|
|
162
|
-
return visitor.visitSwitchStmt(this);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
class Pausa extends Stmt {
|
|
167
|
-
constructor() {
|
|
168
|
-
super();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
aceitar(visitor) {
|
|
172
|
-
return visitor.visitBreakStmt(this);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
class Continua extends Stmt {
|
|
177
|
-
constructor() {
|
|
178
|
-
super();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
aceitar(visitor) {
|
|
182
|
-
return visitor.visitContinueStmt(this);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
class Var extends Stmt {
|
|
187
|
-
constructor(nome, inicializador) {
|
|
188
|
-
super();
|
|
189
|
-
this.nome = nome;
|
|
190
|
-
this.inicializador = inicializador;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
aceitar(visitor) {
|
|
194
|
-
return visitor.visitVarStmt(this);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
module.exports = {
|
|
199
|
-
Expressao,
|
|
200
|
-
Funcao,
|
|
201
|
-
Retorna,
|
|
202
|
-
Classe,
|
|
203
|
-
Block,
|
|
204
|
-
Escreva,
|
|
205
|
-
Importar,
|
|
206
|
-
Fazer,
|
|
207
|
-
Enquanto,
|
|
208
|
-
Para,
|
|
209
|
-
Tente,
|
|
210
|
-
Se,
|
|
211
|
-
Escolha,
|
|
212
|
-
Pausa,
|
|
213
|
-
Continua,
|
|
214
|
-
Var
|
|
215
|
-
};
|