@designliquido/delegua 0.0.1 → 0.1.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.
Files changed (153) hide show
  1. package/README.md +14 -7
  2. package/bin/delegua.cmd +1 -0
  3. package/bin/package.json +51 -0
  4. package/index.js +25 -12
  5. package/index.js.map +1 -0
  6. package/package.json +51 -37
  7. package/src/ambiente.js +49 -0
  8. package/src/ambiente.js.map +1 -0
  9. package/src/avaliador-sintatico/dialetos/egua-classico.js +635 -0
  10. package/src/avaliador-sintatico/dialetos/egua-classico.js.map +1 -0
  11. package/src/avaliador-sintatico/dialetos/index.js +14 -0
  12. package/src/avaliador-sintatico/dialetos/index.js.map +1 -0
  13. package/src/avaliador-sintatico/index.js +635 -0
  14. package/src/avaliador-sintatico/index.js.map +1 -0
  15. package/src/avaliador-sintatico/parser-error.js +27 -0
  16. package/src/avaliador-sintatico/parser-error.js.map +1 -0
  17. package/src/bibliotecas/bibliotecaGlobal.js +97 -0
  18. package/src/bibliotecas/bibliotecaGlobal.js.map +1 -0
  19. package/src/bibliotecas/importarBiblioteca.js +32 -0
  20. package/src/bibliotecas/importarBiblioteca.js.map +1 -0
  21. package/src/construtos/assign-subscript.js +35 -0
  22. package/src/construtos/assign-subscript.js.map +1 -0
  23. package/src/construtos/atribuir.js +34 -0
  24. package/src/construtos/atribuir.js.map +1 -0
  25. package/src/construtos/binario.js +35 -0
  26. package/src/construtos/binario.js.map +1 -0
  27. package/src/construtos/call.js +35 -0
  28. package/src/construtos/call.js.map +1 -0
  29. package/src/construtos/conjunto.js +35 -0
  30. package/src/construtos/conjunto.js.map +1 -0
  31. package/src/construtos/dicionario.js +34 -0
  32. package/src/construtos/dicionario.js.map +1 -0
  33. package/src/construtos/expr.js +11 -0
  34. package/src/construtos/expr.js.map +1 -0
  35. package/src/construtos/funcao.js +34 -0
  36. package/src/construtos/funcao.js.map +1 -0
  37. package/src/construtos/get.js +34 -0
  38. package/src/construtos/get.js.map +1 -0
  39. package/src/construtos/grouping.js +33 -0
  40. package/src/construtos/grouping.js.map +1 -0
  41. package/src/construtos/index.js +31 -0
  42. package/src/construtos/index.js.map +1 -0
  43. package/src/construtos/isto.js +33 -0
  44. package/src/construtos/isto.js.map +1 -0
  45. package/src/construtos/literal.js +33 -0
  46. package/src/construtos/literal.js.map +1 -0
  47. package/src/construtos/logical.js +35 -0
  48. package/src/construtos/logical.js.map +1 -0
  49. package/src/construtos/subscript.js +35 -0
  50. package/src/construtos/subscript.js.map +1 -0
  51. package/src/construtos/super.js +34 -0
  52. package/src/construtos/super.js.map +1 -0
  53. package/src/construtos/unario.js +34 -0
  54. package/src/construtos/unario.js.map +1 -0
  55. package/src/construtos/variavel.js +33 -0
  56. package/src/construtos/variavel.js.map +1 -0
  57. package/src/construtos/vetor.js +33 -0
  58. package/src/construtos/vetor.js.map +1 -0
  59. package/src/declaracoes/index.js +249 -0
  60. package/src/declaracoes/index.js.map +1 -0
  61. package/src/delegua.js +132 -0
  62. package/src/delegua.js.map +1 -0
  63. package/src/estruturas/callable.js +16 -0
  64. package/src/estruturas/callable.js.map +1 -0
  65. package/src/estruturas/classe.js +57 -0
  66. package/src/estruturas/classe.js.map +1 -0
  67. package/src/estruturas/funcao-padrao.js +38 -0
  68. package/src/estruturas/funcao-padrao.js.map +1 -0
  69. package/src/estruturas/funcao.js +81 -0
  70. package/src/estruturas/funcao.js.map +1 -0
  71. package/src/estruturas/index.js +19 -0
  72. package/src/estruturas/index.js.map +1 -0
  73. package/src/estruturas/instancia.js +28 -0
  74. package/src/estruturas/instancia.js.map +1 -0
  75. package/src/estruturas/modulo.js +15 -0
  76. package/src/estruturas/modulo.js.map +1 -0
  77. package/src/excecoes/break-exception.js +27 -0
  78. package/src/excecoes/break-exception.js.map +1 -0
  79. package/src/excecoes/continue-exception.js +27 -0
  80. package/src/excecoes/continue-exception.js.map +1 -0
  81. package/src/excecoes/erro-em-tempo-de-execucao.js +31 -0
  82. package/src/excecoes/erro-em-tempo-de-execucao.js.map +1 -0
  83. package/src/excecoes/index.js +17 -0
  84. package/src/excecoes/index.js.map +1 -0
  85. package/src/excecoes/return-exception.js +30 -0
  86. package/src/excecoes/return-exception.js.map +1 -0
  87. package/src/interfaces/avaliador-sintatico-interface.js +3 -0
  88. package/src/interfaces/avaliador-sintatico-interface.js.map +1 -0
  89. package/src/interfaces/index.js +19 -0
  90. package/src/interfaces/index.js.map +1 -0
  91. package/src/interfaces/interpretador-interface.js +3 -0
  92. package/src/interfaces/interpretador-interface.js.map +1 -0
  93. package/src/interfaces/lexador-interface.js +3 -0
  94. package/src/interfaces/lexador-interface.js.map +1 -0
  95. package/src/interfaces/pilha-interface.js +3 -0
  96. package/src/interfaces/pilha-interface.js.map +1 -0
  97. package/src/interfaces/resolvedor-interface.js +3 -0
  98. package/src/interfaces/resolvedor-interface.js.map +1 -0
  99. package/src/interfaces/simbolo-interface.js +3 -0
  100. package/src/interfaces/simbolo-interface.js.map +1 -0
  101. package/src/interpretador/dialetos/egua-classico.js +665 -0
  102. package/src/interpretador/dialetos/egua-classico.js.map +1 -0
  103. package/src/interpretador/dialetos/index.js +14 -0
  104. package/src/interpretador/dialetos/index.js.map +1 -0
  105. package/src/interpretador/index.js +665 -0
  106. package/src/interpretador/index.js.map +1 -0
  107. package/src/lexador/dialetos/egua-classico.js +287 -0
  108. package/src/lexador/dialetos/egua-classico.js.map +1 -0
  109. package/src/lexador/dialetos/index.js +14 -0
  110. package/src/lexador/dialetos/index.js.map +1 -0
  111. package/src/lexador/index.js +287 -0
  112. package/src/lexador/index.js.map +1 -0
  113. package/src/resolvedor/Pilha.js +27 -0
  114. package/src/resolvedor/Pilha.js.map +1 -0
  115. package/src/resolvedor/ResolverError.js +29 -0
  116. package/src/resolvedor/ResolverError.js.map +1 -0
  117. package/src/resolvedor/dialetos/egua-classico.js +331 -0
  118. package/src/resolvedor/dialetos/egua-classico.js.map +1 -0
  119. package/src/resolvedor/dialetos/index.js +14 -0
  120. package/src/resolvedor/dialetos/index.js.map +1 -0
  121. package/src/resolvedor/index.js +331 -0
  122. package/src/resolvedor/index.js.map +1 -0
  123. package/src/tiposDeSimbolos.js +69 -0
  124. package/src/tiposDeSimbolos.js.map +1 -0
  125. package/src/web.js +65 -69
  126. package/src/web.js.map +1 -0
  127. package/.vscode/launch.json +0 -29
  128. package/.vscode/settings.json +0 -3
  129. package/LICENSE +0 -21
  130. package/babel.config.js +0 -1
  131. package/index.html +0 -43
  132. package/src/egua.js +0 -102
  133. package/src/environment.js +0 -53
  134. package/src/errors.js +0 -17
  135. package/src/expr.js +0 -228
  136. package/src/interpreter.js +0 -798
  137. package/src/lexer.js +0 -315
  138. package/src/lib/__tests__/eguamat.test.js +0 -101
  139. package/src/lib/eguamat.js +0 -725
  140. package/src/lib/globalLib.js +0 -171
  141. package/src/lib/importStdlib.js +0 -41
  142. package/src/lib/tempo.js +0 -50
  143. package/src/parser.js +0 -826
  144. package/src/resolver.js +0 -425
  145. package/src/stmt.js +0 -215
  146. package/src/structures/callable.js +0 -5
  147. package/src/structures/class.js +0 -43
  148. package/src/structures/function.js +0 -62
  149. package/src/structures/instance.js +0 -27
  150. package/src/structures/module.js +0 -9
  151. package/src/structures/standardFn.js +0 -18
  152. package/src/tokenTypes.js +0 -67
  153. package/testes/testes.egua +0 -631
