@designliquido/delegua 0.0.1 → 0.0.2
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/.github/CONTRIBUTING.md +0 -0
- package/.github/workflows/principal.yml +20 -0
- package/.release-it.json +8 -0
- package/.vscode/launch.json +2 -2
- package/README.md +5 -6
- package/bin/delegua +1 -1
- package/bin/delegua.cmd +1 -0
- package/indice.js +14 -0
- package/package.json +46 -37
- package/src/ambiente.js +53 -0
- package/src/{egua.js → delegua.js} +20 -20
- package/src/erro.js +18 -0
- package/src/estruturas/callable.js +5 -0
- package/src/estruturas/classe.js +43 -0
- package/src/estruturas/funcao.js +62 -0
- package/src/estruturas/funcaoPadrao.js +18 -0
- package/src/estruturas/instancia.js +27 -0
- package/src/estruturas/modulo.js +9 -0
- package/src/expr.js +52 -52
- package/src/interpretador.js +802 -0
- package/src/lexer.js +90 -89
- package/src/lib/globalLib.js +63 -63
- package/src/lib/importStdlib.js +18 -27
- package/src/parser.js +219 -223
- package/src/resolver.js +93 -93
- package/src/stmt.js +34 -34
- package/src/{tokenTypes.js → tiposDeSimbolos.js} +21 -21
- package/src/web.js +41 -41
- package/testes/testes.egua +363 -364
- package/index.html +0 -43
- package/index.js +0 -14
- package/src/environment.js +0 -53
- package/src/errors.js +0 -17
- package/src/interpreter.js +0 -798
- package/src/lib/__tests__/eguamat.test.js +0 -101
- package/src/lib/eguamat.js +0 -725
- package/src/lib/tempo.js +0 -50
- package/src/structures/callable.js +0 -5
- package/src/structures/class.js +0 -43
- package/src/structures/function.js +0 -62
- package/src/structures/instance.js +0 -27
- package/src/structures/module.js +0 -9
- package/src/structures/standardFn.js +0 -18
package/src/resolver.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class ResolverError extends Error {
|
|
2
|
-
constructor(
|
|
3
|
-
super(
|
|
4
|
-
this.
|
|
2
|
+
constructor(mensagem) {
|
|
3
|
+
super(mensagem);
|
|
4
|
+
this.mensagem = mensagem;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -57,9 +57,9 @@ const LoopType = {
|
|
|
57
57
|
* No entanto, todas as variáveis declaradas dentro da classe A podem ser vistas tanto por M quanto por N.
|
|
58
58
|
*/
|
|
59
59
|
module.exports = class Resolver {
|
|
60
|
-
constructor(
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
60
|
+
constructor(interpretador, Delegua) {
|
|
61
|
+
this.interpretador = interpretador;
|
|
62
|
+
this.Delegua = Delegua;
|
|
63
63
|
this.escopos = new Stack();
|
|
64
64
|
|
|
65
65
|
this.FuncaoAtual = FunctionType.NONE;
|
|
@@ -67,20 +67,20 @@ module.exports = class Resolver {
|
|
|
67
67
|
this.cicloAtual = ClassType.NONE;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
definir(
|
|
70
|
+
definir(nome) {
|
|
71
71
|
if (this.escopos.isEmpty()) return;
|
|
72
|
-
this.escopos.peek()[
|
|
72
|
+
this.escopos.peek()[nome.lexeme] = true;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
declarar(
|
|
75
|
+
declarar(nome) {
|
|
76
76
|
if (this.escopos.isEmpty()) return;
|
|
77
77
|
let escopo = this.escopos.peek();
|
|
78
|
-
if (escopo.hasOwnProperty(
|
|
79
|
-
this.
|
|
80
|
-
|
|
78
|
+
if (escopo.hasOwnProperty(nome.lexeme))
|
|
79
|
+
this.Delegua.erro(
|
|
80
|
+
nome,
|
|
81
81
|
"Variável com esse nome já declarada neste escopo."
|
|
82
82
|
);
|
|
83
|
-
escopo[
|
|
83
|
+
escopo[nome.lexeme] = false;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
inicioDoEscopo() {
|
|
@@ -91,27 +91,27 @@ module.exports = class Resolver {
|
|
|
91
91
|
this.escopos.pop();
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
resolver(
|
|
95
|
-
if (Array.isArray(
|
|
96
|
-
for (let i = 0; i <
|
|
97
|
-
|
|
94
|
+
resolver(declaracoes) {
|
|
95
|
+
if (Array.isArray(declaracoes)) {
|
|
96
|
+
for (let i = 0; i < declaracoes.length; i++) {
|
|
97
|
+
declaracoes[i].aceitar(this);
|
|
98
98
|
}
|
|
99
99
|
} else {
|
|
100
|
-
|
|
100
|
+
declaracoes.aceitar(this);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
resolverLocal(expr,
|
|
104
|
+
resolverLocal(expr, nome) {
|
|
105
105
|
for (let i = this.escopos.stack.length - 1; i >= 0; i--) {
|
|
106
|
-
if (this.escopos.stack[i].hasOwnProperty(
|
|
107
|
-
this.
|
|
106
|
+
if (this.escopos.stack[i].hasOwnProperty(nome.lexeme)) {
|
|
107
|
+
this.interpretador.resolver(expr, this.escopos.stack.length - 1 - i);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
visitBlockStmt(stmt) {
|
|
113
113
|
this.inicioDoEscopo();
|
|
114
|
-
this.resolver(stmt.
|
|
114
|
+
this.resolver(stmt.declaracoes);
|
|
115
115
|
this.finalDoEscopo();
|
|
116
116
|
return null;
|
|
117
117
|
}
|
|
@@ -119,28 +119,28 @@ module.exports = class Resolver {
|
|
|
119
119
|
visitVariableExpr(expr) {
|
|
120
120
|
if (
|
|
121
121
|
!this.escopos.isEmpty() &&
|
|
122
|
-
this.escopos.peek()[expr.
|
|
122
|
+
this.escopos.peek()[expr.nome.lexeme] === false
|
|
123
123
|
) {
|
|
124
124
|
throw new ResolverError(
|
|
125
125
|
"Não é possível ler a variável local em seu próprio inicializador."
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
|
-
this.resolverLocal(expr, expr.
|
|
128
|
+
this.resolverLocal(expr, expr.nome);
|
|
129
129
|
return null;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
visitVarStmt(stmt) {
|
|
133
|
-
this.declarar(stmt.
|
|
134
|
-
if (stmt.
|
|
135
|
-
this.resolver(stmt.
|
|
133
|
+
this.declarar(stmt.nome);
|
|
134
|
+
if (stmt.inicializador !== null) {
|
|
135
|
+
this.resolver(stmt.inicializador);
|
|
136
136
|
}
|
|
137
|
-
this.definir(stmt.
|
|
137
|
+
this.definir(stmt.nome);
|
|
138
138
|
return null;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
visitAssignExpr(expr) {
|
|
142
|
-
this.resolver(expr.
|
|
143
|
-
this.resolverLocal(expr, expr.
|
|
142
|
+
this.resolver(expr.valor);
|
|
143
|
+
this.resolverLocal(expr, expr.nome);
|
|
144
144
|
return null;
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -149,22 +149,22 @@ module.exports = class Resolver {
|
|
|
149
149
|
this.FuncaoAtual = funcType;
|
|
150
150
|
|
|
151
151
|
this.inicioDoEscopo();
|
|
152
|
-
let parametros = funcao.
|
|
152
|
+
let parametros = funcao.parametros;
|
|
153
153
|
for (let i = 0; i < parametros.length; i++) {
|
|
154
|
-
this.declarar(parametros[i]["
|
|
155
|
-
this.definir(parametros[i]["
|
|
154
|
+
this.declarar(parametros[i]["nome"]);
|
|
155
|
+
this.definir(parametros[i]["nome"]);
|
|
156
156
|
}
|
|
157
|
-
this.resolver(funcao.
|
|
157
|
+
this.resolver(funcao.corpo);
|
|
158
158
|
this.finalDoEscopo();
|
|
159
159
|
|
|
160
160
|
this.FuncaoAtual = enclosingFunc;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
visitFunctionStmt(stmt) {
|
|
164
|
-
this.declarar(stmt.
|
|
165
|
-
this.definir(stmt.
|
|
164
|
+
this.declarar(stmt.nome);
|
|
165
|
+
this.definir(stmt.nome);
|
|
166
166
|
|
|
167
|
-
this.resolverFuncao(stmt.
|
|
167
|
+
this.resolverFuncao(stmt.funcao, FunctionType.FUNCAO);
|
|
168
168
|
return null;
|
|
169
169
|
}
|
|
170
170
|
|
|
@@ -185,22 +185,22 @@ module.exports = class Resolver {
|
|
|
185
185
|
let enclosingClass = this.ClasseAtual;
|
|
186
186
|
this.ClasseAtual = ClassType.CLASSE;
|
|
187
187
|
|
|
188
|
-
this.declarar(stmt.
|
|
189
|
-
this.definir(stmt.
|
|
188
|
+
this.declarar(stmt.nome);
|
|
189
|
+
this.definir(stmt.nome);
|
|
190
190
|
|
|
191
191
|
if (
|
|
192
|
-
stmt.
|
|
193
|
-
stmt.
|
|
192
|
+
stmt.superClasse !== null &&
|
|
193
|
+
stmt.nome.lexeme === stmt.superClasse.nome.lexeme
|
|
194
194
|
) {
|
|
195
|
-
this.
|
|
195
|
+
this.Delegua.error("Uma classe não pode herdar de si mesma.");
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
if (stmt.
|
|
198
|
+
if (stmt.superClasse !== null) {
|
|
199
199
|
this.ClasseAtual = ClassType.SUBCLASS;
|
|
200
|
-
this.resolver(stmt.
|
|
200
|
+
this.resolver(stmt.superClasse);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
if (stmt.
|
|
203
|
+
if (stmt.superClasse !== null) {
|
|
204
204
|
this.inicioDoEscopo();
|
|
205
205
|
this.escopos.peek()["super"] = true;
|
|
206
206
|
}
|
|
@@ -208,20 +208,20 @@ module.exports = class Resolver {
|
|
|
208
208
|
this.inicioDoEscopo();
|
|
209
209
|
this.escopos.peek()["isto"] = true;
|
|
210
210
|
|
|
211
|
-
let metodos = stmt.
|
|
211
|
+
let metodos = stmt.metodos;
|
|
212
212
|
for (let i = 0; i < metodos.length; i++) {
|
|
213
213
|
let declaracao = FunctionType.METHOD;
|
|
214
214
|
|
|
215
|
-
if (metodos[i].
|
|
215
|
+
if (metodos[i].nome.lexeme === "isto") {
|
|
216
216
|
declaracao = FunctionType.CONSTRUTOR;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
this.resolverFuncao(metodos[i].
|
|
219
|
+
this.resolverFuncao(metodos[i].funcao, declaracao);
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
this.finalDoEscopo();
|
|
223
223
|
|
|
224
|
-
if (stmt.
|
|
224
|
+
if (stmt.superClasse !== null) this.finalDoEscopo();
|
|
225
225
|
|
|
226
226
|
this.ClasseAtual = enclosingClass;
|
|
227
227
|
return null;
|
|
@@ -229,34 +229,34 @@ module.exports = class Resolver {
|
|
|
229
229
|
|
|
230
230
|
visitSuperExpr(expr) {
|
|
231
231
|
if (this.ClasseAtual === ClassType.NONE) {
|
|
232
|
-
this.
|
|
232
|
+
this.Delegua.error(expr.palavraChave, "Não pode usar 'super' fora de uma classe.");
|
|
233
233
|
} else if (this.ClasseAtual !== ClassType.SUBCLASS) {
|
|
234
|
-
this.
|
|
235
|
-
expr.
|
|
236
|
-
"Não se usa 'super' numa classe sem
|
|
234
|
+
this.Delegua.error(
|
|
235
|
+
expr.palavraChave,
|
|
236
|
+
"Não se usa 'super' numa classe sem SuperClasse."
|
|
237
237
|
);
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
this.resolverLocal(expr, expr.
|
|
240
|
+
this.resolverLocal(expr, expr.palavraChave);
|
|
241
241
|
return null;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
visitGetExpr(expr) {
|
|
245
|
-
this.resolver(expr.
|
|
245
|
+
this.resolver(expr.objeto);
|
|
246
246
|
return null;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
visitExpressionStmt(stmt) {
|
|
250
|
-
this.resolver(stmt.
|
|
250
|
+
this.resolver(stmt.expressao);
|
|
251
251
|
return null;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
visitIfStmt(stmt) {
|
|
255
|
-
this.resolver(stmt.
|
|
255
|
+
this.resolver(stmt.condicao);
|
|
256
256
|
this.resolver(stmt.thenBranch);
|
|
257
257
|
|
|
258
258
|
for (let i = 0; i < stmt.elifBranches.length; i++) {
|
|
259
|
-
this.resolver(stmt.elifBranches[i].
|
|
259
|
+
this.resolver(stmt.elifBranches[i].condicao);
|
|
260
260
|
this.resolver(stmt.elifBranches[i].branch);
|
|
261
261
|
}
|
|
262
262
|
|
|
@@ -265,25 +265,25 @@ module.exports = class Resolver {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
visitImportStmt(stmt) {
|
|
268
|
-
this.resolver(stmt.
|
|
268
|
+
this.resolver(stmt.caminho);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
visitPrintStmt(stmt) {
|
|
272
|
-
this.resolver(stmt.
|
|
272
|
+
this.resolver(stmt.expressao);
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
visitReturnStmt(stmt) {
|
|
276
276
|
if (this.FuncaoAtual === FunctionType.NONE) {
|
|
277
|
-
this.
|
|
277
|
+
this.Delegua.error(stmt.palavraChave, "Não é possível retornar do código do escopo superior.");
|
|
278
278
|
}
|
|
279
|
-
if (stmt.
|
|
279
|
+
if (stmt.valor !== null) {
|
|
280
280
|
if (this.FuncaoAtual === FunctionType.CONSTRUTOR) {
|
|
281
|
-
this.
|
|
282
|
-
stmt.
|
|
281
|
+
this.Delegua.error(
|
|
282
|
+
stmt.palavraChave,
|
|
283
283
|
"Não pode retornar o valor do construtor."
|
|
284
284
|
);
|
|
285
285
|
}
|
|
286
|
-
this.resolver(stmt.
|
|
286
|
+
this.resolver(stmt.valor);
|
|
287
287
|
}
|
|
288
288
|
return null;
|
|
289
289
|
}
|
|
@@ -305,25 +305,25 @@ module.exports = class Resolver {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
visitWhileStmt(stmt) {
|
|
308
|
-
this.resolver(stmt.
|
|
309
|
-
this.resolver(stmt.
|
|
308
|
+
this.resolver(stmt.condicao);
|
|
309
|
+
this.resolver(stmt.corpo);
|
|
310
310
|
return null;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
visitForStmt(stmt) {
|
|
314
|
-
if (stmt.
|
|
315
|
-
this.resolver(stmt.
|
|
314
|
+
if (stmt.inicializador !== null) {
|
|
315
|
+
this.resolver(stmt.inicializador);
|
|
316
316
|
}
|
|
317
|
-
if (stmt.
|
|
318
|
-
this.resolver(stmt.
|
|
317
|
+
if (stmt.condicao !== null) {
|
|
318
|
+
this.resolver(stmt.condicao);
|
|
319
319
|
}
|
|
320
|
-
if (stmt.
|
|
321
|
-
this.resolver(stmt.
|
|
320
|
+
if (stmt.incrementar !== null) {
|
|
321
|
+
this.resolver(stmt.incrementar);
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
let enclosingType = this.cicloAtual;
|
|
325
325
|
this.cicloAtual = LoopType.ENQUANTO;
|
|
326
|
-
this.resolver(stmt.
|
|
326
|
+
this.resolver(stmt.corpo);
|
|
327
327
|
this.cicloAtual = enclosingType;
|
|
328
328
|
|
|
329
329
|
return null;
|
|
@@ -340,45 +340,45 @@ module.exports = class Resolver {
|
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
visitBinaryExpr(expr) {
|
|
343
|
-
this.resolver(expr.
|
|
344
|
-
this.resolver(expr.
|
|
343
|
+
this.resolver(expr.esquerda);
|
|
344
|
+
this.resolver(expr.direita);
|
|
345
345
|
return null;
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
visitCallExpr(expr) {
|
|
349
349
|
this.resolver(expr.callee);
|
|
350
350
|
|
|
351
|
-
let
|
|
352
|
-
for (let i = 0; i <
|
|
353
|
-
this.resolver(
|
|
351
|
+
let argumentos = expr.argumentos;
|
|
352
|
+
for (let i = 0; i < argumentos.length; i++) {
|
|
353
|
+
this.resolver(argumentos[i]);
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
return null;
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
visitGroupingExpr(expr) {
|
|
360
|
-
this.resolver(expr.
|
|
360
|
+
this.resolver(expr.expressao);
|
|
361
361
|
return null;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
visitDictionaryExpr(expr) {
|
|
365
|
-
for (let i = 0; i < expr.
|
|
366
|
-
this.resolver(expr.
|
|
367
|
-
this.resolver(expr.
|
|
365
|
+
for (let i = 0; i < expr.chaves.length; i++) {
|
|
366
|
+
this.resolver(expr.chaves[i]);
|
|
367
|
+
this.resolver(expr.valores[i]);
|
|
368
368
|
}
|
|
369
369
|
return null;
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
visitArrayExpr(expr) {
|
|
373
|
-
for (let i = 0; i < expr.
|
|
374
|
-
this.resolver(expr.
|
|
373
|
+
for (let i = 0; i < expr.valores.length; i++) {
|
|
374
|
+
this.resolver(expr.valores[i]);
|
|
375
375
|
}
|
|
376
376
|
return null;
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
visitSubscriptExpr(expr) {
|
|
380
380
|
this.resolver(expr.callee);
|
|
381
|
-
this.resolver(expr.
|
|
381
|
+
this.resolver(expr.indice);
|
|
382
382
|
return null;
|
|
383
383
|
}
|
|
384
384
|
|
|
@@ -399,27 +399,27 @@ module.exports = class Resolver {
|
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
visitLogicalExpr(expr) {
|
|
402
|
-
this.resolver(expr.
|
|
403
|
-
this.resolver(expr.
|
|
402
|
+
this.resolver(expr.esquerda);
|
|
403
|
+
this.resolver(expr.direita);
|
|
404
404
|
return null;
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
visitUnaryExpr(expr) {
|
|
408
|
-
this.resolver(expr.
|
|
408
|
+
this.resolver(expr.direita);
|
|
409
409
|
return null;
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
visitSetExpr(expr) {
|
|
413
|
-
this.resolver(expr.
|
|
414
|
-
this.resolver(expr.
|
|
413
|
+
this.resolver(expr.valor);
|
|
414
|
+
this.resolver(expr.objeto);
|
|
415
415
|
return null;
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
visitThisExpr(expr) {
|
|
419
419
|
if (this.ClasseAtual == ClassType.NONE) {
|
|
420
|
-
this.
|
|
420
|
+
this.Delegua.error(expr.palavraChave, "Não pode usar 'isto' fora da classe.");
|
|
421
421
|
}
|
|
422
|
-
this.resolverLocal(expr, expr.
|
|
422
|
+
this.resolverLocal(expr, expr.palavraChave);
|
|
423
423
|
return null;
|
|
424
424
|
}
|
|
425
425
|
};
|
package/src/stmt.js
CHANGED
|
@@ -2,10 +2,10 @@ class Stmt {
|
|
|
2
2
|
aceitar(visitor) { }
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
5
|
+
class Expressao extends Stmt {
|
|
6
|
+
constructor(expressao) {
|
|
7
7
|
super();
|
|
8
|
-
this.
|
|
8
|
+
this.expressao = expressao;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
aceitar(visitor) {
|
|
@@ -14,10 +14,10 @@ class Expression extends Stmt {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
class Funcao extends Stmt {
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(nome, funcao) {
|
|
18
18
|
super();
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
19
|
+
this.nome = nome;
|
|
20
|
+
this.funcao = funcao;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
aceitar(visitor) {
|
|
@@ -26,10 +26,10 @@ class Funcao extends Stmt {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
class Retorna extends Stmt {
|
|
29
|
-
constructor(
|
|
29
|
+
constructor(palavraChave, valor) {
|
|
30
30
|
super();
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
31
|
+
this.palavraChave = palavraChave;
|
|
32
|
+
this.valor = valor;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
aceitar(visitor) {
|
|
@@ -40,9 +40,9 @@ class Retorna extends Stmt {
|
|
|
40
40
|
class Classe extends Stmt {
|
|
41
41
|
constructor(nome, superClasse, metodos) {
|
|
42
42
|
super();
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
43
|
+
this.nome = nome;
|
|
44
|
+
this.superClasse = superClasse;
|
|
45
|
+
this.metodos = metodos;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
aceitar(visitor) {
|
|
@@ -51,9 +51,9 @@ class Classe extends Stmt {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
class Block extends Stmt {
|
|
54
|
-
constructor(
|
|
54
|
+
constructor(declaracoes) {
|
|
55
55
|
super();
|
|
56
|
-
this.
|
|
56
|
+
this.declaracoes = declaracoes;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
aceitar(visitor) {
|
|
@@ -62,9 +62,9 @@ class Block extends Stmt {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
class Escreva extends Stmt {
|
|
65
|
-
constructor(
|
|
65
|
+
constructor(expressao) {
|
|
66
66
|
super();
|
|
67
|
-
this.
|
|
67
|
+
this.expressao = expressao;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
aceitar(visitor) {
|
|
@@ -73,9 +73,9 @@ class Escreva extends Stmt {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
class Importar extends Stmt {
|
|
76
|
-
constructor(
|
|
76
|
+
constructor(caminho, closeBracket) {
|
|
77
77
|
super();
|
|
78
|
-
this.
|
|
78
|
+
this.caminho = caminho;
|
|
79
79
|
this.closeBracket = closeBracket;
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -97,10 +97,10 @@ class Fazer extends Stmt {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
class Enquanto extends Stmt {
|
|
100
|
-
constructor(
|
|
100
|
+
constructor(condicao, corpo) {
|
|
101
101
|
super();
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
102
|
+
this.condicao = condicao;
|
|
103
|
+
this.corpo = corpo;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
aceitar(visitor) {
|
|
@@ -109,12 +109,12 @@ class Enquanto extends Stmt {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
class Para extends Stmt {
|
|
112
|
-
constructor(
|
|
112
|
+
constructor(inicializador, condicao, incrementar, corpo) {
|
|
113
113
|
super();
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
114
|
+
this.inicializador = inicializador;
|
|
115
|
+
this.condicao = condicao;
|
|
116
|
+
this.incrementar = incrementar;
|
|
117
|
+
this.corpo = corpo;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
aceitar(visitor) {
|
|
@@ -137,9 +137,9 @@ class Tente extends Stmt {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
class Se extends Stmt {
|
|
140
|
-
constructor(
|
|
140
|
+
constructor(condicao, thenBranch, elifBranches, elseBranch) {
|
|
141
141
|
super();
|
|
142
|
-
this.
|
|
142
|
+
this.condicao = condicao;
|
|
143
143
|
this.thenBranch = thenBranch;
|
|
144
144
|
this.elifBranches = elifBranches;
|
|
145
145
|
this.elseBranch = elseBranch;
|
|
@@ -151,9 +151,9 @@ class Se extends Stmt {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
class Escolha extends Stmt {
|
|
154
|
-
constructor(
|
|
154
|
+
constructor(condicao, branches, defaultBranch) {
|
|
155
155
|
super();
|
|
156
|
-
this.
|
|
156
|
+
this.condicao = condicao;
|
|
157
157
|
this.branches = branches;
|
|
158
158
|
this.defaultBranch = defaultBranch;
|
|
159
159
|
}
|
|
@@ -184,10 +184,10 @@ class Continua extends Stmt {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
class Var extends Stmt {
|
|
187
|
-
constructor(
|
|
187
|
+
constructor(nome, inicializador) {
|
|
188
188
|
super();
|
|
189
|
-
this.
|
|
190
|
-
this.
|
|
189
|
+
this.nome = nome;
|
|
190
|
+
this.inicializador = inicializador;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
aceitar(visitor) {
|
|
@@ -196,7 +196,7 @@ class Var extends Stmt {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
module.exports = {
|
|
199
|
-
|
|
199
|
+
Expressao,
|
|
200
200
|
Funcao,
|
|
201
201
|
Retorna,
|
|
202
202
|
Classe,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
NEGACAO: "NEGACAO",
|
|
3
|
+
DIFERENTE: "DIFERENTE",
|
|
4
4
|
BIT_AND: "BIT_AND",
|
|
5
5
|
BIT_OR: "BIT_OR",
|
|
6
6
|
BIT_XOR: "BIT_XOR",
|
|
@@ -15,48 +15,48 @@ module.exports = {
|
|
|
15
15
|
EM: "EM",
|
|
16
16
|
ENQUANTO: "ENQUANTO",
|
|
17
17
|
EOF: "EOF",
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
IGUAL: "IGUAL",
|
|
19
|
+
IGUAL_IGUAL: "IGUAL_IGUAL",
|
|
20
20
|
ESCOLHA: "ESCOLHA",
|
|
21
21
|
ESCREVA: "ESCREVA",
|
|
22
22
|
FALSO: "FALSO",
|
|
23
23
|
FAZER: "FAZER",
|
|
24
24
|
FINALMENTE: "FINALMENTE",
|
|
25
25
|
FUNCAO: "FUNCAO",
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
MAIOR: "MAIOR",
|
|
27
|
+
MAIOR_IGUAL: "MAIOR_IGUAL",
|
|
28
|
+
MAIOR_MAIOR: "MAIOR_MAIOR",
|
|
29
29
|
HERDA: "HERDA",
|
|
30
|
-
|
|
30
|
+
IDENTIFICADOR: "IDENTIFICADOR",
|
|
31
31
|
IMPORTAR: "IMPORTAR",
|
|
32
32
|
ISTO: "ISTO",
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
CHAVE_ESQUERDA: "CHAVE_ESQUERDA",
|
|
34
|
+
PARENTESE_ESQUERDO: "PARENTESE_ESQUERDO",
|
|
35
|
+
COLCHETE_ESQUERDO: "COLCHETE_ESQUERDO",
|
|
36
|
+
MENOR: "MENOR",
|
|
37
|
+
MENOR_IGUAL: "MENOR_IGUAL",
|
|
38
|
+
MENOR_MENOR: "MENOR_MENOR",
|
|
39
39
|
MAIS_IGUAL: "MAIS_IGUAL",
|
|
40
40
|
MENOR_IGUAL: "MENOR_IGUAL",
|
|
41
|
-
|
|
41
|
+
SUBTRACAO: "SUBTRACAO",
|
|
42
42
|
MODULUS: "MODULUS",
|
|
43
43
|
NULO: "NULO",
|
|
44
|
-
|
|
44
|
+
NUMERO: "NUMERO",
|
|
45
45
|
OU: "OU",
|
|
46
46
|
PADRAO: "PADRAO",
|
|
47
47
|
PARA: "PARA",
|
|
48
48
|
PAUSA: "PAUSA",
|
|
49
49
|
PEGUE: "PEGUE",
|
|
50
|
-
|
|
50
|
+
ADICAO: "ADICAO",
|
|
51
51
|
RETORNA: "RETORNA",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
PARENTESE_DIREITO: "PARENTESE_DIREITO",
|
|
53
|
+
CHAVE_DIREITA: "CHAVE_DIREITA",
|
|
54
|
+
COLCHETE_DIREITO: "COLCHETE_DIREITO",
|
|
55
55
|
SEMICOLON: "SEMICOLON",
|
|
56
56
|
SLASH: "SLASH",
|
|
57
57
|
STAR: "STAR",
|
|
58
58
|
STAR_STAR: "STAR_STAR",
|
|
59
|
-
|
|
59
|
+
TEXTO: "TEXTO",
|
|
60
60
|
SE: "SE",
|
|
61
61
|
SENAO: "SENAO",
|
|
62
62
|
SENAOSE: "SENAOSE",
|