@designliquido/delegua 0.0.2 → 0.1.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.
Files changed (81) hide show
  1. package/.github/CONTRIBUTING.md +37 -0
  2. package/.github/workflows/principal.yml +3 -1
  3. package/.release-it.json +2 -1
  4. package/.vscode/launch.json +43 -8
  5. package/README.md +9 -1
  6. package/bin/delegua +2 -2
  7. package/bin/delegua.cmd +1 -1
  8. package/index.ts +29 -0
  9. package/package.json +9 -4
  10. package/src/ambiente.ts +56 -0
  11. package/src/avaliador-sintatico/dialetos/egua-classico.ts +983 -0
  12. package/src/avaliador-sintatico/dialetos/index.ts +1 -0
  13. package/src/avaliador-sintatico/index.ts +983 -0
  14. package/src/avaliador-sintatico/parser-error.ts +1 -0
  15. package/src/{lib/globalLib.js → bibliotecas/bibliotecaGlobal.ts} +34 -34
  16. package/src/{lib/importStdlib.js → bibliotecas/importarBiblioteca.ts} +9 -9
  17. package/src/construtos/assign-subscript.ts +19 -0
  18. package/src/construtos/atribuir.ts +17 -0
  19. package/src/construtos/binario.ts +19 -0
  20. package/src/construtos/call.ts +19 -0
  21. package/src/construtos/conjunto.ts +19 -0
  22. package/src/construtos/dicionario.ts +17 -0
  23. package/src/construtos/expr.ts +3 -0
  24. package/src/construtos/funcao.ts +17 -0
  25. package/src/construtos/get.ts +17 -0
  26. package/src/construtos/grouping.ts +15 -0
  27. package/src/construtos/index.ts +18 -0
  28. package/src/construtos/isto.ts +15 -0
  29. package/src/construtos/literal.ts +15 -0
  30. package/src/construtos/logical.ts +19 -0
  31. package/src/construtos/subscript.ts +19 -0
  32. package/src/construtos/super.ts +17 -0
  33. package/src/construtos/unario.ts +17 -0
  34. package/src/construtos/variavel.ts +15 -0
  35. package/src/construtos/vetor.ts +15 -0
  36. package/src/{stmt.js → declaracoes/index.ts} +79 -51
  37. package/src/delegua.ts +156 -0
  38. package/src/estruturas/callable.ts +11 -0
  39. package/src/estruturas/{classe.js → classe.ts} +11 -7
  40. package/src/estruturas/{funcaoPadrao.js → funcao-padrao.ts} +8 -4
  41. package/src/estruturas/funcao.ts +70 -0
  42. package/src/estruturas/index.ts +6 -0
  43. package/src/estruturas/{instancia.js → instancia.ts} +12 -9
  44. package/src/estruturas/modulo.ts +11 -0
  45. package/src/excecoes/break-exception.ts +1 -0
  46. package/src/excecoes/continue-exception.ts +1 -0
  47. package/src/excecoes/erro-em-tempo-de-execucao.ts +11 -0
  48. package/src/excecoes/index.ts +4 -0
  49. package/src/excecoes/return-exception.ts +10 -0
  50. package/src/interfaces/avaliador-sintatico-interface.ts +58 -0
  51. package/src/interfaces/index.ts +6 -0
  52. package/src/interfaces/interpretador-interface.ts +52 -0
  53. package/src/interfaces/lexador-interface.ts +24 -0
  54. package/src/interfaces/pilha-interface.ts +7 -0
  55. package/src/interfaces/resolvedor-interface.ts +49 -0
  56. package/src/interfaces/simbolo-interface.ts +6 -0
  57. package/src/interpretador/dialetos/egua-classico.ts +825 -0
  58. package/src/interpretador/dialetos/index.ts +1 -0
  59. package/src/interpretador/index.ts +825 -0
  60. package/src/lexador/dialetos/egua-classico.ts +333 -0
  61. package/src/lexador/dialetos/index.ts +1 -0
  62. package/src/{lexer.js → lexador/index.ts} +38 -21
  63. package/src/resolvedor/Pilha.ts +29 -0
  64. package/src/resolvedor/ResolverError.ts +8 -0
  65. package/src/resolvedor/dialetos/egua-classico.ts +412 -0
  66. package/src/resolvedor/dialetos/index.ts +1 -0
  67. package/src/{resolver.js → resolvedor/index.ts} +101 -114
  68. package/src/{tiposDeSimbolos.js → tiposDeSimbolos.ts} +21 -22
  69. package/src/web.ts +75 -0
  70. package/tsconfig.json +11 -0
  71. package/indice.js +0 -14
  72. package/src/ambiente.js +0 -53
  73. package/src/delegua.js +0 -102
  74. package/src/erro.js +0 -18
  75. package/src/estruturas/callable.js +0 -5
  76. package/src/estruturas/funcao.js +0 -62
  77. package/src/estruturas/modulo.js +0 -9
  78. package/src/expr.js +0 -228
  79. package/src/interpretador.js +0 -802
  80. package/src/parser.js +0 -822
  81. package/src/web.js +0 -70