package/src/resolver.js DELETED
@@ -1,425 +0,0 @@
1
- class ResolverError extends Error {
2
- constructor(msg) {
3
- super(msg);
4
- this.message = msg;
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(interpreter, egua) {
61
- this.interpreter = interpreter;
62
- this.egua = egua;
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(name) {
71
- if (this.escopos.isEmpty()) return;
72
- this.escopos.peek()[name.lexeme] = true;
73
- }
74
-
75
- declarar(name) {
76
- if (this.escopos.isEmpty()) return;
77
- let escopo = this.escopos.peek();
78
- if (escopo.hasOwnProperty(name.lexeme))
79
- this.egua.error(
80
- name,
81
- "Variável com esse nome já declarada neste escopo."
82
- );
83
- escopo[name.lexeme] = false;
84
- }
85
-
86
- inicioDoEscopo() {
87
- this.escopos.push({});
88
- }
89
-
90
- finalDoEscopo() {
91
- this.escopos.pop();
92
- }
93
-
94
- resolver(statements) {
95
- if (Array.isArray(statements)) {
96
- for (let i = 0; i < statements.length; i++) {
97
- statements[i].aceitar(this);
98
- }
99
- } else {
100
- statements.aceitar(this);
101
- }
102
- }
103
-
104
- resolverLocal(expr, name) {
105
- for (let i = this.escopos.stack.length - 1; i >= 0; i--) {
106
- if (this.escopos.stack[i].hasOwnProperty(name.lexeme)) {
107
- this.interpreter.resolver(expr, this.escopos.stack.length - 1 - i);
108
- }
109
- }
110
- }
111
-
112
- visitBlockStmt(stmt) {
113
- this.inicioDoEscopo();
114
- this.resolver(stmt.statements);
115
- this.finalDoEscopo();
116
- return null;
117
- }
118
-
119
- visitVariableExpr(expr) {
120
- if (
121
- !this.escopos.isEmpty() &&
122
- this.escopos.peek()[expr.name.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.name);
129
- return null;
130
- }
131
-
132
- visitVarStmt(stmt) {
133
- this.declarar(stmt.name);
134
- if (stmt.initializer !== null) {
135
- this.resolver(stmt.initializer);
136
- }
137
- this.definir(stmt.name);
138
- return null;
139
- }
140
-
141
- visitAssignExpr(expr) {
142
- this.resolver(expr.value);
143
- this.resolverLocal(expr, expr.name);
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.params;
153
- for (let i = 0; i < parametros.length; i++) {
154
- this.declarar(parametros[i]["name"]);
155
- this.definir(parametros[i]["name"]);
156
- }
157
- this.resolver(funcao.body);
158
- this.finalDoEscopo();
159
-
160
- this.FuncaoAtual = enclosingFunc;
161
- }
162
-
163
- visitFunctionStmt(stmt) {
164
- this.declarar(stmt.name);
165
- this.definir(stmt.name);
166
-
167
- this.resolverFuncao(stmt.func, 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.name);
189
- this.definir(stmt.name);
190
-
191
- if (
192
- stmt.superclass !== null &&
193
- stmt.name.lexeme === stmt.superclass.name.lexeme
194
- ) {
195
- this.egua.error("Uma classe não pode herdar de si mesma.");
196
- }
197
-
198
- if (stmt.superclass !== null) {
199
- this.ClasseAtual = ClassType.SUBCLASS;
200
- this.resolver(stmt.superclass);
201
- }
202
-
203
- if (stmt.superclass !== 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.methods;
212
- for (let i = 0; i < metodos.length; i++) {
213
- let declaracao = FunctionType.METHOD;
214
-
215
- if (metodos[i].name.lexeme === "isto") {
216
- declaracao = FunctionType.CONSTRUTOR;
217
- }
218
-
219
- this.resolverFuncao(metodos[i].func, declaracao);
220
- }
221
-
222
- this.finalDoEscopo();
223
-
224
- if (stmt.superclass !== null) this.finalDoEscopo();
225
-
226
- this.ClasseAtual = enclosingClass;
227
- return null;
228
- }
229
-
230
- visitSuperExpr(expr) {
231
- if (this.ClasseAtual === ClassType.NONE) {
232
- this.egua.error(expr.keyword, "Não pode usar 'super' fora de uma classe.");
233
- } else if (this.ClasseAtual !== ClassType.SUBCLASS) {
234
- this.egua.error(
235
- expr.keyword,
236
- "Não se usa 'super' numa classe sem superclasse."
237
- );
238
- }
239
-
240
- this.resolverLocal(expr, expr.keyword);
241
- return null;
242
- }
243
-
244
- visitGetExpr(expr) {
245
- this.resolver(expr.object);
246
- return null;
247
- }
248
-
249
- visitExpressionStmt(stmt) {
250
- this.resolver(stmt.expression);
251
- return null;
252
- }
253
-
254
- visitIfStmt(stmt) {
255
- this.resolver(stmt.condition);
256
- this.resolver(stmt.thenBranch);
257
-
258
- for (let i = 0; i < stmt.elifBranches.length; i++) {
259
- this.resolver(stmt.elifBranches[i].condition);
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.path);
269
- }
270
-
271
- visitPrintStmt(stmt) {
272
- this.resolver(stmt.expression);
273
- }
274
-
275
- visitReturnStmt(stmt) {
276
- if (this.FuncaoAtual === FunctionType.NONE) {
277
- this.egua.error(stmt.keyword, "Não é possível retornar do código do escopo superior.");
278
- }
279
- if (stmt.value !== null) {
280
- if (this.FuncaoAtual === FunctionType.CONSTRUTOR) {
281
- this.egua.error(
282
- stmt.keyword,
283
- "Não pode retornar o valor do construtor."
284
- );
285
- }
286
- this.resolver(stmt.value);
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.condition);
309
- this.resolver(stmt.body);
310
- return null;
311
- }
312
-
313
- visitForStmt(stmt) {
314
- if (stmt.initializer !== null) {
315
- this.resolver(stmt.initializer);
316
- }
317
- if (stmt.condition !== null) {
318
- this.resolver(stmt.condition);
319
- }
320
- if (stmt.increment !== null) {
321
- this.resolver(stmt.increment);
322
- }
323
-
324
- let enclosingType = this.cicloAtual;
325
- this.cicloAtual = LoopType.ENQUANTO;
326
- this.resolver(stmt.body);
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.left);
344
- this.resolver(expr.right);
345
- return null;
346
- }
347
-
348
- visitCallExpr(expr) {
349
- this.resolver(expr.callee);
350
-
351
- let args = expr.args;
352
- for (let i = 0; i < args.length; i++) {
353
- this.resolver(args[i]);
354
- }
355
-
356
- return null;
357
- }
358
-
359
- visitGroupingExpr(expr) {
360
- this.resolver(expr.expression);
361
- return null;
362
- }
363
-
364
- visitDictionaryExpr(expr) {
365
- for (let i = 0; i < expr.keys.length; i++) {
366
- this.resolver(expr.keys[i]);
367
- this.resolver(expr.values[i]);
368
- }
369
- return null;
370
- }
371
-
372
- visitArrayExpr(expr) {
373
- for (let i = 0; i < expr.values.length; i++) {
374
- this.resolver(expr.values[i]);
375
- }
376
- return null;
377
- }
378
-
379
- visitSubscriptExpr(expr) {
380
- this.resolver(expr.callee);
381
- this.resolver(expr.index);
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.left);
403
- this.resolver(expr.right);
404
- return null;
405
- }
406
-
407
- visitUnaryExpr(expr) {
408
- this.resolver(expr.right);
409
- return null;
410
- }
411
-
412
- visitSetExpr(expr) {
413
- this.resolver(expr.value);
414
- this.resolver(expr.object);
415
- return null;
416
- }
417
-
418
- visitThisExpr(expr) {
419
- if (this.ClasseAtual == ClassType.NONE) {
420
- this.egua.error(expr.keyword, "Não pode usar 'isto' fora da classe.");
421
- }
422
- this.resolverLocal(expr, expr.keyword);
423
- return null;
424
- }
425
- };
package/src/stmt.js DELETED
@@ -1,215 +0,0 @@
1
- class Stmt {
2
- aceitar(visitor) { }
3
- }
4
-
5
- class Expression extends Stmt {
6
- constructor(expression) {
7
- super();
8
- this.expression = expression;
9
- }
10
-
11
- aceitar(visitor) {
12
- return visitor.visitExpressionStmt(this)
13
- }
14
- }
15
-
16
- class Funcao extends Stmt {
17
- constructor(name, func) {
18
- super();
19
- this.name = name;
20
- this.func = func;
21
- }
22
-
23
- aceitar(visitor) {
24
- return visitor.visitFunctionStmt(this);
25
- }
26
- }
27
-
28
- class Retorna extends Stmt {
29
- constructor(keyword, value) {
30
- super();
31
- this.keyword = keyword;
32
- this.value = value;
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.name = nome;
44
- this.superclass = superClasse;
45
- this.methods = metodos;
46
- }
47
-
48
- aceitar(visitor) {
49
- return visitor.visitClassStmt(this);
50
- }
51
- }
52
-
53
- class Block extends Stmt {
54
- constructor(statements) {
55
- super();
56
- this.statements = statements;
57
- }
58
-
59
- aceitar(visitor) {
60
- return visitor.visitBlockStmt(this);
61
- }
62
- }
63
-
64
- class Escreva extends Stmt {
65
- constructor(expression) {
66
- super();
67
- this.expression = expression;
68
- }
69
-
70
- aceitar(visitor) {
71
- return visitor.visitPrintStmt(this);
72
- }
73
- }
74
-
75
- class Importar extends Stmt {
76
- constructor(path, closeBracket) {
77
- super();
78
- this.path = path;
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(condition, body) {
101
- super();
102
- this.condition = condition;
103
- this.body = body;
104
- }
105
-
106
- aceitar(visitor) {
107
- return visitor.visitWhileStmt(this);
108
- }
109
- }
110
-
111
- class Para extends Stmt {
112
- constructor(initializer, condition, increment, body) {
113
- super();
114
- this.initializer = initializer;
115
- this.condition = condition;
116
- this.increment = increment;
117
- this.body = body;
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(condition, thenBranch, elifBranches, elseBranch) {
141
- super();
142
- this.condition = condition;
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(condition, branches, defaultBranch) {
155
- super();
156
- this.condition = condition;
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(name, initializer) {
188
- super();
189
- this.name = name;
190
- this.initializer = initializer;
191
- }
192
-
193
- aceitar(visitor) {
194
- return visitor.visitVarStmt(this);
195
- }
196
- }
197
-
198
- module.exports = {
199
- Expression,
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
- };
@@ -1,5 +0,0 @@
1
- module.exports = class Callable {
2
- arity() {
3
- return this.arityValue;
4
- }
5
- };
@@ -1,43 +0,0 @@
1
- const Callable = require("./callable.js");
2
- const EguaInstance = require("./instance.js");
3
-
4
- module.exports = class EguaClass extends Callable {
5
- constructor(name, superclass, methods) {
6
- super();
7
- this.name = name;
8
- this.superclass = superclass;
9
- this.methods = methods;
10
- }
11
-
12
- findMethod(name) {
13
- if (this.methods.hasOwnProperty(name)) {
14
- return this.methods[name];
15
- }
16
-
17
- if (this.superclass !== null) {
18
- return this.superclass.findMethod(name);
19
- }
20
-
21
- return undefined;
22
- }
23
-
24
- toString() {
25
- return `<classe ${this.name}>`;
26
- }
27
-
28
- arity() {
29
- let initializer = this.findMethod("construtor");
30
- return initializer ? initializer.arity() : 0;
31
- }
32
-
33
- call(interpreter, args) {
34
- let instance = new EguaInstance(this);
35
-
36
- let initializer = this.findMethod("construtor");
37
- if (initializer) {
38
- initializer.bind(instance).call(interpreter, args);
39
- }
40
-
41
- return instance;
42
- }
43
- };