@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/lexer.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
const
|
|
1
|
+
const tiposDeSimbolos = require("./tiposDeSimbolos.js");
|
|
2
2
|
|
|
3
3
|
const palavrasReservadas = {
|
|
4
|
-
e:
|
|
5
|
-
em:
|
|
6
|
-
classe:
|
|
7
|
-
senao:
|
|
8
|
-
falso:
|
|
9
|
-
para:
|
|
10
|
-
funcao:
|
|
11
|
-
se:
|
|
12
|
-
senaose:
|
|
13
|
-
nulo:
|
|
14
|
-
ou:
|
|
15
|
-
escreva:
|
|
16
|
-
retorna:
|
|
17
|
-
super:
|
|
18
|
-
isto:
|
|
19
|
-
verdadeiro:
|
|
20
|
-
var:
|
|
21
|
-
fazer:
|
|
22
|
-
enquanto:
|
|
23
|
-
pausa:
|
|
24
|
-
continua:
|
|
25
|
-
escolha:
|
|
26
|
-
caso:
|
|
27
|
-
padrao:
|
|
28
|
-
importar:
|
|
29
|
-
tente:
|
|
30
|
-
pegue:
|
|
31
|
-
finalmente:
|
|
32
|
-
herda:
|
|
4
|
+
e: tiposDeSimbolos.E,
|
|
5
|
+
em: tiposDeSimbolos.EM,
|
|
6
|
+
classe: tiposDeSimbolos.CLASSE,
|
|
7
|
+
senao: tiposDeSimbolos.SENAO,
|
|
8
|
+
falso: tiposDeSimbolos.FALSO,
|
|
9
|
+
para: tiposDeSimbolos.PARA,
|
|
10
|
+
funcao: tiposDeSimbolos.FUNCAO,
|
|
11
|
+
se: tiposDeSimbolos.SE,
|
|
12
|
+
senaose: tiposDeSimbolos.SENAOSE,
|
|
13
|
+
nulo: tiposDeSimbolos.NULO,
|
|
14
|
+
ou: tiposDeSimbolos.OU,
|
|
15
|
+
escreva: tiposDeSimbolos.ESCREVA,
|
|
16
|
+
retorna: tiposDeSimbolos.RETORNA,
|
|
17
|
+
super: tiposDeSimbolos.SUPER,
|
|
18
|
+
isto: tiposDeSimbolos.ISTO,
|
|
19
|
+
verdadeiro: tiposDeSimbolos.VERDADEIRO,
|
|
20
|
+
var: tiposDeSimbolos.VAR,
|
|
21
|
+
fazer: tiposDeSimbolos.FAZER,
|
|
22
|
+
enquanto: tiposDeSimbolos.ENQUANTO,
|
|
23
|
+
pausa: tiposDeSimbolos.PAUSA,
|
|
24
|
+
continua: tiposDeSimbolos.CONTINUA,
|
|
25
|
+
escolha: tiposDeSimbolos.ESCOLHA,
|
|
26
|
+
caso: tiposDeSimbolos.CASO,
|
|
27
|
+
padrao: tiposDeSimbolos.PADRAO,
|
|
28
|
+
importar: tiposDeSimbolos.IMPORTAR,
|
|
29
|
+
tente: tiposDeSimbolos.TENTE,
|
|
30
|
+
pegue: tiposDeSimbolos.PEGUE,
|
|
31
|
+
finalmente: tiposDeSimbolos.FINALMENTE,
|
|
32
|
+
herda: tiposDeSimbolos.HERDA
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
class
|
|
35
|
+
class Simbolo {
|
|
36
36
|
constructor(tipo, lexeme, literal, linha) {
|
|
37
37
|
this.tipo = tipo;
|
|
38
38
|
this.lexeme = lexeme;
|
|
@@ -52,8 +52,8 @@ class Token {
|
|
|
52
52
|
* estruturas, tais como nomes de variáveis, funções, literais, classes e assim por diante.
|
|
53
53
|
*/
|
|
54
54
|
module.exports = class Lexer {
|
|
55
|
-
constructor(codigo,
|
|
56
|
-
this.
|
|
55
|
+
constructor(codigo, Delegua) {
|
|
56
|
+
this.Delegua = Delegua;
|
|
57
57
|
this.codigo = codigo;
|
|
58
58
|
|
|
59
59
|
this.simbolos = [];
|
|
@@ -63,19 +63,19 @@ module.exports = class Lexer {
|
|
|
63
63
|
this.linha = 1;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
eDigito(
|
|
67
|
-
return
|
|
66
|
+
eDigito(caractere) {
|
|
67
|
+
return caractere >= "0" && caractere <= "9";
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
eAlfabeto(
|
|
71
|
-
return (
|
|
70
|
+
eAlfabeto(caractere) {
|
|
71
|
+
return (caractere >= "a" && caractere <= "z") || (caractere >= "A" && caractere <= "Z") || caractere == "_";
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
eAlfabetoOuDigito(
|
|
75
|
-
return this.eDigito(
|
|
74
|
+
eAlfabetoOuDigito(caractere) {
|
|
75
|
+
return this.eDigito(caractere) || this.eAlfabeto(caractere);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
eFinalDoCodigo() {
|
|
79
79
|
return this.atual >= this.codigo.length;
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -86,11 +86,11 @@ module.exports = class Lexer {
|
|
|
86
86
|
|
|
87
87
|
adicionarSimbolo(tipo, literal = null) {
|
|
88
88
|
const texto = this.codigo.substring(this.inicio, this.atual);
|
|
89
|
-
this.simbolos.push(new
|
|
89
|
+
this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
match(esperado) {
|
|
93
|
-
if (this.
|
|
93
|
+
if (this.eFinalDoCodigo()) {
|
|
94
94
|
return false;
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -103,7 +103,7 @@ module.exports = class Lexer {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
peek() {
|
|
106
|
-
if (this.
|
|
106
|
+
if (this.eFinalDoCodigo()) return "\0";
|
|
107
107
|
return this.codigo.charAt(this.atual);
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -116,14 +116,14 @@ module.exports = class Lexer {
|
|
|
116
116
|
return this.codigo.charAt(this.atual - 1);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
analisarTexto(
|
|
120
|
-
while (this.peek() !==
|
|
119
|
+
analisarTexto(texto = '"') {
|
|
120
|
+
while (this.peek() !== texto && !this.eFinalDoCodigo()) {
|
|
121
121
|
if (this.peek() === "\n") this.linha = +1;
|
|
122
122
|
this.avancar();
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
if (this.
|
|
126
|
-
this.
|
|
125
|
+
if (this.eFinalDoCodigo()) {
|
|
126
|
+
this.Delegua.lexerError(
|
|
127
127
|
this.linha,
|
|
128
128
|
this.voltar(),
|
|
129
129
|
"Texto não finalizado."
|
|
@@ -134,7 +134,7 @@ module.exports = class Lexer {
|
|
|
134
134
|
this.avancar();
|
|
135
135
|
|
|
136
136
|
const valor = this.codigo.substring(this.inicio + 1, this.atual - 1);
|
|
137
|
-
this.adicionarSimbolo(
|
|
137
|
+
this.adicionarSimbolo(tiposDeSimbolos.TEXTO, valor);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
analisarNumero() {
|
|
@@ -151,7 +151,7 @@ module.exports = class Lexer {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
const numeroCompleto = this.codigo.substring(this.inicio, this.atual);
|
|
154
|
-
this.adicionarSimbolo(
|
|
154
|
+
this.adicionarSimbolo(tiposDeSimbolos.NUMERO, parseFloat(numeroCompleto));
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
identificarPalavraChave() {
|
|
@@ -159,121 +159,121 @@ module.exports = class Lexer {
|
|
|
159
159
|
this.avancar();
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
const
|
|
163
|
-
const tipo =
|
|
162
|
+
const codigo = this.codigo.substring(this.inicio, this.atual);
|
|
163
|
+
const tipo = codigo in palavrasReservadas ? palavrasReservadas[codigo] : tiposDeSimbolos.IDENTIFICADOR;
|
|
164
164
|
|
|
165
165
|
this.adicionarSimbolo(tipo);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
scanToken() {
|
|
169
|
-
const
|
|
169
|
+
const caractere = this.avancar();
|
|
170
170
|
|
|
171
|
-
switch (
|
|
171
|
+
switch (caractere) {
|
|
172
172
|
case "[":
|
|
173
|
-
this.adicionarSimbolo(
|
|
173
|
+
this.adicionarSimbolo(tiposDeSimbolos.COLCHETE_ESQUERDO);
|
|
174
174
|
break;
|
|
175
175
|
case "]":
|
|
176
|
-
this.adicionarSimbolo(
|
|
176
|
+
this.adicionarSimbolo(tiposDeSimbolos.COLCHETE_DIREITO);
|
|
177
177
|
break;
|
|
178
178
|
case "(":
|
|
179
|
-
this.adicionarSimbolo(
|
|
179
|
+
this.adicionarSimbolo(tiposDeSimbolos.PARENTESE_ESQUERDO);
|
|
180
180
|
break;
|
|
181
181
|
case ")":
|
|
182
|
-
this.adicionarSimbolo(
|
|
182
|
+
this.adicionarSimbolo(tiposDeSimbolos.PARENTESE_DIREITO);
|
|
183
183
|
break;
|
|
184
184
|
case "{":
|
|
185
|
-
this.adicionarSimbolo(
|
|
185
|
+
this.adicionarSimbolo(tiposDeSimbolos.CHAVE_ESQUERDA);
|
|
186
186
|
break;
|
|
187
187
|
case "}":
|
|
188
|
-
this.adicionarSimbolo(
|
|
188
|
+
this.adicionarSimbolo(tiposDeSimbolos.CHAVE_DIREITA);
|
|
189
189
|
break;
|
|
190
190
|
case ",":
|
|
191
|
-
this.adicionarSimbolo(
|
|
191
|
+
this.adicionarSimbolo(tiposDeSimbolos.COMMA);
|
|
192
192
|
break;
|
|
193
193
|
case ".":
|
|
194
|
-
this.adicionarSimbolo(
|
|
194
|
+
this.adicionarSimbolo(tiposDeSimbolos.DOT);
|
|
195
195
|
break;
|
|
196
196
|
case "-":
|
|
197
197
|
if (this.match("=")) {
|
|
198
|
-
this.adicionarSimbolo(
|
|
198
|
+
this.adicionarSimbolo(tiposDeSimbolos.MENOR_IGUAL);
|
|
199
199
|
}
|
|
200
|
-
this.adicionarSimbolo(
|
|
200
|
+
this.adicionarSimbolo(tiposDeSimbolos.SUBTRACAO);
|
|
201
201
|
break;
|
|
202
202
|
case "+":
|
|
203
203
|
if (this.match("=")) {
|
|
204
|
-
this.adicionarSimbolo(
|
|
204
|
+
this.adicionarSimbolo(tiposDeSimbolos.MAIS_IGUAL);
|
|
205
205
|
}
|
|
206
|
-
this.adicionarSimbolo(
|
|
206
|
+
this.adicionarSimbolo(tiposDeSimbolos.ADICAO);
|
|
207
207
|
break;
|
|
208
208
|
case ":":
|
|
209
|
-
this.adicionarSimbolo(
|
|
209
|
+
this.adicionarSimbolo(tiposDeSimbolos.COLON);
|
|
210
210
|
break;
|
|
211
211
|
case ";":
|
|
212
|
-
this.adicionarSimbolo(
|
|
212
|
+
this.adicionarSimbolo(tiposDeSimbolos.SEMICOLON);
|
|
213
213
|
break;
|
|
214
214
|
case "%":
|
|
215
|
-
this.adicionarSimbolo(
|
|
215
|
+
this.adicionarSimbolo(tiposDeSimbolos.MODULUS);
|
|
216
216
|
break;
|
|
217
217
|
case "*":
|
|
218
218
|
if (this.peek() === "*") {
|
|
219
219
|
this.avancar();
|
|
220
|
-
this.adicionarSimbolo(
|
|
220
|
+
this.adicionarSimbolo(tiposDeSimbolos.STAR_STAR);
|
|
221
221
|
break;
|
|
222
222
|
}
|
|
223
|
-
this.adicionarSimbolo(
|
|
223
|
+
this.adicionarSimbolo(tiposDeSimbolos.STAR);
|
|
224
224
|
break;
|
|
225
225
|
case "!":
|
|
226
226
|
this.adicionarSimbolo(
|
|
227
|
-
this.match("=") ?
|
|
227
|
+
this.match("=") ? tiposDeSimbolos.DIFERENTE : tiposDeSimbolos.NEGACAO
|
|
228
228
|
);
|
|
229
229
|
break;
|
|
230
230
|
case "=":
|
|
231
231
|
this.adicionarSimbolo(
|
|
232
|
-
this.match("=") ?
|
|
232
|
+
this.match("=") ? tiposDeSimbolos.IGUAL_IGUAL : tiposDeSimbolos.IGUAL
|
|
233
233
|
);
|
|
234
234
|
break;
|
|
235
235
|
|
|
236
236
|
case "&":
|
|
237
|
-
this.adicionarSimbolo(
|
|
237
|
+
this.adicionarSimbolo(tiposDeSimbolos.BIT_AND);
|
|
238
238
|
break;
|
|
239
239
|
|
|
240
240
|
case "~":
|
|
241
|
-
this.adicionarSimbolo(
|
|
241
|
+
this.adicionarSimbolo(tiposDeSimbolos.BIT_NOT);
|
|
242
242
|
break;
|
|
243
243
|
|
|
244
244
|
case "|":
|
|
245
|
-
this.adicionarSimbolo(
|
|
245
|
+
this.adicionarSimbolo(tiposDeSimbolos.BIT_OR);
|
|
246
246
|
break;
|
|
247
247
|
|
|
248
248
|
case "^":
|
|
249
|
-
this.adicionarSimbolo(
|
|
249
|
+
this.adicionarSimbolo(tiposDeSimbolos.BIT_XOR);
|
|
250
250
|
break;
|
|
251
251
|
|
|
252
252
|
case "<":
|
|
253
253
|
if (this.match("=")) {
|
|
254
|
-
this.adicionarSimbolo(
|
|
254
|
+
this.adicionarSimbolo(tiposDeSimbolos.MENOR_IGUAL);
|
|
255
255
|
} else if (this.match("<")) {
|
|
256
|
-
this.adicionarSimbolo(
|
|
256
|
+
this.adicionarSimbolo(tiposDeSimbolos.MENOR_MENOR);
|
|
257
257
|
} else {
|
|
258
|
-
this.adicionarSimbolo(
|
|
258
|
+
this.adicionarSimbolo(tiposDeSimbolos.MENOR);
|
|
259
259
|
}
|
|
260
260
|
break;
|
|
261
261
|
|
|
262
262
|
case ">":
|
|
263
263
|
if (this.match("=")) {
|
|
264
|
-
this.adicionarSimbolo(
|
|
264
|
+
this.adicionarSimbolo(tiposDeSimbolos.MAIOR_IGUAL);
|
|
265
265
|
} else if (this.match(">")) {
|
|
266
|
-
this.adicionarSimbolo(
|
|
266
|
+
this.adicionarSimbolo(tiposDeSimbolos.MAIOR_MAIOR);
|
|
267
267
|
} else {
|
|
268
|
-
this.adicionarSimbolo(
|
|
268
|
+
this.adicionarSimbolo(tiposDeSimbolos.MAIOR);
|
|
269
269
|
}
|
|
270
270
|
break;
|
|
271
271
|
|
|
272
272
|
case "/":
|
|
273
273
|
if (this.match("/")) {
|
|
274
|
-
while (this.peek() != "\n" && !this.
|
|
274
|
+
while (this.peek() != "\n" && !this.eFinalDoCodigo()) this.avancar();
|
|
275
275
|
} else {
|
|
276
|
-
this.adicionarSimbolo(
|
|
276
|
+
this.adicionarSimbolo(tiposDeSimbolos.SLASH);
|
|
277
277
|
}
|
|
278
278
|
break;
|
|
279
279
|
|
|
@@ -297,19 +297,20 @@ module.exports = class Lexer {
|
|
|
297
297
|
break;
|
|
298
298
|
|
|
299
299
|
default:
|
|
300
|
-
if (this.eDigito(
|
|
301
|
-
else if (this.eAlfabeto(
|
|
302
|
-
else this.
|
|
300
|
+
if (this.eDigito(caractere)) this.analisarNumero();
|
|
301
|
+
else if (this.eAlfabeto(caractere)) this.identificarPalavraChave();
|
|
302
|
+
else this.Delegua.lexerError(this.linha, caractere, "Caractere inesperado.");
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
scan() {
|
|
307
|
-
while (!this.
|
|
307
|
+
while (!this.eFinalDoCodigo()) {
|
|
308
308
|
this.inicio = this.atual;
|
|
309
309
|
this.scanToken();
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
this.simbolos.push(new
|
|
312
|
+
this.simbolos.push(new Simbolo(tiposDeSimbolos.EOF, "", null, this.linha));
|
|
313
|
+
|
|
313
314
|
return this.simbolos;
|
|
314
315
|
}
|
|
315
316
|
};
|
package/src/lib/globalLib.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao,
|
|
2
|
+
DeleguaFuncao = require("../estruturas/funcao.js"),
|
|
3
|
+
DeleguaInstancia = require("../estruturas/instancia.js"),
|
|
4
|
+
FuncaoPadrao = require("../estruturas/funcaoPadrao.js"),
|
|
5
|
+
DeleguaClasse = require("../estruturas/classe.js");
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
module.exports = function (
|
|
8
|
+
module.exports = function (interpretador, globals) {
|
|
9
9
|
// Retorna um número aleatório entre 0 e 1.
|
|
10
|
-
globals.
|
|
10
|
+
globals.definirVariavel(
|
|
11
11
|
"aleatorio",
|
|
12
|
-
new
|
|
12
|
+
new FuncaoPadrao(1, function () {
|
|
13
13
|
return Math.random();
|
|
14
14
|
})
|
|
15
15
|
);
|
|
16
16
|
|
|
17
17
|
// Retorna um número aleatório de acordo com o parâmetro passado.
|
|
18
18
|
// MIN(inclusivo) - MAX(exclusivo)
|
|
19
|
-
globals.
|
|
19
|
+
globals.definirVariavel(
|
|
20
20
|
"aleatorioEntre",
|
|
21
|
-
new
|
|
21
|
+
new FuncaoPadrao(1, function (min, max) {
|
|
22
22
|
if (typeof min !== 'number' || typeof max !== 'number') {
|
|
23
|
-
throw new
|
|
24
|
-
this.
|
|
23
|
+
throw new ErroEmTempoDeExecucao(
|
|
24
|
+
this.simbolo,
|
|
25
25
|
"Os dois parâmetros devem ser do tipo número."
|
|
26
26
|
);
|
|
27
27
|
}
|
|
@@ -30,49 +30,49 @@ module.exports = function (interpreter, globals) {
|
|
|
30
30
|
})
|
|
31
31
|
);
|
|
32
32
|
|
|
33
|
-
globals.
|
|
33
|
+
globals.definirVariavel(
|
|
34
34
|
"inteiro",
|
|
35
|
-
new
|
|
36
|
-
if (
|
|
37
|
-
throw new
|
|
38
|
-
this.
|
|
35
|
+
new FuncaoPadrao(1, function (valor) {
|
|
36
|
+
if (valor === undefined || valor === null) {
|
|
37
|
+
throw new ErroEmTempoDeExecucao(
|
|
38
|
+
this.simbolo,
|
|
39
39
|
"Somente números podem passar para inteiro."
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
if (!/^-{0,1}\d+$/.test(
|
|
44
|
-
throw new
|
|
45
|
-
this.
|
|
43
|
+
if (!/^-{0,1}\d+$/.test(valor) && !/^\d+\.\d+$/.test(valor)) {
|
|
44
|
+
throw new ErroEmTempoDeExecucao(
|
|
45
|
+
this.simbolo,
|
|
46
46
|
"Somente números podem passar para inteiro."
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
return parseInt(
|
|
50
|
+
return parseInt(valor);
|
|
51
51
|
})
|
|
52
52
|
);
|
|
53
53
|
|
|
54
|
-
globals.
|
|
54
|
+
globals.definirVariavel(
|
|
55
55
|
"mapear",
|
|
56
|
-
new
|
|
56
|
+
new FuncaoPadrao(1, function (array, callback) {
|
|
57
57
|
if (!Array.isArray(array)) {
|
|
58
|
-
throw new
|
|
59
|
-
this.
|
|
58
|
+
throw new ErroEmTempoDeExecucao(
|
|
59
|
+
this.simbolo,
|
|
60
60
|
"Parâmetro inválido. O primeiro parâmetro da função, deve ser um array."
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
if (callback.constructor.
|
|
65
|
-
throw new
|
|
66
|
-
this.
|
|
64
|
+
if (callback.constructor.nome !== 'DeleguaFuncao') {
|
|
65
|
+
throw new ErroEmTempoDeExecucao(
|
|
66
|
+
this.simbolo,
|
|
67
67
|
"Parâmetro inválido. O segundo parâmetro da função, deve ser uma função."
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
let provisorio = [];
|
|
72
|
-
for (let
|
|
72
|
+
for (let indice = 0; indice < array.length; ++indice) {
|
|
73
73
|
provisorio.push(
|
|
74
74
|
callback.call(
|
|
75
|
-
|
|
75
|
+
interpretador, [array[indice]]
|
|
76
76
|
)
|
|
77
77
|
);
|
|
78
78
|
}
|
|
@@ -81,12 +81,12 @@ module.exports = function (interpreter, globals) {
|
|
|
81
81
|
})
|
|
82
82
|
);
|
|
83
83
|
|
|
84
|
-
globals.
|
|
84
|
+
globals.definirVariavel(
|
|
85
85
|
"ordenar",
|
|
86
|
-
new
|
|
86
|
+
new FuncaoPadrao(1, function (obj) {
|
|
87
87
|
if (Array.isArray(obj) == false) {
|
|
88
|
-
throw new
|
|
89
|
-
this.
|
|
88
|
+
throw new ErroEmTempoDeExecucao(
|
|
89
|
+
this.simbolo,
|
|
90
90
|
"Valor Inválido. Objeto inserido não é um vetor."
|
|
91
91
|
);
|
|
92
92
|
}
|
|
@@ -106,66 +106,66 @@ module.exports = function (interpreter, globals) {
|
|
|
106
106
|
})
|
|
107
107
|
);
|
|
108
108
|
|
|
109
|
-
globals.
|
|
109
|
+
globals.definirVariavel(
|
|
110
110
|
"real",
|
|
111
|
-
new
|
|
112
|
-
if (!/^-{0,1}\d+$/.test(
|
|
113
|
-
throw new
|
|
114
|
-
this.
|
|
111
|
+
new FuncaoPadrao(1, function (valor) {
|
|
112
|
+
if (!/^-{0,1}\d+$/.test(valor) && !/^\d+\.\d+$/.test(valor))
|
|
113
|
+
throw new ErroEmTempoDeExecucao(
|
|
114
|
+
this.simbolo,
|
|
115
115
|
"Somente números podem passar para real."
|
|
116
116
|
);
|
|
117
|
-
return parseFloat(
|
|
117
|
+
return parseFloat(valor);
|
|
118
118
|
})
|
|
119
119
|
);
|
|
120
120
|
|
|
121
|
-
globals.
|
|
121
|
+
globals.definirVariavel(
|
|
122
122
|
"tamanho",
|
|
123
|
-
new
|
|
124
|
-
if (!isNaN(
|
|
125
|
-
throw new
|
|
126
|
-
this.
|
|
123
|
+
new FuncaoPadrao(1, function (objeto) {
|
|
124
|
+
if (!isNaN(objeto)) {
|
|
125
|
+
throw new ErroEmTempoDeExecucao(
|
|
126
|
+
this.simbolo,
|
|
127
127
|
"Não é possível encontrar o tamanho de um número."
|
|
128
128
|
);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
if (
|
|
132
|
-
throw new
|
|
133
|
-
this.
|
|
131
|
+
if (objeto instanceof DeleguaInstancia) {
|
|
132
|
+
throw new ErroEmTempoDeExecucao(
|
|
133
|
+
this.simbolo,
|
|
134
134
|
"Você não pode encontrar o tamanho de uma declaração."
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
if (
|
|
139
|
-
return
|
|
138
|
+
if (objeto instanceof DeleguaFuncao) {
|
|
139
|
+
return objeto.declaracao.parametros.length;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
if (
|
|
143
|
-
return
|
|
142
|
+
if (objeto instanceof FuncaoPadrao) {
|
|
143
|
+
return objeto.valorAridade;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
if (
|
|
147
|
-
let
|
|
148
|
-
let
|
|
146
|
+
if (objeto instanceof DeleguaClasse) {
|
|
147
|
+
let metodos = objeto.metodos;
|
|
148
|
+
let tamanho = 0;
|
|
149
149
|
|
|
150
|
-
if (
|
|
151
|
-
|
|
150
|
+
if (metodos.init && metodos.init.eInicializador) {
|
|
151
|
+
tamanho = metodos.init.declaracao.parametros.length;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
return
|
|
154
|
+
return tamanho;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
return
|
|
157
|
+
return objeto.length;
|
|
158
158
|
})
|
|
159
159
|
);
|
|
160
160
|
|
|
161
|
-
globals.
|
|
161
|
+
globals.definirVariavel(
|
|
162
162
|
"texto",
|
|
163
|
-
new
|
|
164
|
-
return `${
|
|
163
|
+
new FuncaoPadrao(1, function (valor) {
|
|
164
|
+
return `${valor}`;
|
|
165
165
|
})
|
|
166
166
|
);
|
|
167
167
|
|
|
168
|
-
globals.
|
|
168
|
+
globals.definirVariavel("exports", {});
|
|
169
169
|
|
|
170
170
|
return globals;
|
|
171
171
|
};
|
package/src/lib/importStdlib.js
CHANGED
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const ErroEmTempoDeExecucao = require("../erro.js").ErroEmTempoDeExecucao,
|
|
2
|
+
FuncaoPadrao = require("../estruturas/funcaoPadrao.js"),
|
|
3
|
+
DeleguaModulo = require("../estruturas/modulo.js");
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
let
|
|
5
|
+
const carregarModulo = function (nomeDoModulo, caminhoDoModulo) {
|
|
6
|
+
let dadosDoModulo;
|
|
7
7
|
try {
|
|
8
|
-
|
|
8
|
+
dadosDoModulo = require(caminhoDoModulo);
|
|
9
9
|
} catch (erro) {
|
|
10
|
-
throw new
|
|
10
|
+
throw new ErroEmTempoDeExecucao(nomeDoModulo, `Biblioteca ${nomeDoModulo} não encontrada para importação.`);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
let
|
|
13
|
+
let novoModulo = new DeleguaModulo(nomeDoModulo);
|
|
14
14
|
|
|
15
|
-
let
|
|
16
|
-
for (let i = 0; i <
|
|
17
|
-
|
|
15
|
+
let chaves = Object.keys(dadosDoModulo);
|
|
16
|
+
for (let i = 0; i < chaves.length; i++) {
|
|
17
|
+
const moduloAtual = dadosDoModulo[chaves[i]];
|
|
18
18
|
|
|
19
|
-
if (typeof
|
|
20
|
-
|
|
19
|
+
if (typeof moduloAtual === "function") {
|
|
20
|
+
novoModulo[chaves[i]] = new FuncaoPadrao(moduloAtual.length, moduloAtual);
|
|
21
21
|
} else {
|
|
22
|
-
|
|
22
|
+
novoModulo[chaves[i]] = moduloAtual;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
return
|
|
26
|
+
return novoModulo;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
module.exports = function (name) {
|
|
33
|
-
switch (name) {
|
|
34
|
-
case "tempo":
|
|
35
|
-
return loadModule("tempo", "./tempo.js");
|
|
36
|
-
case "eguamat":
|
|
37
|
-
return loadModule("eguamat", "./eguamat.js");
|
|
38
|
-
default:
|
|
39
|
-
return loadModule(name, name);
|
|
40
|
-
}
|
|
29
|
+
module.exports = function (nome) {
|
|
30
|
+
//TODO:Samuel: Precisa testar ainda.
|
|
31
|
+
return carregarModulo(nome, nome);
|
|
41
32
|
};
|