@devalade/algolang 2.0.0 → 2.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/cli.js +34 -24
- package/dist/index.js +69 -48
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2893,6 +2893,7 @@ var KEYWORDS = {
|
|
|
2893
2893
|
documentation: "**reel_en_entier(x)** : Convertit un réel en entier (troncature)."
|
|
2894
2894
|
}
|
|
2895
2895
|
};
|
|
2896
|
+
var BUILTIN_NAMES = new Set(Object.entries(KEYWORDS).filter(([, e]) => e.tokenType === null).map(([label]) => label));
|
|
2896
2897
|
|
|
2897
2898
|
// src/lexer/lexer.ts
|
|
2898
2899
|
class Lexer {
|
|
@@ -3221,22 +3222,12 @@ class SemanticAnalyzer {
|
|
|
3221
3222
|
const algoType = node.value;
|
|
3222
3223
|
const line = node.token?.line ?? 0;
|
|
3223
3224
|
const column = node.token?.column ?? 0;
|
|
3225
|
+
const position = node.token?.position ?? 0;
|
|
3224
3226
|
for (const child of node.children ?? []) {
|
|
3225
3227
|
if (child.type !== "VARIABLE" /* VARIABLE */)
|
|
3226
3228
|
continue;
|
|
3227
3229
|
const name = child.value;
|
|
3228
|
-
if (this.
|
|
3229
|
-
this.errors.push({
|
|
3230
|
-
type: "ERROR",
|
|
3231
|
-
message: `La variable '${name}' est déjà déclarée`,
|
|
3232
|
-
line,
|
|
3233
|
-
column,
|
|
3234
|
-
position: node.token?.position ?? 0,
|
|
3235
|
-
code: "DUPLICATE_VARIABLE",
|
|
3236
|
-
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
3237
|
-
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
3238
|
-
});
|
|
3239
|
-
} else {
|
|
3230
|
+
if (this.validateName(name, line, column, position)) {
|
|
3240
3231
|
this.defineSymbol(name, algoType, line, column);
|
|
3241
3232
|
}
|
|
3242
3233
|
}
|
|
@@ -3248,26 +3239,45 @@ class SemanticAnalyzer {
|
|
|
3248
3239
|
const typeLabel = `TABLEAU[${size}] DE ${elemType}`;
|
|
3249
3240
|
const line = node.token?.line ?? 0;
|
|
3250
3241
|
const column = node.token?.column ?? 0;
|
|
3242
|
+
const position = node.token?.position ?? 0;
|
|
3251
3243
|
for (const child of (node.children ?? []).slice(1)) {
|
|
3252
3244
|
if (child.type !== "VARIABLE" /* VARIABLE */)
|
|
3253
3245
|
continue;
|
|
3254
3246
|
const name = child.value;
|
|
3255
|
-
if (this.
|
|
3256
|
-
this.errors.push({
|
|
3257
|
-
type: "ERROR",
|
|
3258
|
-
message: `La variable '${name}' est déjà déclarée`,
|
|
3259
|
-
line,
|
|
3260
|
-
column,
|
|
3261
|
-
position: node.token?.position ?? 0,
|
|
3262
|
-
code: "DUPLICATE_VARIABLE",
|
|
3263
|
-
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
3264
|
-
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
3265
|
-
});
|
|
3266
|
-
} else {
|
|
3247
|
+
if (this.validateName(name, line, column, position)) {
|
|
3267
3248
|
this.defineSymbol(name, typeLabel, line, column);
|
|
3268
3249
|
}
|
|
3269
3250
|
}
|
|
3270
3251
|
}
|
|
3252
|
+
validateName(name, line, column, position) {
|
|
3253
|
+
if (BUILTIN_NAMES.has(name)) {
|
|
3254
|
+
this.errors.push({
|
|
3255
|
+
type: "ERROR",
|
|
3256
|
+
message: `Le nom '${name}' est une fonction intégrée et ne peut pas être utilisé comme nom de variable`,
|
|
3257
|
+
line,
|
|
3258
|
+
column,
|
|
3259
|
+
position,
|
|
3260
|
+
code: "BUILTIN_SHADOWING",
|
|
3261
|
+
explanation: `'${name}' est une fonction intégrée d'AlgoLang`,
|
|
3262
|
+
suggestion: `Choisissez un autre nom, par exemple '${name}Valeur' ou 'mon${name.charAt(0).toUpperCase()}${name.slice(1)}'`
|
|
3263
|
+
});
|
|
3264
|
+
return false;
|
|
3265
|
+
}
|
|
3266
|
+
if (this.symbolTable.symbols.has(name)) {
|
|
3267
|
+
this.errors.push({
|
|
3268
|
+
type: "ERROR",
|
|
3269
|
+
message: `La variable '${name}' est déjà déclarée`,
|
|
3270
|
+
line,
|
|
3271
|
+
column,
|
|
3272
|
+
position,
|
|
3273
|
+
code: "DUPLICATE_VARIABLE",
|
|
3274
|
+
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
3275
|
+
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
3276
|
+
});
|
|
3277
|
+
return false;
|
|
3278
|
+
}
|
|
3279
|
+
return true;
|
|
3280
|
+
}
|
|
3271
3281
|
defineSymbol(name, type, line, column) {
|
|
3272
3282
|
const info = {
|
|
3273
3283
|
name,
|
package/dist/index.js
CHANGED
|
@@ -262,6 +262,7 @@ var KEYWORDS = {
|
|
|
262
262
|
documentation: "**reel_en_entier(x)** : Convertit un réel en entier (troncature)."
|
|
263
263
|
}
|
|
264
264
|
};
|
|
265
|
+
var BUILTIN_NAMES = new Set(Object.entries(KEYWORDS).filter(([, e]) => e.tokenType === null).map(([label]) => label));
|
|
265
266
|
|
|
266
267
|
// src/lexer/lexer.ts
|
|
267
268
|
class Lexer {
|
|
@@ -589,22 +590,12 @@ class SemanticAnalyzer {
|
|
|
589
590
|
const algoType = node.value;
|
|
590
591
|
const line = node.token?.line ?? 0;
|
|
591
592
|
const column = node.token?.column ?? 0;
|
|
593
|
+
const position = node.token?.position ?? 0;
|
|
592
594
|
for (const child of node.children ?? []) {
|
|
593
595
|
if (child.type !== "VARIABLE" /* VARIABLE */)
|
|
594
596
|
continue;
|
|
595
597
|
const name = child.value;
|
|
596
|
-
if (this.
|
|
597
|
-
this.errors.push({
|
|
598
|
-
type: "ERROR",
|
|
599
|
-
message: `La variable '${name}' est déjà déclarée`,
|
|
600
|
-
line,
|
|
601
|
-
column,
|
|
602
|
-
position: node.token?.position ?? 0,
|
|
603
|
-
code: "DUPLICATE_VARIABLE",
|
|
604
|
-
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
605
|
-
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
606
|
-
});
|
|
607
|
-
} else {
|
|
598
|
+
if (this.validateName(name, line, column, position)) {
|
|
608
599
|
this.defineSymbol(name, algoType, line, column);
|
|
609
600
|
}
|
|
610
601
|
}
|
|
@@ -616,26 +607,45 @@ class SemanticAnalyzer {
|
|
|
616
607
|
const typeLabel = `TABLEAU[${size}] DE ${elemType}`;
|
|
617
608
|
const line = node.token?.line ?? 0;
|
|
618
609
|
const column = node.token?.column ?? 0;
|
|
610
|
+
const position = node.token?.position ?? 0;
|
|
619
611
|
for (const child of (node.children ?? []).slice(1)) {
|
|
620
612
|
if (child.type !== "VARIABLE" /* VARIABLE */)
|
|
621
613
|
continue;
|
|
622
614
|
const name = child.value;
|
|
623
|
-
if (this.
|
|
624
|
-
this.errors.push({
|
|
625
|
-
type: "ERROR",
|
|
626
|
-
message: `La variable '${name}' est déjà déclarée`,
|
|
627
|
-
line,
|
|
628
|
-
column,
|
|
629
|
-
position: node.token?.position ?? 0,
|
|
630
|
-
code: "DUPLICATE_VARIABLE",
|
|
631
|
-
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
632
|
-
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
633
|
-
});
|
|
634
|
-
} else {
|
|
615
|
+
if (this.validateName(name, line, column, position)) {
|
|
635
616
|
this.defineSymbol(name, typeLabel, line, column);
|
|
636
617
|
}
|
|
637
618
|
}
|
|
638
619
|
}
|
|
620
|
+
validateName(name, line, column, position) {
|
|
621
|
+
if (BUILTIN_NAMES.has(name)) {
|
|
622
|
+
this.errors.push({
|
|
623
|
+
type: "ERROR",
|
|
624
|
+
message: `Le nom '${name}' est une fonction intégrée et ne peut pas être utilisé comme nom de variable`,
|
|
625
|
+
line,
|
|
626
|
+
column,
|
|
627
|
+
position,
|
|
628
|
+
code: "BUILTIN_SHADOWING",
|
|
629
|
+
explanation: `'${name}' est une fonction intégrée d'AlgoLang`,
|
|
630
|
+
suggestion: `Choisissez un autre nom, par exemple '${name}Valeur' ou 'mon${name.charAt(0).toUpperCase()}${name.slice(1)}'`
|
|
631
|
+
});
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
if (this.symbolTable.symbols.has(name)) {
|
|
635
|
+
this.errors.push({
|
|
636
|
+
type: "ERROR",
|
|
637
|
+
message: `La variable '${name}' est déjà déclarée`,
|
|
638
|
+
line,
|
|
639
|
+
column,
|
|
640
|
+
position,
|
|
641
|
+
code: "DUPLICATE_VARIABLE",
|
|
642
|
+
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
643
|
+
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
644
|
+
});
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
639
649
|
defineSymbol(name, type, line, column) {
|
|
640
650
|
const info = {
|
|
641
651
|
name,
|
|
@@ -4225,6 +4235,7 @@ var KEYWORDS2 = {
|
|
|
4225
4235
|
documentation: "**reel_en_entier(x)** : Convertit un réel en entier (troncature)."
|
|
4226
4236
|
}
|
|
4227
4237
|
};
|
|
4238
|
+
var BUILTIN_NAMES2 = new Set(Object.entries(KEYWORDS2).filter(([, e]) => e.tokenType === null).map(([label]) => label));
|
|
4228
4239
|
// src/semantic/semantic-analyzer.ts
|
|
4229
4240
|
class SemanticAnalyzer2 {
|
|
4230
4241
|
symbolTable = {
|
|
@@ -4254,22 +4265,12 @@ class SemanticAnalyzer2 {
|
|
|
4254
4265
|
const algoType = node.value;
|
|
4255
4266
|
const line = node.token?.line ?? 0;
|
|
4256
4267
|
const column = node.token?.column ?? 0;
|
|
4268
|
+
const position = node.token?.position ?? 0;
|
|
4257
4269
|
for (const child of node.children ?? []) {
|
|
4258
4270
|
if (child.type !== "VARIABLE" /* VARIABLE */)
|
|
4259
4271
|
continue;
|
|
4260
4272
|
const name = child.value;
|
|
4261
|
-
if (this.
|
|
4262
|
-
this.errors.push({
|
|
4263
|
-
type: "ERROR",
|
|
4264
|
-
message: `La variable '${name}' est déjà déclarée`,
|
|
4265
|
-
line,
|
|
4266
|
-
column,
|
|
4267
|
-
position: node.token?.position ?? 0,
|
|
4268
|
-
code: "DUPLICATE_VARIABLE",
|
|
4269
|
-
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
4270
|
-
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
4271
|
-
});
|
|
4272
|
-
} else {
|
|
4273
|
+
if (this.validateName(name, line, column, position)) {
|
|
4273
4274
|
this.defineSymbol(name, algoType, line, column);
|
|
4274
4275
|
}
|
|
4275
4276
|
}
|
|
@@ -4281,26 +4282,45 @@ class SemanticAnalyzer2 {
|
|
|
4281
4282
|
const typeLabel = `TABLEAU[${size}] DE ${elemType}`;
|
|
4282
4283
|
const line = node.token?.line ?? 0;
|
|
4283
4284
|
const column = node.token?.column ?? 0;
|
|
4285
|
+
const position = node.token?.position ?? 0;
|
|
4284
4286
|
for (const child of (node.children ?? []).slice(1)) {
|
|
4285
4287
|
if (child.type !== "VARIABLE" /* VARIABLE */)
|
|
4286
4288
|
continue;
|
|
4287
4289
|
const name = child.value;
|
|
4288
|
-
if (this.
|
|
4289
|
-
this.errors.push({
|
|
4290
|
-
type: "ERROR",
|
|
4291
|
-
message: `La variable '${name}' est déjà déclarée`,
|
|
4292
|
-
line,
|
|
4293
|
-
column,
|
|
4294
|
-
position: node.token?.position ?? 0,
|
|
4295
|
-
code: "DUPLICATE_VARIABLE",
|
|
4296
|
-
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
4297
|
-
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
4298
|
-
});
|
|
4299
|
-
} else {
|
|
4290
|
+
if (this.validateName(name, line, column, position)) {
|
|
4300
4291
|
this.defineSymbol(name, typeLabel, line, column);
|
|
4301
4292
|
}
|
|
4302
4293
|
}
|
|
4303
4294
|
}
|
|
4295
|
+
validateName(name, line, column, position) {
|
|
4296
|
+
if (BUILTIN_NAMES.has(name)) {
|
|
4297
|
+
this.errors.push({
|
|
4298
|
+
type: "ERROR",
|
|
4299
|
+
message: `Le nom '${name}' est une fonction intégrée et ne peut pas être utilisé comme nom de variable`,
|
|
4300
|
+
line,
|
|
4301
|
+
column,
|
|
4302
|
+
position,
|
|
4303
|
+
code: "BUILTIN_SHADOWING",
|
|
4304
|
+
explanation: `'${name}' est une fonction intégrée d'AlgoLang`,
|
|
4305
|
+
suggestion: `Choisissez un autre nom, par exemple '${name}Valeur' ou 'mon${name.charAt(0).toUpperCase()}${name.slice(1)}'`
|
|
4306
|
+
});
|
|
4307
|
+
return false;
|
|
4308
|
+
}
|
|
4309
|
+
if (this.symbolTable.symbols.has(name)) {
|
|
4310
|
+
this.errors.push({
|
|
4311
|
+
type: "ERROR",
|
|
4312
|
+
message: `La variable '${name}' est déjà déclarée`,
|
|
4313
|
+
line,
|
|
4314
|
+
column,
|
|
4315
|
+
position,
|
|
4316
|
+
code: "DUPLICATE_VARIABLE",
|
|
4317
|
+
explanation: "Chaque variable doit avoir un nom unique dans son scope",
|
|
4318
|
+
suggestion: `Choisissez un autre nom pour la variable '${name}'`
|
|
4319
|
+
});
|
|
4320
|
+
return false;
|
|
4321
|
+
}
|
|
4322
|
+
return true;
|
|
4323
|
+
}
|
|
4304
4324
|
defineSymbol(name, type, line, column) {
|
|
4305
4325
|
const info = {
|
|
4306
4326
|
name,
|
|
@@ -4321,5 +4341,6 @@ export {
|
|
|
4321
4341
|
KEYWORDS2 as KEYWORDS,
|
|
4322
4342
|
DataType2 as DataType,
|
|
4323
4343
|
CodeGenerator,
|
|
4344
|
+
BUILTIN_NAMES2 as BUILTIN_NAMES,
|
|
4324
4345
|
AlgoLangCompiler
|
|
4325
4346
|
};
|