vladx 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/bin/vladpm +9 -0
- package/bin/vladx +10 -0
- package/examples/esempio.vx +79 -0
- package/package.json +23 -0
- package/src/cli/cli.js +191 -0
- package/src/index.js +32 -0
- package/src/interpreter/interpreter.js +455 -0
- package/src/lexer/lexer.js +284 -0
- package/src/lexer/tokens.js +116 -0
- package/src/parser/ast.js +265 -0
- package/src/parser/parser.js +476 -0
- package/src/pm/cli.js +130 -0
- package/src/pm/commands/config.js +76 -0
- package/src/pm/commands/init.js +129 -0
- package/src/pm/commands/install.js +185 -0
- package/src/pm/commands/list.js +70 -0
- package/src/pm/commands/login.js +124 -0
- package/src/pm/commands/publish.js +115 -0
- package/src/pm/commands/search.js +55 -0
- package/src/pm/commands/uninstall.js +68 -0
- package/src/pm/utils/api.js +135 -0
- package/src/pm/utils/config.js +117 -0
- package/src/repl/repl.js +179 -0
package/bin/vladpm
ADDED
package/bin/vladx
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// ========================================
|
|
2
|
+
// VladX - File di Esempio
|
|
3
|
+
// ========================================
|
|
4
|
+
|
|
5
|
+
// Variabili e costanti
|
|
6
|
+
variabile messaggio = "Benvenuto in VladX!";
|
|
7
|
+
costante PI = 3.14159;
|
|
8
|
+
variabile contatore = 0;
|
|
9
|
+
|
|
10
|
+
stampa(messaggio);
|
|
11
|
+
|
|
12
|
+
// Funzione semplice
|
|
13
|
+
funzione saluta(nome) {
|
|
14
|
+
stampa("Ciao, " + nome + "!");
|
|
15
|
+
ritorna vero;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
saluta("Mondo");
|
|
19
|
+
|
|
20
|
+
// Funzione con calcoli
|
|
21
|
+
funzione calcolaAreaCerchio(raggio) {
|
|
22
|
+
variabile area = PI * raggio * raggio;
|
|
23
|
+
ritorna area;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
variabile area = calcolaAreaCerchio(5);
|
|
27
|
+
stampa("Area cerchio: " + area);
|
|
28
|
+
|
|
29
|
+
// Condizionali
|
|
30
|
+
se (contatore == 0) {
|
|
31
|
+
stampa("Il contatore รจ zero");
|
|
32
|
+
} altrimenti {
|
|
33
|
+
stampa("Il contatore non รจ zero");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Ciclo mentre
|
|
37
|
+
mentre (contatore < 3) {
|
|
38
|
+
stampa("Iterazione: " + contatore);
|
|
39
|
+
contatore++;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Ciclo per
|
|
43
|
+
stampa("Numeri da 0 a 4:");
|
|
44
|
+
per (variabile i = 0; i < 5; i++) {
|
|
45
|
+
stampa(i);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Array
|
|
49
|
+
variabile numeri = [1, 2, 3, 4, 5];
|
|
50
|
+
stampa("Array: " + numeri);
|
|
51
|
+
stampa("Lunghezza: " + lunghezza(numeri));
|
|
52
|
+
|
|
53
|
+
// Oggetti
|
|
54
|
+
variabile persona = {
|
|
55
|
+
nome: "Mario",
|
|
56
|
+
cognome: "Rossi",
|
|
57
|
+
eta: 30
|
|
58
|
+
};
|
|
59
|
+
stampa("Persona: " + persona);
|
|
60
|
+
stampa("Nome: " + persona.nome);
|
|
61
|
+
|
|
62
|
+
// Operatori logici
|
|
63
|
+
variabile condizione = vero e non falso;
|
|
64
|
+
stampa("Condizione (vero e non falso): " + condizione);
|
|
65
|
+
|
|
66
|
+
// Arrow function
|
|
67
|
+
costante somma = (a, b) => a + b;
|
|
68
|
+
stampa("Somma 3 + 4: " + somma(3, 4));
|
|
69
|
+
|
|
70
|
+
// Funzione ricorsiva
|
|
71
|
+
funzione fattoriale(n) {
|
|
72
|
+
se (n <= 1) {
|
|
73
|
+
ritorna 1;
|
|
74
|
+
}
|
|
75
|
+
ritorna n * fattoriale(n - 1);
|
|
76
|
+
}
|
|
77
|
+
stampa("Fattoriale di 5: " + fattoriale(5));
|
|
78
|
+
|
|
79
|
+
stampa("Programma terminato!");
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vladx",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "VladX - Linguaggio di programmazione con sintassi italiana",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"vladx": "./bin/vladx",
|
|
9
|
+
"vladpm": "./bin/vladpm"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "node bin/vladx",
|
|
13
|
+
"repl": "node bin/vladx repl"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"language",
|
|
17
|
+
"italian",
|
|
18
|
+
"programming",
|
|
19
|
+
"interpreter"
|
|
20
|
+
],
|
|
21
|
+
"author": "VladX Team",
|
|
22
|
+
"license": "MIT"
|
|
23
|
+
}
|
package/src/cli/cli.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VladX CLI
|
|
3
|
+
* Command Line Interface
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { Lexer } = require('../lexer/lexer.js');
|
|
9
|
+
const { Parser } = require('../parser/parser.js');
|
|
10
|
+
const { Interpreter } = require('../interpreter/interpreter.js');
|
|
11
|
+
const { startREPL } = require('../repl/repl.js');
|
|
12
|
+
|
|
13
|
+
const VERSION = '1.0.0';
|
|
14
|
+
|
|
15
|
+
const COLORS = {
|
|
16
|
+
reset: '\x1b[0m',
|
|
17
|
+
bright: '\x1b[1m',
|
|
18
|
+
red: '\x1b[31m',
|
|
19
|
+
green: '\x1b[32m',
|
|
20
|
+
yellow: '\x1b[33m',
|
|
21
|
+
cyan: '\x1b[36m'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function colorize(text, color) {
|
|
25
|
+
return `${COLORS[color]}${text}${COLORS.reset}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function showHelp() {
|
|
29
|
+
console.log(`
|
|
30
|
+
${colorize('VladX', 'bright')} - Linguaggio di programmazione con sintassi italiana
|
|
31
|
+
|
|
32
|
+
${colorize('Uso:', 'cyan')}
|
|
33
|
+
vladx Avvia REPL interattivo
|
|
34
|
+
vladx <file.vx> Esegue un file VladX
|
|
35
|
+
vladx repl Avvia REPL interattivo
|
|
36
|
+
vladx run <file.vx> Esegue un file VladX
|
|
37
|
+
vladx lex <file.vx> Mostra i token del file
|
|
38
|
+
vladx ast <file.vx> Mostra l'AST del file
|
|
39
|
+
vladx --help, -h Mostra questo aiuto
|
|
40
|
+
vladx --version, -v Mostra la versione
|
|
41
|
+
|
|
42
|
+
${colorize('Esempi:', 'cyan')}
|
|
43
|
+
vladx programma.vx Esegue programma.vx
|
|
44
|
+
vladx Avvia modalitร interattiva
|
|
45
|
+
|
|
46
|
+
${colorize('Estensione file:', 'cyan')} .vx
|
|
47
|
+
`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function showVersion() {
|
|
51
|
+
console.log(`VladX v${VERSION}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function runFile(filePath) {
|
|
55
|
+
const absolutePath = path.resolve(filePath);
|
|
56
|
+
|
|
57
|
+
if (!fs.existsSync(absolutePath)) {
|
|
58
|
+
console.error(colorize(`โ Errore: File non trovato: ${filePath}`, 'red'));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const code = fs.readFileSync(absolutePath, 'utf8');
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const lexer = new Lexer(code);
|
|
66
|
+
const tokens = lexer.tokenize();
|
|
67
|
+
|
|
68
|
+
const parser = new Parser(tokens);
|
|
69
|
+
const ast = parser.parse();
|
|
70
|
+
|
|
71
|
+
const interpreter = new Interpreter();
|
|
72
|
+
interpreter.interpret(ast);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error(colorize(`โ Errore: ${error.message}`, 'red'));
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function showTokens(filePath) {
|
|
80
|
+
const absolutePath = path.resolve(filePath);
|
|
81
|
+
|
|
82
|
+
if (!fs.existsSync(absolutePath)) {
|
|
83
|
+
console.error(colorize(`โ Errore: File non trovato: ${filePath}`, 'red'));
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const code = fs.readFileSync(absolutePath, 'utf8');
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const lexer = new Lexer(code);
|
|
91
|
+
const tokens = lexer.tokenize();
|
|
92
|
+
|
|
93
|
+
console.log(colorize('\n๐ Token:\n', 'bright'));
|
|
94
|
+
tokens.forEach(token => {
|
|
95
|
+
console.log(` ${token.type.padEnd(20)} ${JSON.stringify(token.value).padEnd(20)} [riga ${token.line}, col ${token.column}]`);
|
|
96
|
+
});
|
|
97
|
+
console.log(`\n${colorize('Totale:', 'cyan')} ${tokens.length} token\n`);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(colorize(`โ Errore: ${error.message}`, 'red'));
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function showAST(filePath) {
|
|
105
|
+
const absolutePath = path.resolve(filePath);
|
|
106
|
+
|
|
107
|
+
if (!fs.existsSync(absolutePath)) {
|
|
108
|
+
console.error(colorize(`โ Errore: File non trovato: ${filePath}`, 'red'));
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const code = fs.readFileSync(absolutePath, 'utf8');
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const lexer = new Lexer(code);
|
|
116
|
+
const tokens = lexer.tokenize();
|
|
117
|
+
|
|
118
|
+
const parser = new Parser(tokens);
|
|
119
|
+
const ast = parser.parse();
|
|
120
|
+
|
|
121
|
+
console.log(colorize('\n๐ณ AST:\n', 'bright'));
|
|
122
|
+
console.log(JSON.stringify(ast, null, 2));
|
|
123
|
+
console.log();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(colorize(`โ Errore: ${error.message}`, 'red'));
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function run(args) {
|
|
131
|
+
if (args.length === 0) {
|
|
132
|
+
startREPL();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const command = args[0];
|
|
137
|
+
|
|
138
|
+
switch (command) {
|
|
139
|
+
case '--help':
|
|
140
|
+
case '-h':
|
|
141
|
+
case 'help':
|
|
142
|
+
showHelp();
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
case '--version':
|
|
146
|
+
case '-v':
|
|
147
|
+
case 'version':
|
|
148
|
+
showVersion();
|
|
149
|
+
break;
|
|
150
|
+
|
|
151
|
+
case 'repl':
|
|
152
|
+
startREPL();
|
|
153
|
+
break;
|
|
154
|
+
|
|
155
|
+
case 'run':
|
|
156
|
+
if (args.length < 2) {
|
|
157
|
+
console.error(colorize('โ Errore: Specificare un file da eseguire', 'red'));
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
runFile(args[1]);
|
|
161
|
+
break;
|
|
162
|
+
|
|
163
|
+
case 'lex':
|
|
164
|
+
if (args.length < 2) {
|
|
165
|
+
console.error(colorize('โ Errore: Specificare un file da analizzare', 'red'));
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
showTokens(args[1]);
|
|
169
|
+
break;
|
|
170
|
+
|
|
171
|
+
case 'ast':
|
|
172
|
+
if (args.length < 2) {
|
|
173
|
+
console.error(colorize('โ Errore: Specificare un file da analizzare', 'red'));
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
showAST(args[1]);
|
|
177
|
+
break;
|
|
178
|
+
|
|
179
|
+
default:
|
|
180
|
+
// Assume it's a file path
|
|
181
|
+
if (command.endsWith('.vx') || fs.existsSync(command)) {
|
|
182
|
+
runFile(command);
|
|
183
|
+
} else {
|
|
184
|
+
console.error(colorize(`โ Comando sconosciuto: ${command}`, 'red'));
|
|
185
|
+
console.log('Usa "vladx --help" per vedere i comandi disponibili.');
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
module.exports = { run };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VladX - Linguaggio di programmazione con sintassi italiana
|
|
3
|
+
* Export pubblici
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { Lexer, Token } = require('./lexer/lexer.js');
|
|
7
|
+
const { TokenType, KEYWORDS } = require('./lexer/tokens.js');
|
|
8
|
+
const { Parser, ParserError } = require('./parser/parser.js');
|
|
9
|
+
const AST = require('./parser/ast.js');
|
|
10
|
+
const { Interpreter, Environment } = require('./interpreter/interpreter.js');
|
|
11
|
+
const { REPL, startREPL } = require('./repl/repl.js');
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
// Lexer
|
|
15
|
+
Lexer,
|
|
16
|
+
Token,
|
|
17
|
+
TokenType,
|
|
18
|
+
KEYWORDS,
|
|
19
|
+
|
|
20
|
+
// Parser
|
|
21
|
+
Parser,
|
|
22
|
+
ParserError,
|
|
23
|
+
AST,
|
|
24
|
+
|
|
25
|
+
// Interpreter
|
|
26
|
+
Interpreter,
|
|
27
|
+
Environment,
|
|
28
|
+
|
|
29
|
+
// REPL
|
|
30
|
+
REPL,
|
|
31
|
+
startREPL
|
|
32
|
+
};
|