bahasa-simpl 1.0.0 → 1.0.1
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/dist/simpl-interpreter.js +21 -4
- package/package.json +1 -1
|
@@ -273,6 +273,9 @@ class PetikTipe extends Stipe {
|
|
|
273
273
|
this.member.define("ganti", makeBuiltInFunc([petikSymbol, petikSymbol, petikSymbol], petikSymbol,
|
|
274
274
|
(v, [d, what, rep]) => new Value(petikSymbol, d.data.replaceAll(what.data, rep.data))
|
|
275
275
|
));
|
|
276
|
+
this.member.define("besar", makeBuiltInFunc([petikSymbol], petikSymbol, (v, [p]) => {
|
|
277
|
+
return new Value(petikSymbol, p.data.toUpperCase())
|
|
278
|
+
}));
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
281
|
|
|
@@ -284,6 +287,10 @@ class AngkaTipe extends Stipe {
|
|
|
284
287
|
v.error(`Jumlah argumen tidak sama dengan parameter mesin: ${args.length} != 1.`);
|
|
285
288
|
}
|
|
286
289
|
|
|
290
|
+
if (typeof args[0].data === "number") {
|
|
291
|
+
return new Value(angkaSymbol, args[0].data);
|
|
292
|
+
}
|
|
293
|
+
|
|
287
294
|
switch (args[0].type) {
|
|
288
295
|
case petikSymbol:
|
|
289
296
|
if (isNaN(Number(args[0].data))) {
|
|
@@ -295,7 +302,7 @@ class AngkaTipe extends Stipe {
|
|
|
295
302
|
case logisSymbol:
|
|
296
303
|
return new Value(angkaSymbol, Number(args[0].data));
|
|
297
304
|
default:
|
|
298
|
-
v.error(`Tipe yang dapat diterima hanyalah petik, angka, dan
|
|
305
|
+
v.error(`Tipe yang dapat diterima hanyalah petik, angka, logis, dan jenis. Mendapatkan ${args[0].type.description}.`);
|
|
299
306
|
return;
|
|
300
307
|
}
|
|
301
308
|
}
|
|
@@ -339,6 +346,16 @@ class AngkaTipe extends Stipe {
|
|
|
339
346
|
makeBuiltInFunc([angkaSymbol], angkaSymbol, (v, [r]) => new Value(angkaSymbol, -r.data)));
|
|
340
347
|
|
|
341
348
|
this.member = new Environment();
|
|
349
|
+
this.member.define("acak", makeBuiltInFunc([angkaSymbol, angkaSymbol], angkaSymbol, (v, [a,b]) => {
|
|
350
|
+
let width = Math.abs(a.data-b.data);
|
|
351
|
+
let range = Math.random() * width;
|
|
352
|
+
let final = range + Math.min(a.data,b.data);
|
|
353
|
+
return new Value(angkaSymbol, final);
|
|
354
|
+
}));
|
|
355
|
+
|
|
356
|
+
this.member.define("bulat", makeBuiltInFunc([angkaSymbol], angkaSymbol, (v, [a]) => {
|
|
357
|
+
return new Value(angkaSymbol, Math.round(a.data));
|
|
358
|
+
}));
|
|
342
359
|
}
|
|
343
360
|
}
|
|
344
361
|
|
|
@@ -369,7 +386,7 @@ class LogisTipe extends Stipe {
|
|
|
369
386
|
this.operators.define("SERU_UNARY",
|
|
370
387
|
makeBuiltInFunc([logisSymbol], logisSymbol, (v, [r]) => new Value(logisSymbol, !Boolean(r.data))));
|
|
371
388
|
|
|
372
|
-
this.member =
|
|
389
|
+
this.member = new Environment();
|
|
373
390
|
}
|
|
374
391
|
}
|
|
375
392
|
|
|
@@ -433,7 +450,7 @@ class BarisTipe extends Stipe {
|
|
|
433
450
|
class MesinTipe extends Stipe {
|
|
434
451
|
constructor() {
|
|
435
452
|
super(mesinSymbol);
|
|
436
|
-
this.member =
|
|
453
|
+
this.member = new Environment();
|
|
437
454
|
}
|
|
438
455
|
}
|
|
439
456
|
|
|
@@ -1240,7 +1257,7 @@ class Lexer {
|
|
|
1240
1257
|
|
|
1241
1258
|
scan() {
|
|
1242
1259
|
this.skipWhitespaces();
|
|
1243
|
-
|
|
1260
|
+
while (this.see() === '#') {
|
|
1244
1261
|
this.comment();
|
|
1245
1262
|
this.skipWhitespaces();
|
|
1246
1263
|
}
|