@@ -1,49 +1,22 @@
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
- }
1
+ import { ResolvedorInterface } from "../interfaces/resolvedor-interface";
2
+ import { Pilha } from "./Pilha";
3
+ import { ResolverError } from "./ResolverError";
20
4
 
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",
5
+ const TipoFuncao = {
6
+ NENHUM: "NENHUM",
34
7
  FUNCAO: "FUNCAO",
35
8
  CONSTRUTOR: "CONSTRUTOR",
36
- METHOD: "METHOD"
9
+ METODO: "METODO"
37
10
  };
38
11
 
39
- const ClassType = {
40
- NONE: "NONE",
12
+ const TipoClasse = {
13
+ NENHUM: "NENHUM",
41
14
  CLASSE: "CLASSE",
42
- SUBCLASS: "SUBCLASS"
15
+ SUBCLASSE: "SUBCLASSE"
43
16
  };
44
17
 
45
18
  const LoopType = {
46
- NONE: "NONE",
19
+ NENHUM: "NENHUM",
47
20
  ENQUANTO: "ENQUANTO",
48
21
  ESCOLHA: "ESCOLHA",
49
22
  PARA: "PARA",
@@ -56,70 +29,79 @@ const LoopType = {
56
29
  * 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
30
  * No entanto, todas as variáveis declaradas dentro da classe A podem ser vistas tanto por M quanto por N.
58
31
  */
59
- module.exports = class Resolver {
60
- constructor(interpretador, Delegua) {
32
+ export class Resolver implements ResolvedorInterface {
33
+ interpretador: any;
34
+ Delegua: any;
35
+ escopos: any;
36
+ FuncaoAtual: any;
37
+ ClasseAtual: any;
38
+ cicloAtual: any;
39
+
40
+ constructor(Delegua: any, interpretador: any) {
61
41
  this.interpretador = interpretador;
62
42
  this.Delegua = Delegua;
63
- this.escopos = new Stack();
43
+ this.escopos = new Pilha();
64
44
 
65
- this.FuncaoAtual = FunctionType.NONE;
66
- this.ClasseAtual = ClassType.NONE;
67
- this.cicloAtual = ClassType.NONE;
45
+ this.FuncaoAtual = TipoFuncao.NENHUM;
46
+ this.ClasseAtual = TipoClasse.NENHUM;
47
+ this.cicloAtual = TipoClasse.NENHUM;
68
48
  }
69
49
 
70
- definir(nome) {
71
- if (this.escopos.isEmpty()) return;
72
- this.escopos.peek()[nome.lexeme] = true;
50
+ definir(nome: any): void {
51
+ if (this.escopos.eVazio()) return;
52
+ this.escopos.peek()[nome.lexema] = true;
73
53
  }
74
54
 
75
- declarar(nome) {
76
- if (this.escopos.isEmpty()) return;
55
+ declarar(nome: any): void {
56
+ if (this.escopos.eVazio()) return;
77
57
  let escopo = this.escopos.peek();
78
- if (escopo.hasOwnProperty(nome.lexeme))
58
+ if (escopo.hasOwnProperty(nome.lexema))
79
59
  this.Delegua.erro(
80
60
  nome,
81
61
  "Variável com esse nome já declarada neste escopo."
82
62
  );
83
- escopo[nome.lexeme] = false;
63
+ escopo[nome.lexema] = false;
84
64
  }
85
65
 
86
- inicioDoEscopo() {
87
- this.escopos.push({});
66
+ inicioDoEscopo(): void {
67
+ this.escopos.empilhar({});
88
68
  }
89
69
 
90
- finalDoEscopo() {
91
- this.escopos.pop();
70
+ finalDoEscopo(): void {
71
+ this.escopos.removerUltimo();
92
72
  }
93
73
 
94
- resolver(declaracoes) {
74
+ resolver(declaracoes: any): void {
95
75
  if (Array.isArray(declaracoes)) {
96
76
  for (let i = 0; i < declaracoes.length; i++) {
97
- declaracoes[i].aceitar(this);
77
+ if (declaracoes[i] && declaracoes[i].aceitar) {
78
+ declaracoes[i].aceitar(this);
79
+ }
98
80
  }
99
- } else {
81
+ } else if (declaracoes) {
100
82
  declaracoes.aceitar(this);
101
83
  }
102
84
  }
103
85
 
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);
86
+ resolverLocal(expr: any, nome: any): void {
87
+ for (let i = this.escopos.pilha.length - 1; i >= 0; i--) {
88
+ if (this.escopos.pilha[i].hasOwnProperty(nome.lexema)) {
89
+ this.interpretador.resolver(expr, this.escopos.pilha.length - 1 - i);
108
90
  }
109
91
  }
110
92
  }
111
93
 
112
- visitBlockStmt(stmt) {
94
+ visitBlockStmt(stmt: any) : any {
113
95
  this.inicioDoEscopo();
114
96
  this.resolver(stmt.declaracoes);
115
97
  this.finalDoEscopo();
116
98
  return null;
117
99
  }
118
100
 
119
- visitVariableExpr(expr) {
101
+ visitVariableExpr(expr: any): any {
120
102
  if (
121
- !this.escopos.isEmpty() &&
122
- this.escopos.peek()[expr.nome.lexeme] === false
103
+ !this.escopos.eVazio() &&
104
+ this.escopos.peek()[expr.nome.lexema] === false
123
105
  ) {
124
106
  throw new ResolverError(
125
107
  "Não é possível ler a variável local em seu próprio inicializador."
@@ -129,7 +111,7 @@ module.exports = class Resolver {
129
111
  return null;
130
112
  }
131
113
 
132
- visitVarStmt(stmt) {
114
+ visitVarStmt(stmt: any): any {
133
115
  this.declarar(stmt.nome);
134
116
  if (stmt.inicializador !== null) {
135
117
  this.resolver(stmt.inicializador);
@@ -138,42 +120,46 @@ module.exports = class Resolver {
138
120
  return null;
139
121
  }
140
122
 
141
- visitAssignExpr(expr) {
123
+ visitAssignExpr(expr: any): any {
142
124
  this.resolver(expr.valor);
143
125
  this.resolverLocal(expr, expr.nome);
144
126
  return null;
145
127
  }
146
128
 
147
- resolverFuncao(funcao, funcType) {
129
+ resolverFuncao(funcao: any, funcType: any): void {
148
130
  let enclosingFunc = this.FuncaoAtual;
149
131
  this.FuncaoAtual = funcType;
150
132
 
151
133
  this.inicioDoEscopo();
152
134
  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"]);
135
+
136
+ if (parametros && parametros.length > 0) {
137
+ for (let i = 0; i < parametros.length; i++) {
138
+ this.declarar(parametros[i]["nome"]);
139
+ this.definir(parametros[i]["nome"]);
140
+ }
156
141
  }
157
- this.resolver(funcao.corpo);
142
+
143
+ this.resolver(funcao.funcao);
158
144
  this.finalDoEscopo();
159
145
 
160
146
  this.FuncaoAtual = enclosingFunc;
161
147
  }
162
148
 
163
- visitFunctionStmt(stmt) {
149
+ visitFunctionStmt(stmt: any): any {
164
150
  this.declarar(stmt.nome);
165
151
  this.definir(stmt.nome);
166
152
 
167
- this.resolverFuncao(stmt.funcao, FunctionType.FUNCAO);
153
+ this.resolverFuncao(stmt.funcao, TipoFuncao.FUNCAO);
168
154
  return null;
169
155
  }
170
156
 
171
- visitFunctionExpr(stmt) {
172
- this.resolverFuncao(stmt, FunctionType.FUNCAO);
157
+ visitFunctionExpr(stmt: any): any {
158
+ this.resolverFuncao(stmt, TipoFuncao.FUNCAO);
173
159
  return null;
174
160
  }
175
161
 
176
- visitTryStmt(stmt) {
162
+ visitTryStmt(stmt: any): any {
177
163
  this.resolver(stmt.tryBranch);
178
164
 
179
165
  if (stmt.catchBranch !== null) this.resolver(stmt.catchBranch);
@@ -181,22 +167,22 @@ module.exports = class Resolver {
181
167
  if (stmt.finallyBranch !== null) this.resolver(stmt.finallyBranch);
182
168
  }
183
169
 
184
- visitClassStmt(stmt) {
170
+ visitClassStmt(stmt: any): any {
185
171
  let enclosingClass = this.ClasseAtual;
186
- this.ClasseAtual = ClassType.CLASSE;
172
+ this.ClasseAtual = TipoClasse.CLASSE;
187
173
 
188
174
  this.declarar(stmt.nome);
189
175
  this.definir(stmt.nome);
190
176
 
191
177
  if (
192
178
  stmt.superClasse !== null &&
193
- stmt.nome.lexeme === stmt.superClasse.nome.lexeme
179
+ stmt.nome.lexema === stmt.superClasse.nome.lexema
194
180
  ) {
195
181
  this.Delegua.error("Uma classe não pode herdar de si mesma.");
196
182
  }
197
183
 
198
184
  if (stmt.superClasse !== null) {
199
- this.ClasseAtual = ClassType.SUBCLASS;
185
+ this.ClasseAtual = TipoClasse.SUBCLASSE;
200
186
  this.resolver(stmt.superClasse);
201
187
  }
202
188
 
@@ -210,10 +196,10 @@ module.exports = class Resolver {
210
196
 
211
197
  let metodos = stmt.metodos;
212
198
  for (let i = 0; i < metodos.length; i++) {
213
- let declaracao = FunctionType.METHOD;
199
+ let declaracao = TipoFuncao.METODO;
214
200
 
215
- if (metodos[i].nome.lexeme === "isto") {
216
- declaracao = FunctionType.CONSTRUTOR;
201
+ if (metodos[i].nome.lexema === "isto") {
202
+ declaracao = TipoFuncao.CONSTRUTOR;
217
203
  }
218
204
 
219
205
  this.resolverFuncao(metodos[i].funcao, declaracao);
@@ -227,10 +213,10 @@ module.exports = class Resolver {
227
213
  return null;
228
214
  }
229
215
 
230
- visitSuperExpr(expr) {
231
- if (this.ClasseAtual === ClassType.NONE) {
216
+ visitSuperExpr(expr: any): any {
217
+ if (this.ClasseAtual === TipoClasse.NENHUM) {
232
218
  this.Delegua.error(expr.palavraChave, "Não pode usar 'super' fora de uma classe.");
233
- } else if (this.ClasseAtual !== ClassType.SUBCLASS) {
219
+ } else if (this.ClasseAtual !== TipoClasse.SUBCLASSE) {
234
220
  this.Delegua.error(
235
221
  expr.palavraChave,
236
222
  "Não se usa 'super' numa classe sem SuperClasse."
@@ -241,17 +227,17 @@ module.exports = class Resolver {
241
227
  return null;
242
228
  }
243
229
 
244
- visitGetExpr(expr) {
230
+ visitGetExpr(expr: any): any {
245
231
  this.resolver(expr.objeto);
246
232
  return null;
247
233
  }
248
234
 
249
- visitExpressionStmt(stmt) {
235
+ visitExpressionStmt(stmt: any): any {
250
236
  this.resolver(stmt.expressao);
251
237
  return null;
252
238
  }
253
239
 
254
- visitIfStmt(stmt) {
240
+ visitIfStmt(stmt: any): any {
255
241
  this.resolver(stmt.condicao);
256
242
  this.resolver(stmt.thenBranch);
257
243
 
@@ -264,20 +250,21 @@ module.exports = class Resolver {
264
250
  return null;
265
251
  }
266
252
 
267
- visitImportStmt(stmt) {
253
+ visitImportStmt(stmt: any): void {
268
254
  this.resolver(stmt.caminho);
269
255
  }
270
256
 
271
- visitPrintStmt(stmt) {
257
+ visitPrintStmt(stmt: any): void {
272
258
  this.resolver(stmt.expressao);
273
259
  }
274
260
 
275
- visitReturnStmt(stmt) {
276
- if (this.FuncaoAtual === FunctionType.NONE) {
261
+ visitReturnStmt(stmt: any): any {
262
+ if (this.FuncaoAtual === TipoFuncao.NENHUM) {
277
263
  this.Delegua.error(stmt.palavraChave, "Não é possível retornar do código do escopo superior.");
278
264
  }
265
+
279
266
  if (stmt.valor !== null) {
280
- if (this.FuncaoAtual === FunctionType.CONSTRUTOR) {
267
+ if (this.FuncaoAtual === TipoFuncao.CONSTRUTOR) {
281
268
  this.Delegua.error(
282
269
  stmt.palavraChave,
283
270
  "Não pode retornar o valor do construtor."
@@ -288,7 +275,7 @@ module.exports = class Resolver {
288
275
  return null;
289
276
  }
290
277
 
291
- visitSwitchStmt(stmt) {
278
+ visitSwitchStmt(stmt: any): void {
292
279
  let enclosingType = this.cicloAtual;
293
280
  this.cicloAtual = LoopType.ESCOLHA;
294
281
 
@@ -304,13 +291,13 @@ module.exports = class Resolver {
304
291
  this.cicloAtual = enclosingType;
305
292
  }
306
293
 
307
- visitWhileStmt(stmt) {
294
+ visitWhileStmt(stmt: any): any {
308
295
  this.resolver(stmt.condicao);
309
296
  this.resolver(stmt.corpo);
310
297
  return null;
311
298
  }
312
299
 
313
- visitForStmt(stmt) {
300
+ visitForStmt(stmt: any): any {
314
301
  if (stmt.inicializador !== null) {
315
302
  this.resolver(stmt.inicializador);
316
303
  }
@@ -329,7 +316,7 @@ module.exports = class Resolver {
329
316
  return null;
330
317
  }
331
318
 
332
- visitDoStmt(stmt) {
319
+ visitDoStmt(stmt: any): any {
333
320
  this.resolver(stmt.whileCondition);
334
321
 
335
322
  let enclosingType = this.cicloAtual;
@@ -339,13 +326,13 @@ module.exports = class Resolver {
339
326
  return null;
340
327
  }
341
328
 
342
- visitBinaryExpr(expr) {
329
+ visitBinaryExpr(expr: any): any {
343
330
  this.resolver(expr.esquerda);
344
331
  this.resolver(expr.direita);
345
332
  return null;
346
333
  }
347
334
 
348
- visitCallExpr(expr) {
335
+ visitCallExpr(expr: any): any {
349
336
  this.resolver(expr.callee);
350
337
 
351
338
  let argumentos = expr.argumentos;
@@ -356,12 +343,12 @@ module.exports = class Resolver {
356
343
  return null;
357
344
  }
358
345
 
359
- visitGroupingExpr(expr) {
346
+ visitGroupingExpr(expr: any): any {
360
347
  this.resolver(expr.expressao);
361
348
  return null;
362
349
  }
363
350
 
364
- visitDictionaryExpr(expr) {
351
+ visitDictionaryExpr(expr: any): any {
365
352
  for (let i = 0; i < expr.chaves.length; i++) {
366
353
  this.resolver(expr.chaves[i]);
367
354
  this.resolver(expr.valores[i]);
@@ -369,54 +356,54 @@ module.exports = class Resolver {
369
356
  return null;
370
357
  }
371
358
 
372
- visitArrayExpr(expr) {
359
+ visitArrayExpr(expr: any): any {
373
360
  for (let i = 0; i < expr.valores.length; i++) {
374
361
  this.resolver(expr.valores[i]);
375
362
  }
376
363
  return null;
377
364
  }
378
365
 
379
- visitSubscriptExpr(expr) {
366
+ visitSubscriptExpr(expr: any): any {
380
367
  this.resolver(expr.callee);
381
368
  this.resolver(expr.indice);
382
369
  return null;
383
370
  }
384
371
 
385
- visitContinueStmt(stmt) {
372
+ visitContinueStmt(stmt?: any): any {
386
373
  return null;
387
374
  }
388
375
 
389
- visitBreakStmt(stmt) {
376
+ visitBreakStmt(stmt?: any): any {
390
377
  return null;
391
378
  }
392
379
 
393
- visitAssignsubscriptExpr(expr) {
380
+ visitAssignsubscriptExpr(expr?: any): any {
394
381
  return null;
395
382
  }
396
383
 
397
- visitLiteralExpr(expr) {
384
+ visitLiteralExpr(expr?: any): any {
398
385
  return null;
399
386
  }
400
387
 
401
- visitLogicalExpr(expr) {
388
+ visitLogicalExpr(expr?: any): any {
402
389
  this.resolver(expr.esquerda);
403
390
  this.resolver(expr.direita);
404
391
  return null;
405
392
  }
406
393
 
407
- visitUnaryExpr(expr) {
394
+ visitUnaryExpr(expr?: any): any {
408
395
  this.resolver(expr.direita);
409
396
  return null;
410
397
  }
411
398
 
412
- visitSetExpr(expr) {
399
+ visitSetExpr(expr?: any): any {
413
400
  this.resolver(expr.valor);
414
401
  this.resolver(expr.objeto);
415
402
  return null;
416
403
  }
417
404
 
418
- visitThisExpr(expr) {
419
- if (this.ClasseAtual == ClassType.NONE) {
405
+ visitThisExpr(expr?: any): any {
406
+ if (this.ClasseAtual == TipoClasse.NENHUM) {
420
407
  this.Delegua.error(expr.palavraChave, "Não pode usar 'isto' fora da classe.");
421
408
  }
422
409
  this.resolverLocal(expr, expr.palavraChave);
@@ -1,24 +1,30 @@
1
- module.exports = {
2
- NEGACAO: "NEGACAO",
3
- DIFERENTE: "DIFERENTE",
1
+ export default {
2
+ ADICAO: "ADICAO",
4
3
  BIT_AND: "BIT_AND",
5
4
  BIT_OR: "BIT_OR",
6
5
  BIT_XOR: "BIT_XOR",
7
6
  BIT_NOT: "BIT_NOT",
8
7
  CASO: "CASO",
8
+ CHAVE_DIREITA: "CHAVE_DIREITA",
9
+ CHAVE_ESQUERDA: "CHAVE_ESQUERDA",
9
10
  CLASSE: "CLASSE",
10
- COLON: "COLON",
11
+ COLCHETE_DIREITO: "COLCHETE_DIREITO",
12
+ COLCHETE_ESQUERDO: "COLCHETE_ESQUERDO",
11
13
  COMMA: "COMMA",
12
14
  CONTINUA: "CONTINUA",
15
+ DIFERENTE: "DIFERENTE",
16
+ DIVISAO: "DIVISAO",
17
+ DOIS_PONTOS: "DOIS_PONTOS",
13
18
  DOT: "DOT",
14
19
  E: "E",
15
20
  EM: "EM",
16
21
  ENQUANTO: "ENQUANTO",
17
22
  EOF: "EOF",
18
- IGUAL: "IGUAL",
19
- IGUAL_IGUAL: "IGUAL_IGUAL",
20
23
  ESCOLHA: "ESCOLHA",
21
24
  ESCREVA: "ESCREVA",
25
+ EXPONENCIACAO: "EXPONENCIACAO",
26
+ IGUAL: "IGUAL",
27
+ IGUAL_IGUAL: "IGUAL_IGUAL",
22
28
  FALSO: "FALSO",
23
29
  FAZER: "FAZER",
24
30
  FINALMENTE: "FINALMENTE",
@@ -30,38 +36,31 @@ module.exports = {
30
36
  IDENTIFICADOR: "IDENTIFICADOR",
31
37
  IMPORTAR: "IMPORTAR",
32
38
  ISTO: "ISTO",
33
- CHAVE_ESQUERDA: "CHAVE_ESQUERDA",
34
- PARENTESE_ESQUERDO: "PARENTESE_ESQUERDO",
35
- COLCHETE_ESQUERDO: "COLCHETE_ESQUERDO",
36
39
  MENOR: "MENOR",
37
40
  MENOR_IGUAL: "MENOR_IGUAL",
38
41
  MENOR_MENOR: "MENOR_MENOR",
39
42
  MAIS_IGUAL: "MAIS_IGUAL",
40
- MENOR_IGUAL: "MENOR_IGUAL",
41
- SUBTRACAO: "SUBTRACAO",
42
- MODULUS: "MODULUS",
43
+ MODULO: "MODULO",
44
+ MULTIPLICACAO: "MULTIPLICACAO",
45
+ NEGACAO: "NEGACAO",
43
46
  NULO: "NULO",
44
47
  NUMERO: "NUMERO",
45
48
  OU: "OU",
46
49
  PADRAO: "PADRAO",
47
50
  PARA: "PARA",
51
+ PARENTESE_DIREITO: "PARENTESE_DIREITO",
52
+ PARENTESE_ESQUERDO: "PARENTESE_ESQUERDO",
48
53
  PAUSA: "PAUSA",
49
54
  PEGUE: "PEGUE",
50
- ADICAO: "ADICAO",
55
+ PONTO_E_VIRGULA: "PONTO_E_VIRGULA",
51
56
  RETORNA: "RETORNA",
52
- PARENTESE_DIREITO: "PARENTESE_DIREITO",
53
- CHAVE_DIREITA: "CHAVE_DIREITA",
54
- COLCHETE_DIREITO: "COLCHETE_DIREITO",
55
- SEMICOLON: "SEMICOLON",
56
- SLASH: "SLASH",
57
- STAR: "STAR",
58
- STAR_STAR: "STAR_STAR",
59
- TEXTO: "TEXTO",
57
+ SUBTRACAO: "SUBTRACAO",
60
58
  SE: "SE",
61
59
  SENAO: "SENAO",
62
60
  SENAOSE: "SENAOSE",
63
61
  SUPER: "SUPER",
64
- TENTE: "TENTE",
62
+ TENTE: "TENTE",
63
+ TEXTO: "TEXTO",
65
64
  VAR: "VAR",
66
65
  VERDADEIRO: "VERDADEIRO"
67
66
  };
package/src/web.ts ADDED
@@ -0,0 +1,75 @@
1
+ import { Lexer } from "./lexador";
2
+ import { Parser } from "./avaliador-sintatico";
3
+ import { Resolver } from "./resolvedor";
4
+ import { Interpretador } from "./interpretador";
5
+ import tiposDeSimbolos from "./tiposDeSimbolos";
6
+
7
+ export class Delegua {
8
+ nomeArquivo: any;
9
+
10
+ teveErro: any;
11
+ teveErroEmTempoDeExecucao: any;
12
+
13
+ constructor(nomeArquivo) {
14
+ this.nomeArquivo = nomeArquivo;
15
+
16
+ this.teveErro = false;
17
+ this.teveErroEmTempoDeExecucao = false;
18
+ }
19
+
20
+ runBlock(codigo: any) {
21
+ const interpretador = new Interpretador(this, process.cwd());
22
+
23
+ const lexer = new Lexer(this);
24
+ const simbolos = lexer.scan(codigo);
25
+
26
+ if (this.teveErro === true) return;
27
+
28
+ const analisar = new Parser(this);
29
+ const declaracoes = analisar.analisar(simbolos);
30
+
31
+ if (this.teveErro === true) return;
32
+
33
+ const resolver = new Resolver(this, interpretador);
34
+ resolver.resolver(declaracoes);
35
+
36
+ if (this.teveErro === true) return;
37
+
38
+ interpretador.interpretar(declaracoes);
39
+ }
40
+
41
+ reportar(linha: any, onde: any, mensagem: any) {
42
+ if (this.nomeArquivo)
43
+ console.error(
44
+ `[Arquivo: ${this.nomeArquivo}] [Linha: ${linha}] Erro${onde}: ${mensagem}`
45
+ );
46
+ else console.error(`[Linha: ${linha}] Erro${onde}: ${mensagem}`);
47
+ this.teveErro = true;
48
+ }
49
+
50
+ erro(simbolo: any, mensagemDeErro: any) {
51
+ if (simbolo.tipo === tiposDeSimbolos.EOF) {
52
+ this.reportar(simbolo.line, " no final", mensagemDeErro);
53
+ } else {
54
+ this.reportar(simbolo.line, ` no '${simbolo.lexema}'`, mensagemDeErro);
55
+ }
56
+ }
57
+
58
+ lexerError(linha, caractere, mensagem) {
59
+ this.reportar(linha, ` no '${caractere}'`, mensagem);
60
+ }
61
+
62
+ erroEmTempoDeExecucao(erro) {
63
+ const linha = erro.simbolo.linha;
64
+ if (erro.simbolo && linha) {
65
+ if (this.nomeArquivo)
66
+ console.error(
67
+ `Erro: [Arquivo: ${this.nomeArquivo}] [Linha: ${erro.simbolo.linha}] ${erro.mensagem}`
68
+ );
69
+ else console.error(`Erro: [Linha: ${erro.simbolo.linha}] ${erro.mensagem}`);
70
+ } else {
71
+ console.error(`Erro: ${erro.mensagem}`);
72
+ }
73
+ this.teveErroEmTempoDeExecucao = true;
74
+ }
75
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "module": "commonjs",
5
+ "target": "ES5",
6
+ "rootDir": ".",
7
+ "allowJs": true,
8
+ "sourceMap": true
9
+ },
10
+ "exclude": ["babel.config.js", "dist/**/*"]
11
+ }
package/indice.js DELETED
@@ -1,14 +0,0 @@
1
- const Delegua = require("./src/delegua.js").Delegua;
2
-
3
- const principal = function() {
4
- const argumentos = process.argv;
5
-
6
- const delegua = new Delegua();
7
- if (argumentos.length === 2) {
8
- delegua.runPrompt();
9
- } else {
10
- delegua.runfile(argumentos[2]);
11
- }
12
- };
13
-
14
- principal();