vladx 1.2.5 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vladx",
3
- "version": "1.2.5",
3
+ "version": "1.3.1",
4
4
  "description": "VladX - Linguaggio di programmazione con sintassi italiana",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
@@ -0,0 +1,12 @@
1
+ variabile passport = {}
2
+ passport.nome = chiedi("Come ti chiami? ")
3
+ passport.eta = chiedi("Quanti anni hai? ")
4
+
5
+ se(passport.eta >= 18) {
6
+ stampa("Sei maggiorenne")
7
+ } altrimenti {
8
+ stampa("Sei minorenne")
9
+ }
10
+ stampa(passport)
11
+
12
+ Archivio.scrivi(`passports/${passport.nome}.txt`, JSON.stringify(passport))
@@ -0,0 +1 @@
1
+ {"nome":"Vlad","eta":"25"}
@@ -0,0 +1,5 @@
1
+ {
2
+ "lockfileVersion": 1,
3
+ "requires": true,
4
+ "dependencies": {}
5
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "main",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.vx",
6
+ "scripts": {
7
+ "start": "vladx index.vx",
8
+ "test": "vladx test.vx"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "MIT",
13
+ "dependencies": {}
14
+ }
@@ -225,6 +225,23 @@ class Interpreter {
225
225
  call: (_, args) => Array.isArray(args[0])
226
226
  });
227
227
 
228
+ this.globals.define('booleano', {
229
+ call: (_, args) => Boolean(args[0])
230
+ });
231
+
232
+ this.globals.define('intero', {
233
+ call: (_, args) => parseInt(args[0])
234
+ });
235
+
236
+ this.globals.define('JSON', {
237
+ stringify: {
238
+ call: (_, args) => JSON.stringify(args[0], args[1], args[2])
239
+ },
240
+ parse: {
241
+ call: (_, args) => JSON.parse(args[0])
242
+ }
243
+ });
244
+
228
245
  this.globals.define('aspetta', {
229
246
  call: (_, args) => {
230
247
  const ms = args[0];
@@ -236,6 +253,32 @@ class Interpreter {
236
253
  }
237
254
  });
238
255
 
256
+ this.globals.define('chiedi', {
257
+ call: (_, args) => {
258
+ if (args[0] !== undefined) {
259
+ process.stdout.write(String(args[0]));
260
+ }
261
+
262
+ const buffer = Buffer.alloc(1);
263
+ let input = '';
264
+
265
+ try {
266
+ while (true) {
267
+ const bytesRead = fs.readSync(0, buffer, 0, 1, null);
268
+ if (bytesRead === 0) break; // EOF
269
+ const char = buffer.toString('utf8');
270
+ if (char === '\n') break;
271
+ if (char === '\r') continue;
272
+ input += char;
273
+ }
274
+ } catch (e) {
275
+ // Ignore errors on read (e.g. pipe closed)
276
+ }
277
+
278
+ return input;
279
+ }
280
+ });
281
+
239
282
  this._registerStdLib();
240
283
  }
241
284