Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

algo-lang

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

algo-lang - npm Package Compare versions

Comparing version 1.1.4 to 1.2.0

test/tri.algo

25

build/algo-lang.js
#!/usr/bin/env node
'use strict';
"use strict";
var _fs = require('fs');
var _fs = _interopRequireDefault(require("fs"));
var _fs2 = _interopRequireDefault(_fs);
var _parser = require("./parser.js");
var _parser = require('./parser.js');
var _visitors = require("./visitors");
var _visitors = require('./visitors');
var _chalk = _interopRequireDefault(require("chalk"));
var _chalk = require('chalk');
var _chalk2 = _interopRequireDefault(_chalk);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const p = new _parser.Parser();
const pretty = process.argv.indexOf('--pretty-print');
if (~pretty) process.argv.splice(0, pretty, 1);
const input = _fs2.default.readFileSync(process.argv[2], 'utf8');
const input = _fs.default.readFileSync(process.argv[2], 'utf8');
function getExerpt(input, location) {
const lines = input.split(/\n/g);
var marker = ' ~~';
var marker = ' ~~';
for (var i = 0; i < location.col - 1; ++i) marker += '~';
return (location.line >= 3 ? ' ' + lines[location.line - 3] + '\n' : '') + (location.line >= 2 ? ' ' + lines[location.line - 2] + '\n' : '') + ' ' + lines[location.line - 1] + '\n' + _chalk2.default.white(marker) + _chalk2.default.green('^') + '\n' + (location.line < lines.length ? ' ' + lines[location.line] + '\n' : '') + (location.line + 1 < lines.length ? ' ' + lines[location.line + 1] + '\n' : '');
return (location.line >= 3 ? ' ' + lines[location.line - 3] + '\n' : '') + (location.line >= 2 ? ' ' + lines[location.line - 2] + '\n' : '') + ' ' + lines[location.line - 1] + '\n' + _chalk.default.white(marker) + _chalk.default.green('^') + '\n' + (location.line < lines.length ? ' ' + lines[location.line] + '\n' : '') + (location.line + 1 < lines.length ? ' ' + lines[location.line + 1] + '\n' : '');
}

@@ -46,3 +40,2 @@

const executor = new _visitors.Executor();
res.accept(typer);

@@ -54,3 +47,3 @@ res.accept(executor);

if (err.location) {
message = _chalk2.default.white(process.argv[2]) + ': ligne ' + _chalk2.default.green(err.location.line) + ' col ' + _chalk2.default.white(err.location.col) + ': ' + message + '\n';
message = _chalk.default.white(process.argv[2]) + ': ligne ' + _chalk.default.green(err.location.line) + ' col ' + _chalk.default.white(err.location.col) + ': ' + message + '\n';
message += getExerpt(input, err.location);

@@ -57,0 +50,0 @@ }

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.AlgoDecls = undefined;
exports.AlgoDecls = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -19,3 +19,5 @@ class AlgoDecls extends _base.Ast {

}
}
exports.AlgoDecls = AlgoDecls;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,35 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Algorithm = undefined;
exports.Algorithm = void 0;
var _base = require('./base.js');
var _base = require("./base.js");
var _routine = require('./routine.js');
var _routine = require("./routine.js");
var _error = require('../jungle/error.js');
var _error = require("../jungle/error.js");
class VariablesScope {
constructor(parent = null) {
this.scope = {};
this.parent = parent;
}
add(name, type) {
return this.scope[name] = {
type: type,
value: type.create()
};
}
alias(name, expr) {
return this.scope[name] = expr;
}
get(name) {
if (name in this.scope) return this.scope[name];
if (this.parent !== null) return this.parent.get(name);
throw new Error('Variable ' + name + ' non trouvée');
}
}
class Algorithm extends _base.Ast {

@@ -25,7 +50,5 @@ constructor(location, name, decls, instructions) {

const params = [];
if (!this.decls.params.reverseOrder && this.decls.params.locals.length) params.push(...this.decls.params.locals);
if (this.decls.params.globals.length) params.push(...this.decls.params.globals);
if (this.decls.params.reverseOrder && this.decls.params.locals.length) params.push(...this.decls.params.locals);
return params;

@@ -44,11 +67,7 @@ }

if (!(this.decls instanceof _routine.Routine)) throw new _error.JungleError('Cannot check parameters on a non routine algorithm…');
const paramsDecls = this.getParamDeclsInOrder();
const nbArgs = paramsDecls.reduce((acc, v) => acc + v.names.length, 0);
if (nbArgs !== args.length) throw new _error.JungleError('la routine ' + this.name + ' prend ' + nbArgs + ' paramètres mais ' + args.length + ' paramètres ont été fournis');
this.getOverVariables(paramsDecls, (variables, name, index) => {
if (!variables.type.isCompatibleWith(args[index].resType)) throw new _error.JungleError('L\'argument ' + (index + 1) + ' de la routine routine ' + this.name + ' attend un ' + variables.type.name + ' mais un ' + args[index].resType.name + ' a été fourni à la place', args[index].location);
if (variables.assignable && !args[index].writable) throw new _error.JungleError('L\'argument ' + (index + 1) + ' de la routine ' + this.name + ' attend une expression ' + 'assignable pour un paramètre global', args[index].location);

@@ -59,6 +78,13 @@ });

execute(executor, params) {
this.variablesScope = new VariablesScope(this.decls.searchScopeIn ? this.decls.searchScopeIn.variablesScope : null);
executor.scopes.push(this.variablesScope);
if (this.decls instanceof _routine.Routine) {
this.getOverVariables(this.getParamDeclsInOrder(), (variables, name, index) => {
if (variables.assignable) return executor.variables.alias(name, params[index]);
executor.variables.add(name, variables.type).value = variables.type.create(params[index].value);
if (variables.assignable) {
executor.variables.alias(name, params[index]);
return;
}
this.variablesScope.add(name, variables.type).value = variables.type.create(params[index].value);
});

@@ -69,7 +95,6 @@ }

executor.array(this.instructions);
if (this.type && this.type.name !== '<no value>' && !this.returnValue) throw new _error.JungleError('retourne n\'a pas été appelé durant l\'exécution de la routine ' + this.name);
const res = this.returnValue;
this.returnValue = null;
executor.scopes.pop();
return res;

@@ -81,5 +106,7 @@ }

type: this.type,
get value() {
return value;
}
};

@@ -91,3 +118,5 @@ }

}
}
exports.Algorithm = Algorithm;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.ArrayAccess = undefined;
exports.ArrayAccess = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,3 +17,5 @@ class ArrayAccess extends _base.Ast {

}
}
exports.ArrayAccess = ArrayAccess;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Array = undefined;
exports.Array = void 0;
var _type = require('./type.js');
var _type = require("./type.js");

@@ -24,7 +24,6 @@ class Array extends _type.Type {

if (!dimensions.length) return this.type.create(...rest);
const dimension = dimensions[0];
dimensions = dimensions.slice(1);
const res = [];
const res = [];
for (let i = 0; i < dimension; ++i) res.push(rest.length ? this.createDimensions(dimensions, rest[0][i]) : this.createDimensions(dimensions));

@@ -34,3 +33,5 @@

}
}
exports.Array = Array;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Ast = undefined;
exports.Ast = void 0;
var _error = require('../jungle/error.js');
var _error = require("../jungle/error.js");

@@ -23,2 +23,3 @@ class Ast {

if (!('visit' + this.constructor.name in visitor)) throw new Error('Your visitor must implement visit' + this.constructor.name + '(ast)');
try {

@@ -31,3 +32,5 @@ return visitor['visit' + this.constructor.name](this);

}
}
exports.Ast = Ast;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Binary = undefined;
exports.Binary = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -18,3 +18,5 @@ class Binary extends _base.Ast {

}
}
exports.Binary = Binary;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Const = undefined;
exports.Const = void 0;
var _type = require('./type.js');
var _type = require("./type.js");

@@ -16,3 +16,5 @@ class Const extends _type.Type {

}
}
exports.Const = Const;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Enum = undefined;
exports.Enum = void 0;
var _type = require('./type.js');
var _type = require("./type.js");
var _ast = require('../ast');
var _ast = require("../ast");

@@ -23,3 +23,5 @@ class Enum extends _type.Type {

}
}
exports.Enum = Enum;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Function = undefined;
exports.Function = void 0;
var _algorithm = require('./algorithm.js');
var _algorithm = require("./algorithm.js");

@@ -16,3 +16,5 @@ class Function extends _algorithm.Algorithm {

}
}
exports.Function = Function;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.IdentifierRef = undefined;
exports.IdentifierRef = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -16,3 +16,5 @@ class IdentifierRef extends _base.Ast {

}
}
exports.IdentifierRef = IdentifierRef;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,6 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
var _base = require('./base.js');
Object.defineProperty(exports, 'Ast', {
Object.defineProperty(exports, "Ast", {
enumerable: true,

@@ -16,6 +13,3 @@ get: function () {

});
var _algo_decls = require('./algo_decls.js');
Object.defineProperty(exports, 'AlgoDecls', {
Object.defineProperty(exports, "AlgoDecls", {
enumerable: true,

@@ -26,6 +20,3 @@ get: function () {

});
var _algorithm = require('./algorithm.js');
Object.defineProperty(exports, 'Algorithm', {
Object.defineProperty(exports, "Algorithm", {
enumerable: true,

@@ -36,6 +27,3 @@ get: function () {

});
var _array = require('./array.js');
Object.defineProperty(exports, 'Array', {
Object.defineProperty(exports, "Array", {
enumerable: true,

@@ -46,6 +34,3 @@ get: function () {

});
var _array_access = require('./array_access.js');
Object.defineProperty(exports, 'ArrayAccess', {
Object.defineProperty(exports, "ArrayAccess", {
enumerable: true,

@@ -56,6 +41,3 @@ get: function () {

});
var _binary = require('./binary.js');
Object.defineProperty(exports, 'Binary', {
Object.defineProperty(exports, "Binary", {
enumerable: true,

@@ -66,6 +48,3 @@ get: function () {

});
var _const = require('./const.js');
Object.defineProperty(exports, 'Const', {
Object.defineProperty(exports, "Const", {
enumerable: true,

@@ -76,6 +55,3 @@ get: function () {

});
var _enum = require('./enum.js');
Object.defineProperty(exports, 'Enum', {
Object.defineProperty(exports, "Enum", {
enumerable: true,

@@ -86,6 +62,3 @@ get: function () {

});
var _function = require('./function.js');
Object.defineProperty(exports, 'Function', {
Object.defineProperty(exports, "Function", {
enumerable: true,

@@ -96,6 +69,3 @@ get: function () {

});
var _identifier_ref = require('./identifier_ref.js');
Object.defineProperty(exports, 'IdentifierRef', {
Object.defineProperty(exports, "IdentifierRef", {
enumerable: true,

@@ -106,6 +76,3 @@ get: function () {

});
var _parameters = require('./parameters.js');
Object.defineProperty(exports, 'Parameters', {
Object.defineProperty(exports, "Parameters", {
enumerable: true,

@@ -116,6 +83,3 @@ get: function () {

});
var _pointer = require('./pointer.js');
Object.defineProperty(exports, 'Pointer', {
Object.defineProperty(exports, "Pointer", {
enumerable: true,

@@ -126,6 +90,3 @@ get: function () {

});
var _pointer_access = require('./pointer_access.js');
Object.defineProperty(exports, 'PointerAccess', {
Object.defineProperty(exports, "PointerAccess", {
enumerable: true,

@@ -136,6 +97,3 @@ get: function () {

});
var _pour = require('./pour.js');
Object.defineProperty(exports, 'Pour', {
Object.defineProperty(exports, "Pour", {
enumerable: true,

@@ -146,6 +104,3 @@ get: function () {

});
var _procedure = require('./procedure.js');
Object.defineProperty(exports, 'Procedure', {
Object.defineProperty(exports, "Procedure", {
enumerable: true,

@@ -156,6 +111,3 @@ get: function () {

});
var _record = require('./record.js');
Object.defineProperty(exports, 'Record', {
Object.defineProperty(exports, "Record", {
enumerable: true,

@@ -166,6 +118,3 @@ get: function () {

});
var _record_access = require('./record_access.js');
Object.defineProperty(exports, 'RecordAccess', {
Object.defineProperty(exports, "RecordAccess", {
enumerable: true,

@@ -176,6 +125,3 @@ get: function () {

});
var _routine = require('./routine.js');
Object.defineProperty(exports, 'Routine', {
Object.defineProperty(exports, "Routine", {
enumerable: true,

@@ -186,6 +132,3 @@ get: function () {

});
var _routine_call = require('./routine_call.js');
Object.defineProperty(exports, 'RoutineCall', {
Object.defineProperty(exports, "RoutineCall", {
enumerable: true,

@@ -196,6 +139,3 @@ get: function () {

});
var _scalar = require('./scalar.js');
Object.defineProperty(exports, 'Scalar', {
Object.defineProperty(exports, "Scalar", {
enumerable: true,

@@ -206,6 +146,3 @@ get: function () {

});
var _selon = require('./selon.js');
Object.defineProperty(exports, 'Selon', {
Object.defineProperty(exports, "Selon", {
enumerable: true,

@@ -216,6 +153,3 @@ get: function () {

});
var _selon_expression = require('./selon_expression.js');
Object.defineProperty(exports, 'SelonExpression', {
Object.defineProperty(exports, "SelonExpression", {
enumerable: true,

@@ -226,6 +160,3 @@ get: function () {

});
var _si = require('./si.js');
Object.defineProperty(exports, 'Si', {
Object.defineProperty(exports, "Si", {
enumerable: true,

@@ -236,6 +167,3 @@ get: function () {

});
var _tant_que = require('./tant_que.js');
Object.defineProperty(exports, 'TantQue', {
Object.defineProperty(exports, "TantQue", {
enumerable: true,

@@ -246,6 +174,3 @@ get: function () {

});
var _type = require('./type.js');
Object.defineProperty(exports, 'Type', {
Object.defineProperty(exports, "Type", {
enumerable: true,

@@ -256,6 +181,3 @@ get: function () {

});
var _unary = require('./unary.js');
Object.defineProperty(exports, 'Unary', {
Object.defineProperty(exports, "Unary", {
enumerable: true,

@@ -266,6 +188,3 @@ get: function () {

});
var _value = require('./value.js');
Object.defineProperty(exports, 'Value', {
Object.defineProperty(exports, "Value", {
enumerable: true,

@@ -276,6 +195,3 @@ get: function () {

});
var _variables = require('./variables.js');
Object.defineProperty(exports, 'Variables', {
Object.defineProperty(exports, "Variables", {
enumerable: true,

@@ -285,2 +201,58 @@ get: function () {

}
});
});
var _base = require("./base.js");
var _algo_decls = require("./algo_decls.js");
var _algorithm = require("./algorithm.js");
var _array = require("./array.js");
var _array_access = require("./array_access.js");
var _binary = require("./binary.js");
var _const = require("./const.js");
var _enum = require("./enum.js");
var _function = require("./function.js");
var _identifier_ref = require("./identifier_ref.js");
var _parameters = require("./parameters.js");
var _pointer = require("./pointer.js");
var _pointer_access = require("./pointer_access.js");
var _pour = require("./pour.js");
var _procedure = require("./procedure.js");
var _record = require("./record.js");
var _record_access = require("./record_access.js");
var _routine = require("./routine.js");
var _routine_call = require("./routine_call.js");
var _scalar = require("./scalar.js");
var _selon = require("./selon.js");
var _selon_expression = require("./selon_expression.js");
var _si = require("./si.js");
var _tant_que = require("./tant_que.js");
var _type = require("./type.js");
var _unary = require("./unary.js");
var _value = require("./value.js");
var _variables = require("./variables.js");

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Parameters = undefined;
exports.Parameters = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,6 +17,7 @@ class Parameters extends _base.Ast {

this.reverseOrder = !!reverseOrder;
this.globals.forEach(variables => variables.assignable = true);
}
}
exports.Parameters = Parameters;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.PointerAccess = undefined;
exports.PointerAccess = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -16,3 +16,5 @@ class PointerAccess extends _base.Ast {

}
}
exports.PointerAccess = PointerAccess;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Pointer = undefined;
exports.Pointer = void 0;
var _type = require('./type.js');
var _type = require("./type.js");

@@ -24,3 +24,5 @@ class Pointer extends _type.Type {

}
}
exports.Pointer = Pointer;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Pour = undefined;
exports.Pour = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -20,3 +20,5 @@ class Pour extends _base.Ast {

}
}
exports.Pour = Pour;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Procedure = undefined;
exports.Procedure = void 0;
var _algorithm = require('./algorithm.js');
var _algorithm = require("./algorithm.js");

@@ -15,3 +15,5 @@ class Procedure extends _algorithm.Algorithm {

}
}
exports.Procedure = Procedure;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.RecordAccess = undefined;
exports.RecordAccess = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,3 +17,5 @@ class RecordAccess extends _base.Ast {

}
}
exports.RecordAccess = RecordAccess;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Record = undefined;
exports.Record = void 0;
var _type = require('./type.js');
var _type = require("./type.js");

@@ -19,3 +19,2 @@ class Record extends _type.Type {

if (record) return this.copy(record);
return this.properties.reduce((acc, variables) => {

@@ -29,6 +28,10 @@ variables.names.forEach(name => acc[name] = variables.type.create());

const res = {};
for (let val in record) res[val] = this.properties.find(prop => prop.names.indexOf(val) >= 0).type.create(record[val]);
return res;
}
}
exports.Record = Record;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.RoutineCall = undefined;
exports.RoutineCall = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,3 +17,5 @@ class RoutineCall extends _base.Ast {

}
}
exports.RoutineCall = RoutineCall;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Routine = undefined;
exports.Routine = void 0;
var _base = require('./base.js');
var _base = require("./base.js");
class Routine extends _base.Ast {
constructor(params, consts, types, variables) {
constructor(params, consts, types, variables, routines) {
super();

@@ -18,4 +18,7 @@ this.params = params;

this.variables = variables;
this.routines = routines;
}
}
exports.Routine = Routine;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Scalar = undefined;
exports.Scalar = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -16,3 +16,5 @@ class Scalar extends _base.Ast {

}
}
exports.Scalar = Scalar;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.SelonExpression = undefined;
exports.SelonExpression = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,3 +17,5 @@ class SelonExpression extends _base.Ast {

}
}
exports.SelonExpression = SelonExpression;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Selon = undefined;
exports.Selon = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -18,3 +18,5 @@ class Selon extends _base.Ast {

}
}
exports.Selon = Selon;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Si = undefined;
exports.Si = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -18,3 +18,5 @@ class Si extends _base.Ast {

}
}
exports.Si = Si;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.TantQue = undefined;
exports.TantQue = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -18,3 +18,5 @@ class TantQue extends _base.Ast {

}
}
exports.TantQue = TantQue;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Type = undefined;
exports.Type = void 0;
var _base = require('./base.js');
var _base = require("./base.js");
var _error = require('../jungle/error.js');
var _error = require("../jungle/error.js");

@@ -21,5 +21,3 @@ class Type extends _base.Ast {

if (this.name && this.name !== name) throw new _error.JungleError('Impossible de créer un type avec deux noms : ' + name + ' / ' + this.name, this.location);
this.name = name;
return this;

@@ -39,3 +37,5 @@ }

}
}
exports.Type = Type;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Unary = undefined;
exports.Unary = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,3 +17,5 @@ class Unary extends _base.Ast {

}
}
exports.Unary = Unary;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Value = undefined;
exports.Value = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,3 +17,5 @@ class Value extends _base.Ast {

}
}
exports.Value = Value;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Variables = undefined;
exports.Variables = void 0;
var _base = require('./base.js');
var _base = require("./base.js");

@@ -17,3 +17,5 @@ class Variables extends _base.Ast {

}
}
exports.Variables = Variables;

@@ -6,2 +6,4 @@ "use strict";

});
exports.JungleError = void 0;
class JungleError extends Error {

@@ -14,3 +16,5 @@ constructor(message, location) {

}
}
exports.JungleError = JungleError;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Lexer = undefined;
exports.Lexer = void 0;
var _symbol = require('./symbol.js');
var _symbol = require("./symbol.js");

@@ -16,3 +16,5 @@ const $private = Symbol('private');

constructor(fn) {
this[$private] = { fn: fn };
this[$private] = {
fn: fn
};
}

@@ -34,2 +36,3 @@

}
}

@@ -46,3 +49,2 @@

res.index = str.indexOf(this[$private].str);
return res.index < 0 ? null : res;

@@ -54,2 +56,3 @@ }

}
}

@@ -70,2 +73,3 @@

}
}

@@ -76,3 +80,5 @@

this[$private] = {
rules: { default: [] }
rules: {
default: []
}
};

@@ -83,6 +89,11 @@ this.reset(input);

reset(input) {
this[$private].token = { sy: new _symbol.LngSymbol() };
this[$private].token = {
sy: new _symbol.LngSymbol()
};
this[$private].input = input;
this[$private].currentLine = this[$private].input.substr(0, this[$private].input.indexOf('\n'));
this[$private].pos = { line: 1, col: 1 };
this[$private].pos = {
line: 1,
col: 1
};
this[$private].scopes = [this[$private].rules.default];

@@ -93,3 +104,2 @@ }

if (this[$private].token.sy.type === _symbol.LngSymbol.epsilon) this.eat();
return this[$private].token;

@@ -111,3 +121,2 @@ }

if (!(scopeName in this[$private].rules)) throw new Error('Trying to push an invalid scope `' + scopeName + "'");
this[$private].scopes.push(this[$private].rules[scopeName]);

@@ -122,6 +131,7 @@ }

$eat(reset) {
if (reset) this[$private].token = { val: noValue, sy: new _symbol.LngSymbol(_symbol.LngSymbol.epsilon) };
if (reset) this[$private].token = {
val: noValue,
sy: new _symbol.LngSymbol(_symbol.LngSymbol.epsilon)
};
const scope = this[$private].scopes[this[$private].scopes.length - 1];
let bestSize = 0;

@@ -138,3 +148,7 @@ let bestRule = null;

this[$private].token.sy = new _symbol.LngSymbol(_symbol.LngSymbol.token, 'EOF');
this[$private].token.location = { line: this[$private].pos.line, col: this[$private].pos.col, length: 0 };
this[$private].token.location = {
line: this[$private].pos.line,
col: this[$private].pos.col,
length: 0
};
return;

@@ -150,8 +164,9 @@ }

this.hasMoved = false;
this[$private].token.location = { line: this[$private].pos.line, col: this[$private].pos.col, length: bestSize };
this[$private].token.location = {
line: this[$private].pos.line,
col: this[$private].pos.col,
length: bestSize
};
const res = bestRule.execute(this, this[$private].token);
if (!this.hasMoved) this.move(bestSize);
if (!res) this.$eat(false);

@@ -164,4 +179,4 @@ }

this[$private].input = this[$private].input.substr(size);
const lines = str.split('\n');
const lines = str.split('\n');
if (lines.length < 2) {

@@ -184,8 +199,11 @@ this[$private].pos.col += str.length;

}
}
/*
const descr = Object.getOwnPropertyDescriptor(Lexer.prototype, '$eat')
descr.enumerable = false
Object.defineProperty(Lexer.prototype, '$eat', descr)
//*/
exports.Lexer = Lexer; /*
const descr = Object.getOwnPropertyDescriptor(Lexer.prototype, '$eat')
descr.enumerable = false
Object.defineProperty(Lexer.prototype, '$eat', descr)
//*/
exports.Lexer = Lexer;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Parser = undefined;
exports.Parser = void 0;
var _symbol = require('./symbol.js');
var _symbol = require("./symbol.js");
var _lexer = require('./lexer.js');
var _lexer = require("./lexer.js");
var _error = require('./error.js');
var _error = require("./error.js");

@@ -19,3 +19,5 @@ const $private = Symbol('private');

constructor(states) {
this[$private] = { states: states };
this[$private] = {
states: states
};
}

@@ -32,2 +34,3 @@

}
}

@@ -37,3 +40,5 @@

constructor(rules) {
this[$private] = { rules: rules };
this[$private] = {
rules: rules
};
}

@@ -43,7 +48,6 @@

var res = this[$private].rules[token.sy.name];
if (!res) throw new _error.JungleError('Symbol (' + _symbol.LngSymbol.formatedName(token.sy.name) + ') is invalid. Possibles symbols are: ' + Object.keys(this[$private].rules).map(_symbol.LngSymbol.formatedName).join(', '), token.location);
return res.action;
}
}

@@ -53,3 +57,6 @@

constructor(symbol, action) {
this[$private] = { symbol: symbol, action: action };
this[$private] = {
symbol: symbol,
action: action
};
}

@@ -68,2 +75,3 @@

}
}

@@ -73,3 +81,5 @@

constructor(val) {
this[$private] = { val: val };
this[$private] = {
val: val
};
}

@@ -80,2 +90,3 @@

}
}

@@ -90,2 +101,3 @@

});
case 'r':

@@ -99,2 +111,3 @@ const matches = actionDescr.match(/^r\((.*?)\[(.*?)\],(.*?)\)$/);

});
case 'a':

@@ -104,2 +117,3 @@ return new Action(symbol, {

});
case 'g':

@@ -110,2 +124,3 @@ return new Action(symbol, {

});
default:

@@ -123,5 +138,7 @@ throw new Error('Unknown rule: ' + actionDescr);

}, {}) || {}).map(state => new State(state)));
this[$private] = {
tables: new ParsingTables({ actions: actions, gotos: gotos }),
tables: new ParsingTables({
actions: actions,
gotos: gotos
}),
fns: {},

@@ -136,3 +153,2 @@ tokenStack: [],

const tokenStack = this[$private].tokenStack;
throw new Result(tokenStack[tokenStack.length - 1].val);

@@ -150,7 +166,10 @@ }

const tokenStack = this[$private].tokenStack;
let vals = [];
let vals = [];
for (let i = 0; i < action.pop; ++i) {
const token = tokenStack[tokenStack.length - 1];
vals.unshift({ location: token.location, value: token.val });
vals.unshift({
location: token.location,
value: token.val
});
tokenStack.pop();

@@ -164,5 +183,3 @@ stateStack.pop();

};
tokenStack.push(token);
this.visit(lexer, this[$private].tables.getGoto(stateStack[stateStack.length - 1], tokenStack[tokenStack.length - 1]));

@@ -173,3 +190,2 @@ }

const stateStack = this[$private].stateStack;
stateStack.push(action.to);

@@ -189,3 +205,2 @@ }

if (!(err instanceof Result)) throw err;
return err.val;

@@ -215,6 +230,4 @@ }

const tokenStack = this[$private].tokenStack;
const stateLength = stateStack.length;
const tokenLength = tokenStack.length;
stateStack.push(0);

@@ -235,9 +248,9 @@

if (this[$private].checkOnly) return null;
if (!(rule in this[$private].fns)) throw new Error('No reduction function found for rule "' + rule + '"');
if (this[$private].fns[rule].length <= choice) throw new Error('No reduction function found for rule "' + rule + '[' + choice + ']"');
return this[$private].fns[rule][choice].apply(this, values);
}
}
exports.Parser = Parser;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,8 +6,12 @@ Object.defineProperty(exports, "__esModule", {

});
exports.LngSymbol = void 0;
const $private = Symbol('private');
const token = Symbol('token');
const rule = Symbol('rule');
const epsilon = Symbol('epsilon');
const types = { [token]: token, [rule]: rule, [epsilon]: epsilon };
const types = {
[token]: token,
[rule]: rule,
[epsilon]: epsilon
};

@@ -17,3 +21,2 @@ class LngSymbol {

this[$private] = {};
this.type = type;

@@ -26,2 +29,3 @@ this.name = name;

}
set type(type) {

@@ -40,4 +44,6 @@ if (!(type in types)) throw new Error('Unknown type provided');

return 'token(' + this.formatedName() + ')';
case LngSymbol.rule:
return 'rule(' + this.formatedName() + ')';
case LngSymbol.epsilon:

@@ -51,5 +57,7 @@ return 'epsilon';

}
}
exports.LngSymbol = LngSymbol;
LngSymbol.formatedName = function (name) {

@@ -56,0 +64,0 @@ return name.replace('\n', '\\n').replace('\t', '\\t');

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,20 +6,17 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Lexer = undefined;
exports.Lexer = void 0;
var _ast = require('./ast');
var ast = _interopRequireWildcard(require("./ast"));
var ast = _interopRequireWildcard(_ast);
var _lexer = require("./jungle/lexer.js");
var _lexer = require('./jungle/lexer.js');
var _symbol = require("./jungle/symbol.js");
var _symbol = require('./jungle/symbol.js');
var _error = require("./jungle/error.js");
var _error = require('./jungle/error.js');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Lexer extends _lexer.Lexer {
constructor(str) {
super(str);
this.registerRule('algorithme', this.lex_1, 'default');

@@ -101,552 +98,502 @@ this.registerRule('fonction', this.lex_2, 'default');

__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'algorithme';
return true;
}
lex_2(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'fonction';
return true;
}
lex_3(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'procedure';
return true;
}
lex_4(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'parametres locaux';
return true;
}
lex_5(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'parametres globaux';
return true;
}
lex_6(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'constantes';
return true;
}
lex_7(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'variables';
return true;
}
lex_8(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'types';
return true;
}
lex_9(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'enregistrement';
return true;
}
lex_10(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'debut';
return true;
}
lex_11(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'fin';
return true;
}
lex_12(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'si';
return true;
}
lex_13(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'alors';
return true;
}
lex_14(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'sinon';
return true;
}
lex_15(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'pour';
return true;
}
lex_16(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'jusqu\'a';
return true;
}
lex_17(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'decroissant';
return true;
}
lex_18(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'faire';
return true;
}
lex_19(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'tant que';
return true;
}
lex_20(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'selon';
return true;
}
lex_21(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'cas';
return true;
}
lex_22(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'autrement';
return true;
}
lex_23(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'nul';
return true;
}
lex_24(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
this.pushScope('dbstring');
__token__.val = '';
return false;
}
this.pushScope('dbstring');__token__.val = '';return false;
}
lex_25(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.val = +__match__[0];
__token__.sy.name = 'entier';
return true;
}
__token__.val = +__match__[0];__token__.sy.name = 'entier';return true;
}
lex_26(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.val = +__match__[0];
__token__.sy.name = 'reel';
return true;
}
__token__.val = +__match__[0];__token__.sy.name = 'reel';return true;
}
lex_27(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.val = __match__[1];
__token__.sy.name = 'caractere';
return true;
}
lex_28(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.val = '\n';
__token__.sy.name = 'caractere';
return true;
}
__token__.val = '\n';__token__.sy.name = 'caractere';return true;
}
lex_29(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '←';
return true;
}
lex_30(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '←';
return true;
}
lex_31(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '↑';
return true;
}
lex_32(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '↑';
return true;
}
lex_33(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '.';
return true;
}
lex_34(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '[';
return true;
}
lex_35(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = ']';
return true;
}
lex_36(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '=';
return true;
}
lex_37(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '<>';
return true;
}
lex_38(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '<';
return true;
}
lex_39(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '<=';
return true;
}
lex_40(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '>=';
return true;
}
lex_41(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '>';
return true;
}
lex_42(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'non';
return true;
}
lex_43(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'et';
return true;
}
lex_44(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'ou';
return true;
}
lex_45(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'oue';
return true;
}
lex_46(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '+';
return true;
}
lex_47(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '-';
return true;
}
lex_48(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '*';
return true;
}
lex_49(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '/';
return true;
}
lex_50(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'div';
return true;
}
lex_51(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'mod';
return true;
}
lex_52(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = ',';
return true;
}
lex_53(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = ':';
return true;
}
lex_54(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '(';
return true;
}
lex_55(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = ')';
return true;
}
lex_56(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '/*';
this.pushScope('comment');
return false;
}
lex_57(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'identifieur';
__token__.val = __match__[0].toLowerCase();
return true;
}
__token__.sy.name = 'identifieur';__token__.val = __match__[0].toLowerCase();return true;
}
lex_58(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '\\\n';
return false;
}
lex_59(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '\n';
this.pushScope('linefeed');
return false;
}
lex_60(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
return false;
}
lex_61(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
throw new _error.JungleError('Caractère $0 invalide'.replace("$0", __match__[0]), __token__.location);
return false;
}
lex_62(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '/*';
this.pushScope('comment');
return false;
}
lex_63(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '*/';
this.popScope();
return false;
}
lex_64(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
return false;
}
lex_65(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.val += '\n';
return false;
}
__token__.val += '\n';return false;
}
lex_66(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.val += __match__[1];
return false;
}
__token__.val += __match__[1];return false;
}
lex_67(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = 'chaine';
this.popScope();
return true;
}
__token__.sy.name = 'chaine';this.popScope();return true;
}
lex_68(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.val += __match__[0];
return false;
}
__token__.val += __match__[0];return false;
}
lex_69(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
return false;
}
lex_70(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '/*';
this.pushScope('comment');
return false;
}
lex_71(__match__, __token__) {
const __str__ = __match__[0];
__token__.sy.type = _symbol.LngSymbol.token;
__token__.sy.name = '\n';
this.popScope();

@@ -656,3 +603,5 @@ this.move(0);

}
}
exports.Lexer = Lexer;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,26 +6,21 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Parser = undefined;
exports.Parser = void 0;
var _ast = require('./ast');
var ast = _interopRequireWildcard(require("./ast"));
var ast = _interopRequireWildcard(_ast);
var _fs = _interopRequireDefault(require("fs"));
var _fs = require('fs');
var _lexer = require("./lexer.js");
var _fs2 = _interopRequireDefault(_fs);
var _parser = require("./jungle/parser.js");
var _lexer = require('./lexer.js');
var _error = require("./jungle/error.js");
var _parser = require('./jungle/parser.js');
var _error = require('./jungle/error.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
class Parser extends _parser.Parser {
constructor() {
super(_fs2.default.readFileSync(__dirname + '/../lib/parsing_tables.pt', 'utf8'), _lexer.Lexer);
super(_fs.default.readFileSync(__dirname + '/../lib/parsing_tables.pt', 'utf8'), _lexer.Lexer);
this.registerCode("algo", 0, this.algo0);

@@ -141,110 +136,167 @@ this.registerCode("algo_decls", 0, this.algo_decls0);

}
algo_decls0(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return new ast.AlgoDecls(__arg_1__.value, __arg_2__.value, __arg_3__.value, __arg_4__.value);
}
const_decls0(__arg_1__, __arg_2__, __arg_3__) {
return __arg_3__.value;
}
const_decls1() {
return [];
}
const_decls_list0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__) {
__arg_1__.value.push(new ast.Const(__arg_2__.location, __arg_2__.value, __arg_4__.value));return __arg_1__.value;
__arg_1__.value.push(new ast.Const(__arg_2__.location, __arg_2__.value, __arg_4__.value));
return __arg_1__.value;
}
const_decls_list1(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return [new ast.Const(__arg_1__.location, __arg_1__.value, __arg_3__.value)];
}
types_decls0(__arg_1__, __arg_2__, __arg_3__) {
return __arg_3__.value;
}
types_decls1() {
return [];
}
types_decls_list0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__) {
__arg_1__.value.push(__arg_4__.value.setLocation(__arg_2__.location).setName(__arg_2__.value));return __arg_1__.value;
__arg_1__.value.push(__arg_4__.value.setLocation(__arg_2__.location).setName(__arg_2__.value));
return __arg_1__.value;
}
types_decls_list1(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return [__arg_3__.value.setLocation(__arg_1__.location).setName(__arg_1__.value)];
}
variables_decls0(__arg_1__, __arg_2__, __arg_3__) {
return __arg_3__.value;
}
variables_decls1() {
return [];
}
variable_decls_list0(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
__arg_1__.value.push(new ast.Variables(__arg_2__.location, __arg_2__.value, __arg_3__.value));return __arg_1__.value;
__arg_1__.value.push(new ast.Variables(__arg_2__.location, __arg_2__.value, __arg_3__.value));
return __arg_1__.value;
}
variable_decls_list1(__arg_1__, __arg_2__, __arg_3__) {
return [new ast.Variables(__arg_1__.location, __arg_1__.value, __arg_2__.value)];
}
identifieur_list0(__arg_1__, __arg_2__, __arg_3__) {
__arg_1__.value.push(__arg_3__.value);return __arg_1__.value;
__arg_1__.value.push(__arg_3__.value);
return __arg_1__.value;
}
identifieur_list1(__arg_1__) {
return [__arg_1__.value];
}
type_def0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__) {
__arg_4__.value.unshift(__arg_2__.value);return new ast.Enum(__arg_4__.value);
__arg_4__.value.unshift(__arg_2__.value);
return new ast.Enum(__arg_4__.value);
}
type_def1(__arg_1__, __arg_2__) {
return new ast.Array(__arg_2__.value, __arg_1__.value);
}
type_def2(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__, __arg_6__) {
return new ast.Record(__arg_6__.value, __arg_3__.value);
}
type_def3(__arg_1__, __arg_2__) {
return new ast.Pointer(__arg_2__.value);
}
array_dimension_list0(__arg_1__, __arg_2__, __arg_3__) {
if (__arg_2__.value !== 'x') throw new _error.JungleError('Invalid identifieur, expecting x', __arg_2__.location);__arg_1__.value.push(__arg_3__.value);return __arg_1__.value;
if (__arg_2__.value !== 'x') throw new _error.JungleError('Invalid identifieur, expecting x', __arg_2__.location);
__arg_1__.value.push(__arg_3__.value);
return __arg_1__.value;
}
array_dimension_list1(__arg_1__, __arg_2__, __arg_3__) {
if (__arg_2__.value !== 'x') throw new _error.JungleError('Invalid identifieur, expecting x', __arg_2__.location);__arg_1__.value.push(__arg_3__.value);return __arg_1__.value;
if (__arg_2__.value !== 'x') throw new _error.JungleError('Invalid identifieur, expecting x', __arg_2__.location);
__arg_1__.value.push(__arg_3__.value);
return __arg_1__.value;
}
array_dimension_list2(__arg_1__) {
return [Number(__arg_1__.value)];
}
array_dimension_list3(__arg_1__) {
return [__arg_1__.value];
}
value0(__arg_1__) {
return new ast.Value(__arg_1__.location, 'entier', __arg_1__.value);
}
value1(__arg_1__, __arg_2__) {
return new ast.Value(__arg_1__.location, 'entier', __arg_2__.value);
}
value2(__arg_1__, __arg_2__) {
return new ast.Value(__arg_1__.location, 'entier', -__arg_2__.value);
}
value3(__arg_1__) {
return new ast.Value(__arg_1__.location, 'reel', __arg_1__.value);
}
value4(__arg_1__, __arg_2__) {
return new ast.Value(__arg_1__.location, 'reel', __arg_2__.value);
}
value5(__arg_1__, __arg_2__) {
return new ast.Value(__arg_1__.location, 'reel', -__arg_2__.value);
}
value6(__arg_1__) {
return new ast.Value(__arg_1__.location, 'chaine', __arg_1__.value);
}
value7(__arg_1__) {
return new ast.Value(__arg_1__.location, 'caractere', __arg_1__.value);
}
value8(__arg_1__) {
return new ast.Value(__arg_1__.location, '!nul');
}
routines_decls0(__arg_1__) {
return __arg_1__.value;
}
routines_decls1() {
return [];
}
routines_decls_no_empty0(__arg_1__, __arg_2__, __arg_3__) {
__arg_1__.value.push(__arg_2__.value);return __arg_1__.value;
__arg_1__.value.push(__arg_2__.value);
return __arg_1__.value;
}
routines_decls_no_empty1(__arg_1__, __arg_2__) {
return [__arg_1__.value];
}
routine_decl0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__, __arg_6__, __arg_7__, __arg_8__, __arg_9__, __arg_10__, __arg_11__, __arg_12__) {

@@ -254,2 +306,3 @@ if (__arg_3__.value != __arg_12__.value) throw new _error.JungleError('Erreur de correspondance de nom pour la procédure : ' + __arg_3__.value + ' / ' + __arg_12__.value, __arg_12__.location);

}
routine_decl1(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__, __arg_6__, __arg_7__, __arg_8__, __arg_9__, __arg_10__, __arg_11__, __arg_12__, __arg_13__, __arg_14__) {

@@ -259,198 +312,273 @@ if (__arg_3__.value != __arg_14__.value) throw new _error.JungleError('Erreur de correspondance de nom pour la fonction ' + __arg_3__.value + ' / ' + __arg_14__.value, __arg_14__.location);

}
routine_decls0(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return new ast.Routine(__arg_1__.value, __arg_2__.value, __arg_3__.value, __arg_4__.value);
routine_decls0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__) {
return new ast.Routine(__arg_1__.value, __arg_2__.value, __arg_3__.value, __arg_4__.value, __arg_5__.value);
}
routine_params0(__arg_1__, __arg_2__) {
return new ast.Parameters(__arg_1__.value, __arg_2__.value);
}
routine_params1(__arg_1__, __arg_2__) {
return new ast.Parameters(__arg_2__.value, __arg_1__.value, true);
}
routine_params2(__arg_1__) {
return new ast.Parameters(__arg_1__.value, []);
}
routine_params3(__arg_1__) {
return new ast.Parameters([], __arg_1__.value);
}
routine_params4() {
return new ast.Parameters([], []);
}
local_params0(__arg_1__, __arg_2__, __arg_3__) {
return __arg_3__.value;
}
global_params0(__arg_1__, __arg_2__, __arg_3__) {
return __arg_3__.value;
}
algo_instructions0(__arg_1__) {
return __arg_1__.value;
}
algo_instructions1() {
return [];
}
algo_expressions_list0(__arg_1__, __arg_2__, __arg_3__) {
__arg_1__.value.push(__arg_2__.value);return __arg_1__.value;
__arg_1__.value.push(__arg_2__.value);
return __arg_1__.value;
}
algo_expressions_list1(__arg_1__, __arg_2__) {
return [__arg_1__.value];
}
expression0(__arg_1__) {
return __arg_1__.value;
}
expression1(__arg_1__) {
return __arg_1__.value;
}
valued_cplte_expression0(__arg_1__) {
return __arg_1__.value;
}
valued_cplte_expression1(__arg_1__) {
return new ast.IdentifierRef(__arg_1__.location, __arg_1__.value);
}
valued_cplte_expression2(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return new ast.RoutineCall(__arg_1__.location, __arg_1__.value, __arg_3__.value);
}
valued_cplte_expression3(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return new ast.ArrayAccess(__arg_2__.location, __arg_1__.value, __arg_3__.value);
}
valued_cplte_expression4(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '←', __arg_3__.value);
}
valued_cplte_expression5(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '+', __arg_3__.value);
}
valued_cplte_expression6(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '-', __arg_3__.value);
}
valued_cplte_expression7(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '=', __arg_3__.value);
}
valued_cplte_expression8(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '<>', __arg_3__.value);
}
valued_cplte_expression9(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, 'et', __arg_3__.value);
}
valued_cplte_expression10(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, 'ou', __arg_3__.value);
}
valued_cplte_expression11(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, 'oue', __arg_3__.value);
}
valued_cplte_expression12(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '<', __arg_3__.value);
}
valued_cplte_expression13(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '<=', __arg_3__.value);
}
valued_cplte_expression14(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '>', __arg_3__.value);
}
valued_cplte_expression15(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '>=', __arg_3__.value);
}
valued_cplte_expression16(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '*', __arg_3__.value);
}
valued_cplte_expression17(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, '/', __arg_3__.value);
}
valued_cplte_expression18(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, 'div', __arg_3__.value);
}
valued_cplte_expression19(__arg_1__, __arg_2__, __arg_3__) {
return new ast.Binary(__arg_2__.location, __arg_1__.value, 'mod', __arg_3__.value);
}
valued_cplte_expression20(__arg_1__, __arg_2__) {
return new ast.PointerAccess(__arg_2__.location, __arg_1__.value);
}
valued_cplte_expression21(__arg_1__, __arg_2__, __arg_3__) {
return new ast.RecordAccess(__arg_2__.location, __arg_1__.value, __arg_3__.value);
}
valued_cplte_expression22(__arg_1__, __arg_2__) {
return new ast.Unary(__arg_1__.location, '+', __arg_2__.value);
}
valued_cplte_expression23(__arg_1__, __arg_2__) {
return new ast.Unary(__arg_1__.location, '-', __arg_2__.value);
}
valued_cplte_expression24(__arg_1__, __arg_2__) {
return new ast.Unary(__arg_1__.location, 'non', __arg_2__.value);
}
valued_cplte_expression25(__arg_1__, __arg_2__, __arg_3__) {
return __arg_2__.value;
}
valued_expression0(__arg_1__) {
return __arg_1__.value;
}
valued_expression1(__arg_1__) {
return new ast.IdentifierRef(__arg_1__.location, __arg_1__.value);
}
valued_expression2(__arg_1__) {
return __arg_1__.value;
}
control_expression0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__, __arg_6__, __arg_7__, __arg_8__) {
return new ast.Si(__arg_1__.location, __arg_2__.value, __arg_5__.value, __arg_6__.value);
}
control_expression1(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__, __arg_6__, __arg_7__) {
return new ast.TantQue(__arg_1__.location, __arg_2__.value, __arg_5__.value);
}
control_expression2(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__) {
return new ast.TantQue(__arg_1__.location, __arg_5__.value, __arg_3__.value, true);
}
control_expression3(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__, __arg_6__, __arg_7__, __arg_8__, __arg_9__, __arg_10__, __arg_11__, __arg_12__) {
return new ast.Pour(__arg_1__.location, __arg_2__.value, __arg_4__.value, __arg_6__.value, __arg_7__.value, __arg_10__.value);
}
control_expression4(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__, __arg_6__, __arg_7__, __arg_8__) {
return new ast.Selon(__arg_1__.location, __arg_2__.value, __arg_5__.value, __arg_6__.value);
}
valued_expression_list0(__arg_1__) {
return __arg_1__.value;
}
valued_expression_list1() {
return [];
}
valued_expression_list_not_empty0(__arg_1__, __arg_2__, __arg_3__) {
__arg_1__.value.push(__arg_3__.value);return __arg_1__.value;
__arg_1__.value.push(__arg_3__.value);
return __arg_1__.value;
}
valued_expression_list_not_empty1(__arg_1__) {
return [__arg_1__.value];
}
sinon0(__arg_1__, __arg_2__, __arg_3__) {
return __arg_3__.value;
}
sinon1() {
return null;
}
ordre0(__arg_1__) {
return true;
}
ordre1() {
return false;
}
selon_expressions0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__) {
__arg_1__.value.push(new ast.SelonExpression(__arg_3__.value, __arg_5__.value));return __arg_1__.value;
__arg_1__.value.push(new ast.SelonExpression(__arg_3__.value, __arg_5__.value));
return __arg_1__.value;
}
selon_expressions1(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return [new ast.SelonExpression(__arg_2__.value, __arg_4__.value)];
}
autrement0(__arg_1__, __arg_2__) {
return __arg_2__.value;
}
autrement1() {
return null;
}
scalar_list0(__arg_1__, __arg_2__, __arg_3__) {
__arg_1__.value.push(__arg_3__.value);return __arg_1__.value;
__arg_1__.value.push(__arg_3__.value);
return __arg_1__.value;
}
scalar_list1(__arg_1__) {
return [__arg_1__.value];
}
scalar0(__arg_1__) {
return new ast.Scalar(__arg_1__.location, new ast.IdentifierRef(__arg_1__.location, __arg_1__.value));
}
scalar1(__arg_1__) {
return new ast.Scalar(__arg_1__.location, new ast.Value(__arg_1__.location, 'entier', __arg_1__.value));
}
scalar2(__arg_1__) {
return new ast.Scalar(__arg_1__.location, new ast.Value(__arg_1__.location, 'caractere', __arg_1__.value));
}
}
exports.Parser = Parser;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Afficher = undefined;
exports.Afficher = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Afficher extends ast.Procedure {

@@ -23,3 +21,5 @@ constructor(chaine) {

}
}
exports.Afficher = Afficher;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,12 +6,10 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Allouer = undefined;
exports.Allouer = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
var _error = require("../jungle/error.js");
var _error = require('../jungle/error.js');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Allouer extends ast.Procedure {

@@ -24,5 +22,3 @@ constructor() {

if (args.length !== 1) throw new _error.JungleError('allouer prend un seul paramètre et non ' + args.length);
if (!(args[0].resType instanceof ast.Pointer)) throw new _error.JungleError('allouer prend un paramètre de type pointeur et non un ' + args[0].resType, args[0].location);
return true;

@@ -38,3 +34,5 @@ }

}
}
exports.Allouer = Allouer;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,16 +6,12 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Caractere = undefined;
exports.Caractere = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
var types = _interopRequireWildcard(require("../types"));
var _types = require('../types');
var _error = require("../jungle/error.js");
var types = _interopRequireWildcard(_types);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
var _error = require('../jungle/error.js');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Caractere extends ast.Function {

@@ -28,7 +24,4 @@ constructor(caractere) {

if (args.length !== 1) throw new Error('caractere prend un seul paramètre et non ' + args.length);
const argType = args[0].resType;
if (!(argType instanceof types.Entier || argType instanceof types.Caractere)) throw new _error.JungleError('cet argument ne peut pas être transformé en caractere', args[0].location);
return true;

@@ -41,3 +34,5 @@ }

}
}
exports.Caractere = Caractere;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,16 +6,12 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Chaine = undefined;
exports.Chaine = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
var types = _interopRequireWildcard(require("../types"));
var _types = require('../types');
var _error = require("../jungle/error.js");
var types = _interopRequireWildcard(_types);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
var _error = require('../jungle/error.js');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Chaine extends ast.Function {

@@ -28,7 +24,4 @@ constructor(chaine) {

if (args.length !== 1) throw new _error.JungleError('chaine prend un seul paramètre et non ' + args.length);
const argType = args[0].resType;
if (!(argType instanceof types.Entier || argType instanceof types.Reel || argType instanceof types.Caractere || argType instanceof types.Chaine)) throw new _error.JungleError('cet argument ne peut pas être transformé en chaine', args[0].location);
return true;

@@ -40,3 +33,5 @@ }

}
}
exports.Chaine = Chaine;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,16 +6,12 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Entier = undefined;
exports.Entier = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
var types = _interopRequireWildcard(require("../types"));
var _types = require('../types');
var _error = require("../jungle/error.js");
var types = _interopRequireWildcard(_types);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
var _error = require('../jungle/error.js');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Entier extends ast.Function {

@@ -28,7 +24,4 @@ constructor(entier) {

if (args.length !== 1) throw new Error('entier prend un seul paramètre et non ' + args.length);
const argType = args[0].resType;
if (!(argType instanceof types.Entier || argType instanceof types.Reel || argType instanceof types.Caractere)) throw new _error.JungleError('cet argument ne peut pas être transformé en entier', args[0].location);
return true;

@@ -41,3 +34,5 @@ }

}
}
exports.Entier = Entier;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,6 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
var _afficher = require('./afficher.js');
Object.defineProperty(exports, 'Afficher', {
Object.defineProperty(exports, "Afficher", {
enumerable: true,

@@ -16,6 +13,3 @@ get: function () {

});
var _allouer = require('./allouer.js');
Object.defineProperty(exports, 'Allouer', {
Object.defineProperty(exports, "Allouer", {
enumerable: true,

@@ -26,6 +20,3 @@ get: function () {

});
var _caractere = require('./caractere.js');
Object.defineProperty(exports, 'Caractere', {
Object.defineProperty(exports, "Caractere", {
enumerable: true,

@@ -36,6 +27,3 @@ get: function () {

});
var _chaine = require('./chaine.js');
Object.defineProperty(exports, 'Chaine', {
Object.defineProperty(exports, "Chaine", {
enumerable: true,

@@ -46,6 +34,3 @@ get: function () {

});
var _entier = require('./entier.js');
Object.defineProperty(exports, 'Entier', {
Object.defineProperty(exports, "Entier", {
enumerable: true,

@@ -56,6 +41,3 @@ get: function () {

});
var _liberer = require('./liberer.js');
Object.defineProperty(exports, 'Liberer', {
Object.defineProperty(exports, "Liberer", {
enumerable: true,

@@ -66,6 +48,3 @@ get: function () {

});
var _longueur = require('./longueur.js');
Object.defineProperty(exports, 'Longueur', {
Object.defineProperty(exports, "Longueur", {
enumerable: true,

@@ -76,6 +55,3 @@ get: function () {

});
var _retourne = require('./retourne.js');
Object.defineProperty(exports, 'Retourne', {
Object.defineProperty(exports, "Retourne", {
enumerable: true,

@@ -85,2 +61,18 @@ get: function () {

}
});
});
var _afficher = require("./afficher.js");
var _allouer = require("./allouer.js");
var _caractere = require("./caractere.js");
var _chaine = require("./chaine.js");
var _entier = require("./entier.js");
var _liberer = require("./liberer.js");
var _longueur = require("./longueur.js");
var _retourne = require("./retourne.js");

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,12 +6,10 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Liberer = undefined;
exports.Liberer = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
var _error = require("../jungle/error.js");
var _error = require('../jungle/error.js');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Liberer extends ast.Procedure {

@@ -24,5 +22,3 @@ constructor() {

if (args.length !== 1) throw new _error.JungleError('liberer prend un seul paramètre et non ' + args.length);
if (!(args[0].resType instanceof ast.Pointer)) throw new _error.JungleError('liberer prend un paramètre de type pointeur et non un ' + args[0].resType, args[0].location);
return true;

@@ -37,3 +33,5 @@ }

}
}
exports.Liberer = Liberer;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Longueur = undefined;
exports.Longueur = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Longueur extends ast.Function {

@@ -23,3 +21,5 @@ constructor(entier, chaine) {

}
}
exports.Longueur = Longueur;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Retourne = undefined;
exports.Retourne = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Retourne extends ast.Procedure {

@@ -24,3 +22,5 @@ constructor(algorithm) {

}
}
exports.Retourne = Retourne;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Caractere = undefined;
exports.Caractere = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Caractere extends ast.Type {

@@ -24,3 +22,5 @@ constructor() {

}
}
exports.Caractere = Caractere;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Chaine = undefined;
exports.Chaine = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Chaine extends ast.Type {

@@ -23,3 +21,5 @@ constructor() {

}
}
exports.Chaine = Chaine;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Entier = undefined;
exports.Entier = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Entier extends ast.Type {

@@ -23,3 +21,5 @@ constructor() {

}
}
exports.Entier = Entier;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,6 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
var _caractere = require('./caractere.js');
Object.defineProperty(exports, 'Caractere', {
Object.defineProperty(exports, "Caractere", {
enumerable: true,

@@ -16,6 +13,3 @@ get: function () {

});
var _chaine = require('./chaine.js');
Object.defineProperty(exports, 'Chaine', {
Object.defineProperty(exports, "Chaine", {
enumerable: true,

@@ -26,6 +20,3 @@ get: function () {

});
var _entier = require('./entier.js');
Object.defineProperty(exports, 'Entier', {
Object.defineProperty(exports, "Entier", {
enumerable: true,

@@ -36,6 +27,3 @@ get: function () {

});
var _no_value = require('./no_value.js');
Object.defineProperty(exports, 'NoValue', {
Object.defineProperty(exports, "NoValue", {
enumerable: true,

@@ -46,6 +34,3 @@ get: function () {

});
var _nul_pointer = require('./nul_pointer.js');
Object.defineProperty(exports, 'NulPointer', {
Object.defineProperty(exports, "NulPointer", {
enumerable: true,

@@ -56,6 +41,3 @@ get: function () {

});
var _reel = require('./reel.js');
Object.defineProperty(exports, 'Reel', {
Object.defineProperty(exports, "Reel", {
enumerable: true,

@@ -65,2 +47,14 @@ get: function () {

}
});
});
var _caractere = require("./caractere.js");
var _chaine = require("./chaine.js");
var _entier = require("./entier.js");
var _no_value = require("./no_value.js");
var _nul_pointer = require("./nul_pointer.js");
var _reel = require("./reel.js");

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.NoValue = undefined;
exports.NoValue = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class NoValue extends ast.Type {

@@ -19,3 +17,5 @@ constructor() {

}
}
exports.NoValue = NoValue;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.NulPointer = undefined;
exports.NulPointer = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class NulPointer extends ast.Pointer {

@@ -24,3 +22,5 @@ constructor() {

}
}
exports.NulPointer = NulPointer;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Reel = undefined;
exports.Reel = void 0;
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Reel extends ast.Type {

@@ -23,3 +21,5 @@ constructor() {

}
}
exports.Reel = Reel;

@@ -6,2 +6,4 @@ "use strict";

});
exports.EmptyVisitor = void 0;
class EmptyVisitor {

@@ -110,3 +112,2 @@ array(arr) {

this.array(selon.expressions);
if (selon.either && selon.either.length) this.array(selon.either);

@@ -123,3 +124,5 @@ }

}
}
exports.EmptyVisitor = EmptyVisitor;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,41 +6,8 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Executor = undefined;
exports.Executor = void 0;
var _empty = require('./empty.js');
var _empty = require("./empty.js");
var _error = require('../jungle/error.js');
var _error = require("../jungle/error.js");
class VariablesScope {
constructor() {
this.scopes = [{}];
}
get scope() {
return this.scopes[this.scopes.length - 1];
}
pushScope() {
this.scopes.push({});
}
popScope() {
if (this.scopes.length === 1) throw new Error('Cannot pop last scope');
this.scopes.pop();
}
add(name, type) {
return this.scope[name] = { type: type, value: type.create() };
}
alias(name, expr) {
return this.scope[name] = expr;
}
get(name) {
for (let i = this.scopes.length - 1; i >= 0; --i) if (name in this.scopes[i]) return this.scopes[i][name];
throw new Error('Variable ' + name + ' non trouvée');
}
}
const binaryOps = {

@@ -98,2 +65,7 @@ '←': function (left, right) {

function checkArrayAccess(dim, pos, length) {
if (1 <= pos && pos <= length) return;
throw new _error.JungleError("Accès hors des limites d'un tableau sur sa dimension " + dim + ': ' + pos + (pos < 1 ? ' < 1 ' : ' > ' + length));
}
class Executor extends _empty.EmptyVisitor {

@@ -104,2 +76,6 @@ get routine() {

get variables() {
return this.scopes[this.scopes.length - 1];
}
array(arr) {

@@ -111,12 +87,9 @@ for (let i = 0; !this.routine.returnValue && i < arr.length; ++i) arr[i].accept(this);

if (!algo.typed) throw new Error('You must type your ast before executing it');
this.variables = new VariablesScope();
this.routines = [algo];
this.scopes = [];
this.heap = {};
algo.execute(this);
if (!Object.keys(this.heap).length) return;
console.error('Fuites mémoires détectées:');
console.error('Fuites mémoires détectées:');
for (let key in this.heap) console.error(' + ' + key + ' a fuité un ' + this.heap[key].type.name);

@@ -133,5 +106,7 @@ }

type: identifier.resType,
get value() {
return identifier.resType.create(identifier.value || identifier.ref);
}
};

@@ -143,5 +118,7 @@ }

type: value.resType,
get value() {
return value.resType.create(value.value);
}
};

@@ -152,11 +129,13 @@ }

const res = record.record.accept(this);
return {
type: record.resType,
get value() {
return res.value[record.property];
},
set value(val) {
return res.value[record.property] = record.resType.create(val);
}
};

@@ -167,19 +146,20 @@ }

const res = array.array.accept(this);
const positions = array.positions.map(pos => pos.accept(this).value);
const lastPos = positions.pop() - 1;
const lastCell = positions.reduce((acc, dim, i) => {
if (dim < 1 || dim > acc.length) throw new _error.JungleError('Accès hors des limites d\'un tableau sur sa dimension ' + (i + 1) + ': ' + dim + ' > ' + acc.length);
return acc[dim - 1];
const lastCell = positions.reduce((acc, pos, dim) => {
checkArrayAccess(dim + 1, pos, acc.length);
return acc[pos - 1];
}, res.value);
if (lastPos < 0 || lastPos >= lastCell.length) throw new _error.JungleError('Accès hors des limites d\'un tableau sur sa dimension ' + (positions.length + 1) + ': ' + (lastPos + 1) + ' > ' + lastCell.length);
checkArrayAccess(positions.length + 1, lastPos + 1, lastCell.length);
return {
type: array.resType,
get value() {
return lastCell[lastPos];
},
set value(val) {
return lastCell[lastPos] = array.resType.create(val);
}
};

@@ -192,2 +172,3 @@ }

return unary.expr.accept(this);
case '-':

@@ -199,2 +180,3 @@ const minus = unary.resType.create(-unary.expr.accept(this).value);

};
case 'non':

@@ -206,2 +188,3 @@ const not = unary.resType.create(!unary.expr.accept(this).value);

};
default:

@@ -214,10 +197,10 @@ throw new Error('Implémentation manquante pour l\'opérateur unaire ' + unary.op);

if (!(binary.op in binaryOps)) throw new Error('Implémentation manquante pour l\'opérateur binaire ' + binary.op);
const res = binaryOps[binary.op](() => binary.left.accept(this), () => binary.right.accept(this), binary.resType);
return {
type: binary.resType,
get value() {
return res;
}
};

@@ -228,17 +211,16 @@ }

const res = pointer.pointer.accept(this);
if (res.value === 0) throw new _error.JungleError('Null pointer exception');
if (!(res.value in this.heap)) throw new _error.JungleError('Segmentation fault');
const heap = this.heap;
return {
type: pointer.resType,
get value() {
return heap[res.value].value;
},
set value(val) {
return heap[res.value].value = val;
}
};

@@ -255,8 +237,6 @@ }

const end = pour.end.accept(this).value + (pour.desc ? -1 : 1);
ref.value = start;
if (!pour.desc && start >= end || pour.desc && start <= end) return;
const incr = pour.desc ? -1 : 1;
const incr = pour.desc ? -1 : 1;
for (; !this.routine.returnValue && ref.value !== end; ref.value += incr) {

@@ -277,7 +257,6 @@ this.array(pour.loop);

visitRoutineCall(routine) {
this.variables.pushScope();
const args = routine.args.map(arg => arg.accept(this));
this.routines.push(routine.toCall);
const res = this.routine.execute(this, routine.args.map(arg => arg.accept(this)));
const res = this.routine.execute(this, args);
this.routines.pop();
this.variables.popScope();
return res;

@@ -309,3 +288,5 @@ }

}
}
exports.Executor = Executor;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,6 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
var _executor = require('./executor.js');
Object.defineProperty(exports, 'Executor', {
Object.defineProperty(exports, "Executor", {
enumerable: true,

@@ -16,6 +13,3 @@ get: function () {

});
var _pretty_printer = require('./pretty_printer.js');
Object.defineProperty(exports, 'PrettyPrinter', {
Object.defineProperty(exports, "PrettyPrinter", {
enumerable: true,

@@ -26,6 +20,3 @@ get: function () {

});
var _typer = require('./typer.js');
Object.defineProperty(exports, 'Typer', {
Object.defineProperty(exports, "Typer", {
enumerable: true,

@@ -35,2 +26,8 @@ get: function () {

}
});
});
var _executor = require("./executor.js");
var _pretty_printer = require("./pretty_printer.js");
var _typer = require("./typer.js");

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,14 +6,10 @@ Object.defineProperty(exports, "__esModule", {

});
exports.PrettyPrinter = undefined;
exports.PrettyPrinter = void 0;
var _chalk = require('chalk');
var _chalk = _interopRequireDefault(require("chalk"));
var _chalk2 = _interopRequireDefault(_chalk);
var ast = _interopRequireWildcard(require("../ast"));
var _ast = require('../ast');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
var ast = _interopRequireWildcard(_ast);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -40,3 +36,2 @@

const dest = this.cols.length ? this.row : this;
if (dest.str[dest.str.length - 1] === '\n') dest.str += this.indentChars;

@@ -66,3 +61,7 @@ dest.str += value;

newrow(header) {
this.col.push({ header: header, headerLength: _chalk2.default.stripColor(header).length, str: '' });
this.col.push({
header: header,
headerLength: _chalk.default.stripColor(header).length,
str: ''
});
}

@@ -77,6 +76,6 @@

let indent = ' ';
for (var i = 0; i < pad; ++i) indent += ' ';
this.print(row.header + ' ');
this.print(row.str.replace(/\n(.)/g, '\n' + indent + '$1'));

@@ -89,2 +88,3 @@ });

}
}

@@ -102,9 +102,7 @@

this.str = new Printer();
this.str.print(_chalk2.default.yellow('algorithme ') + _chalk2.default.white(algo.name)).linefeed().indent();
this.str.print(_chalk.default.yellow('algorithme ') + _chalk.default.white(algo.name)).linefeed().indent();
algo.decls.accept(this);
this.str.deindent().print(_chalk2.default.yellow('debut')).linefeed().indent();
this.str.deindent().print(_chalk.default.yellow('debut')).linefeed().indent();
this.instructionArray(algo.instructions);
this.str.deindent().print(_chalk2.default.yellow('fin algorithme ') + _chalk2.default.white(algo.name));
this.str.deindent().print(_chalk.default.yellow('fin algorithme ') + _chalk.default.white(algo.name));
return this.str.value();

@@ -115,16 +113,19 @@ }

if (decls.consts.length) {
this.str.print(_chalk2.default.yellow('constantes')).linefeed().indent();
this.str.print(_chalk.default.yellow('constantes')).linefeed().indent();
this.instructionArray(decls.consts);
this.str.deindent().linefeed();
}
if (decls.types.length) {
this.str.print(_chalk2.default.yellow('types')).linefeed().indent();
this.str.print(_chalk.default.yellow('types')).linefeed().indent();
this.instructionArray(decls.types);
this.str.deindent().linefeed();
}
if (decls.variables.length) {
this.str.print(_chalk2.default.yellow('variables')).linefeed().indent();
this.str.print(_chalk.default.yellow('variables')).linefeed().indent();
this.instructionArray(decls.variables);
this.str.deindent().linefeed();
}
if (decls.routines && decls.routines.length) this.instructionArray(decls.routines);

@@ -134,3 +135,3 @@ }

visitConst(c) {
this.str.print(_chalk2.default.white(c.name) + ' = ');
this.str.print(_chalk.default.white(c.name) + ' = ');
c.value.accept(this);

@@ -140,37 +141,37 @@ }

visitEnum(e) {
this.str.print(_chalk2.default.white(e.name) + _chalk2.default.magenta(' = ') + '(' + e.values.join(', ') + ')');
this.str.print(_chalk.default.white(e.name) + _chalk.default.magenta(' = ') + '(' + e.values.join(', ') + ')');
}
visitArray(array) {
this.str.print(_chalk2.default.white(array.name) + _chalk2.default.magenta(' = ') + _chalk2.default.blue(array.dimensions.join(_chalk2.default.magenta(' x '))) + ' ' + _chalk2.default.white(array.type));
this.str.print(_chalk.default.white(array.name) + _chalk.default.magenta(' = ') + _chalk.default.blue(array.dimensions.join(_chalk.default.magenta(' x '))) + ' ' + _chalk.default.white(array.type));
}
visitRecord(record) {
this.str.print(_chalk2.default.white(record.name) + _chalk2.default.magenta(' = ') + _chalk2.default.yellow('enregistrement')).linefeed().indent();
this.str.print(_chalk.default.white(record.name) + _chalk.default.magenta(' = ') + _chalk.default.yellow('enregistrement')).linefeed().indent();
this.instructionArray(record.properties);
this.str.deindent().print(_chalk2.default.yellow('fin enregistrement ') + _chalk2.default.white(record.name));
this.str.deindent().print(_chalk.default.yellow('fin enregistrement ') + _chalk.default.white(record.name));
}
visitVariables(variables) {
this.str.print(_chalk2.default.white(variables.type) + ' ' + variables.names.join(', '));
this.str.print(_chalk.default.white(variables.type) + ' ' + variables.names.join(', '));
}
visitPointer(pointer) {
this.str.print(_chalk2.default.white(pointer.name) + _chalk2.default.magenta(' = ↑') + _chalk2.default.white(pointer.pointOn));
this.str.print(_chalk.default.white(pointer.name) + _chalk.default.magenta(' = ↑') + _chalk.default.white(pointer.pointOn));
}
visitFunction(func) {
this.str.print(_chalk2.default.yellow('algorithme fonction ') + _chalk2.default.white(func.name) + _chalk2.default.magenta(': ') + _chalk2.default.white(func.type)).linefeed().indent();
this.str.print(_chalk.default.yellow('algorithme fonction ') + _chalk.default.white(func.name) + _chalk.default.magenta(': ') + _chalk.default.white(func.type)).linefeed().indent();
func.decls.accept(this);
this.str.deindent().print(_chalk2.default.yellow('debut')).linefeed().indent();
this.str.deindent().print(_chalk.default.yellow('debut')).linefeed().indent();
this.instructionArray(func.instructions);
this.str.deindent().print(_chalk2.default.yellow('fin algorithme fonction ') + _chalk2.default.white(func.name)).linefeed();
this.str.deindent().print(_chalk.default.yellow('fin algorithme fonction ') + _chalk.default.white(func.name)).linefeed();
}
visitProcedure(func) {
this.str.print(_chalk2.default.yellow('algorithme procedure ') + _chalk2.default.white(func.name)).linefeed().indent();
this.str.print(_chalk.default.yellow('algorithme procedure ') + _chalk.default.white(func.name)).linefeed().indent();
func.decls.accept(this);
this.str.deindent().print(_chalk2.default.yellow('debut')).linefeed().indent();
this.str.deindent().print(_chalk.default.yellow('debut')).linefeed().indent();
this.instructionArray(func.instructions);
this.str.deindent().print(_chalk2.default.yellow('fin algorithme procedure ') + _chalk2.default.white(func.name)).linefeed();
this.str.deindent().print(_chalk.default.yellow('fin algorithme procedure ') + _chalk.default.white(func.name)).linefeed();
}

@@ -185,3 +186,3 @@

if (!parameters.reverseOrder && parameters.locals.length) {
this.str.print(_chalk2.default.yellow('parametres locaux')).linefeed().indent();
this.str.print(_chalk.default.yellow('parametres locaux')).linefeed().indent();
this.instructionArray(parameters.locals);

@@ -192,3 +193,3 @@ this.str.deindent().linefeed();

if (parameters.globals.length) {
this.str.print(_chalk2.default.yellow('parametres globaux')).linefeed().indent();
this.str.print(_chalk.default.yellow('parametres globaux')).linefeed().indent();
this.instructionArray(parameters.globals);

@@ -199,3 +200,3 @@ this.str.deindent().linefeed();

if (parameters.reverseOrder && parameters.locals.length) {
this.str.print(_chalk2.default.yellow('parametres locaux')).linefeed().indent();
this.str.print(_chalk.default.yellow('parametres locaux')).linefeed().indent();
this.instructionArray(parameters.locals);

@@ -208,3 +209,3 @@ this.str.deindent().linefeed();

binary.left.accept(this);
this.str.print(' ' + _chalk2.default.magenta(binary.op) + ' ');
this.str.print(' ' + _chalk.default.magenta(binary.op) + ' ');
binary.right.accept(this);

@@ -215,7 +216,7 @@ }

record.record.accept(this);
this.str.print(_chalk2.default.magenta('.') + _chalk2.default.white(record.property));
this.str.print(_chalk.default.magenta('.') + _chalk.default.white(record.property));
}
visitIdentifierRef(identifier) {
this.str.print(_chalk2.default.white(identifier.ref));
this.str.print(_chalk.default.white(identifier.ref));
}

@@ -225,3 +226,3 @@

array.array.accept(this);
this.str.print(_chalk2.default.magenta('['));
this.str.print(_chalk.default.magenta('['));
array.positions.forEach((position, i) => {

@@ -231,7 +232,7 @@ if (i != 0) this.str.print(', ');

});
this.str.print(_chalk2.default.magenta(']'));
this.str.print(_chalk.default.magenta(']'));
}
visitUnary(unary) {
this.str.print(_chalk2.default.magenta(unary.op));
this.str.print(_chalk.default.magenta(unary.op));
if (unary.op === 'non') this.str.print(' ');

@@ -245,7 +246,9 @@ unary.expr.accept(this);

case 'string':
return _chalk2.default.green('"' + value.value.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"');
return _chalk.default.green('"' + value.value.replace(/"/g, '\\"').replace(/\n/g, '\\n') + '"');
case 'caractere':
return _chalk2.default.green("'" + value.value.replace(/"/g, '\\"').replace(/\n/g, '\\n') + "'");
return _chalk.default.green("'" + value.value.replace(/"/g, '\\"').replace(/\n/g, '\\n') + "'");
default:
return _chalk2.default.blue(value.value);
return _chalk.default.blue(value.value);
}

@@ -259,15 +262,17 @@ }

visitSi(si) {
this.str.print(_chalk2.default.yellow('si '));
this.str.print(_chalk.default.yellow('si '));
si.expr.accept(this);
this.str.print(_chalk2.default.yellow(' alors')).linefeed().indent();
this.str.print(_chalk.default.yellow(' alors')).linefeed().indent();
this.instructionArray(si.vrai);
if (si.faux) {
this.str.deindent().print(_chalk2.default.yellow('sinon')).linefeed().indent();
this.str.deindent().print(_chalk.default.yellow('sinon')).linefeed().indent();
this.instructionArray(si.faux);
}
this.str.deindent().print(_chalk2.default.yellow('fin si'));
this.str.deindent().print(_chalk.default.yellow('fin si'));
}
visitRoutineCall(routine) {
this.str.print(_chalk2.default.white(routine.ref) + '(');
this.str.print(_chalk.default.white(routine.ref) + '(');
routine.args.forEach((arg, i) => {

@@ -281,21 +286,23 @@ if (i != 0) this.str.print(', ');

visitPour(pour) {
this.str.print(_chalk2.default.yellow('pour ') + _chalk2.default.white(pour.ref) + _chalk2.default.magenta(' ← '));
this.str.print(_chalk.default.yellow('pour ') + _chalk.default.white(pour.ref) + _chalk.default.magenta(' ← '));
pour.start.accept(this);
this.str.print(_chalk2.default.yellow(' jusqu\'a '));
this.str.print(_chalk.default.yellow(' jusqu\'a '));
pour.end.accept(this);
if (pour.desc) this.str.print(_chalk2.default.yellow(' decroissant'));
this.str.print(_chalk2.default.yellow(' faire')).linefeed().indent();
if (pour.desc) this.str.print(_chalk.default.yellow(' decroissant'));
this.str.print(_chalk.default.yellow(' faire')).linefeed().indent();
this.instructionArray(pour.loop);
this.str.deindent().print(_chalk2.default.yellow('fin pour'));
this.str.deindent().print(_chalk.default.yellow('fin pour'));
}
visitTantQue(tantque) {
this.str.print(_chalk2.default.yellow(tantque.oneLoop ? 'faire' : 'tant que '));
this.str.print(_chalk.default.yellow(tantque.oneLoop ? 'faire' : 'tant que '));
if (!tantque.oneLoop) {
tantque.expr.accept(this);
this.str.print(_chalk2.default.yellow(' faire'));
this.str.print(_chalk.default.yellow(' faire'));
}
this.str.linefeed().indent();
this.instructionArray(tantque.loop);
this.str.deindent().print(_chalk2.default.yellow(tantque.oneLoop ? 'tant que ' : 'fin tant que'));
this.str.deindent().print(_chalk.default.yellow(tantque.oneLoop ? 'tant que ' : 'fin tant que'));
if (tantque.oneLoop) tantque.expr.accept(this);

@@ -306,10 +313,9 @@ }

pointer.pointer.accept(this);
this.str.print(_chalk2.default.magenta('↑'));
this.str.print(_chalk.default.magenta('↑'));
}
visitSelon(selon) {
this.str.print(_chalk2.default.yellow('selon '));
this.str.print(_chalk.default.yellow('selon '));
selon.test.accept(this);
this.str.print(_chalk2.default.yellow(' faire')).linefeed().indent();
this.str.print(_chalk.default.yellow(' faire')).linefeed().indent();
this.str.startcol();

@@ -319,3 +325,3 @@ this.instructionArray(selon.expressions, false);

if (selon.either && selon.either.length) {
this.str.newrow(_chalk2.default.yellow('autrement'));
this.str.newrow(_chalk.default.yellow('autrement'));
this.instructionArray(selon.either);

@@ -325,4 +331,3 @@ }

this.str.endcol();
this.str.deindent().print(_chalk2.default.yellow('fin selon'));
this.str.deindent().print(_chalk.default.yellow('fin selon'));
}

@@ -332,6 +337,8 @@

const header = expr.scalars.map(scalar => scalar.value instanceof ast.IdentifierRef ? scalar.value.ref : this.printValue(scalar.value)).join(', ');
this.str.newrow(header + _chalk2.default.yellow(':'));
this.str.newrow(header + _chalk.default.yellow(':'));
this.instructionArray(expr.expressions);
}
}
exports.PrettyPrinter = PrettyPrinter;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,26 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.Typer = exports.Scopes = undefined;
exports.Typer = exports.Scopes = void 0;
var _empty = require('./empty.js');
var _empty = require("./empty.js");
var _error = require('../jungle/error.js');
var _error = require("../jungle/error.js");
var _ast = require('../ast');
var ast = _interopRequireWildcard(require("../ast"));
var ast = _interopRequireWildcard(_ast);
var types = _interopRequireWildcard(require("../types"));
var _types = require('../types');
var routines = _interopRequireWildcard(require("../routines"));
var types = _interopRequireWildcard(_types);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
var _routines = require('../routines');
var routines = _interopRequireWildcard(_routines);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
class Scopes {
constructor() {
constructor(scopeRef) {
this.scopes = [];
this.pushScope();
this.pushScope(scopeRef);
this.addType(new ast.Enum(['faux', 'vrai']).setName('booleen'));

@@ -47,4 +41,5 @@ this.addType(new types.Caractere());

pushScope() {
pushScope(scopeRef) {
this.scopes.push({
scopeRef: scopeRef,
consts: {},

@@ -66,2 +61,6 @@ types: {},

get prevScope() {
return this.scopes[this.scopes.length - 2];
}
getConst(name) {

@@ -71,2 +70,3 @@ for (let i = this.scopes.length - 1; i >= 0; --i) {

}
throw new _error.JungleError('Impossible de trouver la constante ' + name);

@@ -79,2 +79,3 @@ }

}
throw new _error.JungleError('Impossible de trouver le type ' + name);

@@ -87,2 +88,3 @@ }

}
throw new _error.JungleError('Impossible de trouver la variable ' + name);

@@ -95,2 +97,3 @@ }

}
throw new _error.JungleError('Impossible de trouver la valeur ' + value);

@@ -103,2 +106,3 @@ }

}
throw new _error.JungleError('Impossible de trouver la routine ' + name);

@@ -109,5 +113,3 @@ }

if (!(c instanceof ast.Const)) throw new _error.JungleError('Le paramètre doit être une constante');
if (c.name in this.scope.consts) throw new _error.JungleError('Impossible de redéfinir la constante ' + c.name);
this.scope.consts[c.name] = c;

@@ -118,7 +120,4 @@ }

if (!(type instanceof ast.Type)) throw new _error.JungleError('Le paramètre doit être un type');
if (type.name in this.scope.types) throw new _error.JungleError('Impossible de redéfinir le type ' + type.name);
this.scope.types[type.name] = type;
if (type instanceof ast.Enum) this.addValues(type);

@@ -131,3 +130,2 @@ }

if (name in this.scope.variables) throw new _error.JungleError('Impossible de redéfinir la variable ' + name);
this.scope.variables[name] = this.getType(type);

@@ -142,3 +140,2 @@ }

if (value in this.scope.values) throw new _error.JungleError('Impossible de redéfinir la valeur ' + value + ' dans le type ' + type.name + ' car déjà définie par le type ' + this.scope.values[value].name);
this.scope.values[value] = type;

@@ -149,20 +146,28 @@ }

if (routine.name in this.scope.routines) throw new _error.JungleError('Impossible de redéfinir l\'algorithme ' + routine.name);
this.scope.routines[routine.name] = routine;
}
}
exports.Scopes = Scopes;
class Typer extends _empty.EmptyVisitor {
visitAlgorithm(algo) {
this.scopes = new Scopes();
this.scopes = new Scopes(algo);
super.visitAlgorithm(algo);
algo.typed = true;
}
} // Those need new scopes
// Those need new scopes
visitFunction(func) {
this.scopes.addRoutine(func);
this.scopes.pushScope();
func.type = this.scopes.getType(func.type);
if (this.typeMode === 'register') {
this.scopes.addRoutine(func);
this.scopes.pushScope(func);
func.type = this.scopes.getType(func.type);
func.decls.accept(this);
this.scopes.popScope();
return;
}
this.scopes.pushScope(func);
this.scopes.addRoutine(new routines.Retourne(func));

@@ -172,6 +177,14 @@ super.visitFunction(func);

}
visitProcedure(func) {
this.scopes.addRoutine(func);
this.scopes.pushScope();
func.type = this.scopes.getType('<no value>');
if (this.typeMode === 'register') {
this.scopes.addRoutine(func);
this.scopes.pushScope(func);
func.type = this.scopes.getType('<no value>');
func.decls.accept(this);
this.scopes.popScope();
return;
}
this.scopes.pushScope(func);
super.visitProcedure(func);

@@ -181,8 +194,13 @@ this.scopes.popScope();

// Add values in scopes
visitRoutine(routine) {
routine.searchScopeIn = this.scopes.prevScope.scopeRef;
super.visitRoutine(routine);
} // Add values in scopes
visitAlgoDecls(decls) {
if (this.typeMode === 'register') return;
if (decls.consts.length) this.array(decls.consts);
if (decls.types.length) {
const prevMode = this.typeMode;
this.typeMode = 'register';

@@ -192,3 +210,2 @@ this.array(decls.types);

this.array(decls.types);
this.typeMode = prevMode;
}

@@ -198,3 +215,8 @@

if (decls.routines && decls.routines.length) this.array(decls.routines);
if (decls.routines && decls.routines.length) {
this.typeMode = 'register';
this.array(decls.routines);
this.typeMode = 'check';
this.array(decls.routines);
}
}

@@ -206,2 +228,3 @@

}
visitArray(array) {

@@ -212,9 +235,7 @@ if (this.typeMode === 'check') {

}
array.dimensions = array.dimensions.map(dimension => {
if (!isNaN(+dimension)) return dimension;
const c = this.scopes.getConst(dimension);
if (c.value.type !== 'entier') throw new _error.JungleError('Dans la définition du type tableau ' + array.name + ': ' + dimension + ' n\'est pas un entier');
return c.value.value;

@@ -224,2 +245,3 @@ });

}
visitEnum(e) {

@@ -229,2 +251,3 @@ if (this.typeMode === 'check') return;

}
visitRecord(record) {

@@ -235,6 +258,6 @@ if (this.typeMode === 'register') {

}
this.scopes.pushScope();
super.visitRecord(record);
this.scopes.popScope();
}
visitPointer(pointer) {

@@ -245,10 +268,12 @@ if (this.typeMode === 'check') {

}
this.scopes.addType(pointer);
}
visitVariables(variables) {
variables.names.forEach(name => this.scopes.addVariable(name, variables.type));
variables.type = this.scopes.getType(variables.type);
}
} // Check typing
// Check typing
visitIdentifierRef(identifier) {

@@ -273,3 +298,2 @@ try {

routine.resType = routine.toCall.type || this.scopes.getType('<no value>');
routine.toCall.checkParameters(routine.args);

@@ -281,7 +305,5 @@ }

if (!(record.record.resType instanceof ast.Record)) throw new _error.JungleError('Impossible d\'utiliser l\'opérateur . sur une expression qui n\'est pas un enregistrement (type ' + record.record.resType.name + ')');
const property = record.record.resType.properties.find(variables => variables.names.indexOf(record.property) >= 0);
if (!property) throw new _error.JungleError('La propriété ' + record.property + ' n\'existe pas dans l\'enregistrement ' + record.record.resType.name);
record.resType = property.type;
record.writable = record.record.writable;

@@ -292,16 +314,10 @@ }

super.visitArrayAccess(array);
const isArray = array.array.resType instanceof ast.Array;
const isChaine = array.array.resType instanceof types.Chaine;
if (!isArray && !isChaine) throw new _error.JungleError('Impossible d\'utiliser l\'opérateur [] sur une expression qui n\'est pas un tableau ou une chaine (type ' + array.array.resType.name + ')');
if (isArray && array.positions.length != array.array.resType.dimensions.length) throw new _error.JungleError('Impossible d\'accéder à un tableau de type ' + array.array.resType.name + ' en utilisant ' + array.positions.length + ' dimensions alors qu\'il en comporte ' + array.array.resType.dimensions.length);else if (isChaine && array.positions.length != 1) throw new _error.JungleError('Impossible d\'accéder à une chaine en utilisant ' + array.positions.length + ' dimensions');
array.resType = isArray ? array.array.resType.type : this.scopes.getType('caractere');
array.positions.forEach((pos, i) => {
if (pos.resType !== this.scopes.getType('entier')) throw new _error.JungleError('Le type de l\'expression pour la dimension ' + (i + 1) + ' lors de l\'accès à un tableau de type ' + array.resType.name + ' doit être un entier et non un ' + pos.resType.name);
});
array.writable = isArray && array.array.writable;

@@ -316,2 +332,3 @@ }

super.visitUnary(unary);
switch (unary.op) {

@@ -321,2 +338,3 @@ case 'non':

break;
case '+':

@@ -326,2 +344,3 @@ case '-':

break;
default:

@@ -336,3 +355,2 @@ throw new _error.JungleError('Opérateur unaire inconnu : ' + unary.op);

super.visitBinary(binary);
const opPossibilities = {

@@ -356,10 +374,10 @@ arith: {

function resolvePossibilites(scopes, possibilities, left, right) {
if (typeof possibilities !== 'object') possibilities = { entry: possibilities, out: 'last' };
if (typeof possibilities !== 'object') possibilities = {
entry: possibilities,
out: 'last'
};
if (!Array.isArray(possibilities.entry)) possibilities.entry = [possibilities.entry];
const entry = possibilities.entry.find(entry => {
if (typeof entry === 'string') entry = [entry];
entry = entry.map(type => scopes.getType(type));
return entry.indexOf(left) >= 0 && entry.indexOf(right) >= 0;

@@ -399,2 +417,3 @@ });

const sameTypes = binary.left.resType === binary.right.resType;
if (isEnum && sameTypes || isPointer && (sameTypes || binary.left.resType instanceof types.NulPointer || binary.right.resType instanceof types.NulPointer)) {

@@ -404,2 +423,3 @@ binary.resType = this.scopes.getType('booleen');

}
case '<':

@@ -434,5 +454,3 @@ case '>':

super.visitSi(si);
if (si.expr.resType !== this.scopes.getType('booleen')) throw new _error.JungleError('si prend une expression booléenne et non un ' + si.expr.resType.name);
si.resType = this.scopes.getType('<no value>');

@@ -443,13 +461,7 @@ }

super.visitPour(pour);
pour.refType = this.scopes.getVariable(pour.ref);
const entier = this.scopes.getType('entier');
if (pour.refType !== entier) throw new _error.JungleError('pour prend une variable de type entier et non un ' + pour.refType.name);
if (pour.start.resType !== entier) throw new _error.JungleError('pour prend une expression entière comme valeur de départ et non un ' + pour.start.resType.name);
if (pour.end.resType !== entier) throw new _error.JungleError('pour prend une expression entière comme valeur de fin et non un ' + pour.end.resType.name);
pour.resType = this.scopes.getType('<no value>');

@@ -460,5 +472,3 @@ }

super.visitTantQue(tantque);
if (tantque.expr.resType !== this.scopes.getType('booleen')) throw new _error.JungleError('tant que prend une expression booléenne et non un ' + tantque.expr.resType.name);
tantque.resType = this.scopes.getType('<no value>');

@@ -469,5 +479,3 @@ }

super.visitPointerAccess(pointer);
if (!(pointer.pointer.resType instanceof ast.Pointer)) throw new _error.JungleError('Impossible de déréférencer un type qui n\'est pas un pointeur');
pointer.resType = pointer.pointer.resType.pointOn;

@@ -479,5 +487,3 @@ pointer.writable = true;

super.visitSelon(selon);
if (selon.test.resType !== this.scopes.getType('entier') && selon.test.resType !== this.scopes.getType('caractere') && !(selon.test.resType instanceof ast.Enum)) throw new _error.JungleError('selon attend une expression de type entier, caractere ou enum et non un ' + selon.test.resType);
selon.expressions.forEach(expr => {

@@ -490,6 +496,4 @@ if (expr.resType !== selon.test.resType) throw new _error.JungleError('selon a une expression de type ' + selon.test.resType.name + ' mais les scalaires de cette liste sont du type ' + expr.resType.name, expr.scalars[0].location);

super.visitSelonExpression(expr);
expr.resType = expr.scalars.reduce((acc, scalar) => {
if (acc.resType !== scalar.resType) throw new _error.JungleError('tous les scalaires dans la liste du selon doivent être du même type, ici ' + acc.resType.name + ' != ' + scalar.resType.name, scalar.location);
return scalar;

@@ -501,10 +505,9 @@ }).resType;

super.visitScalar(scalar);
if (scalar.value.resType !== this.scopes.getType('entier') && scalar.value.resType !== this.scopes.getType('caractere') && !(scalar.value.resType instanceof ast.Enum)) throw new _error.JungleError('les scalaires dans selon doivent être de type entier, caractere ou enum et non un ' + scalar.value.resType);
if (scalar.value.writable) throw new _error.JungleError('impossible d\'utiliser une variable comme scalaire dans selon');
scalar.resType = scalar.value.resType;
}
}
exports.Typer = Typer;

@@ -5,2 +5,25 @@ import {Ast} from './base.js'

class VariablesScope {
constructor(parent = null) {
this.scope = {}
this.parent = parent
}
add(name, type) {
return this.scope[name] = {type: type, value: type.create()}
}
alias(name, expr) {
return this.scope[name] = expr
}
get(name) {
if (name in this.scope)
return this.scope[name]
if (this.parent !== null)
return this.parent.get(name)
throw new Error('Variable ' + name + ' non trouvée')
}
}
export class Algorithm extends Ast {

@@ -58,2 +81,5 @@ constructor(location, name, decls, instructions) {

execute(executor, params) {
this.variablesScope = new VariablesScope(this.decls.searchScopeIn ? this.decls.searchScopeIn.variablesScope : null)
executor.scopes.push(this.variablesScope)
if (this.decls instanceof Routine) {

@@ -63,5 +89,7 @@ this.getOverVariables(

(variables, name, index) => {
if (variables.assignable)
return executor.variables.alias(name, params[index])
executor.variables.add(name, variables.type).value = variables.type.create(params[index].value)
if (variables.assignable) {
executor.variables.alias(name, params[index])
return
}
this.variablesScope.add(name, variables.type).value = variables.type.create(params[index].value)
}

@@ -79,2 +107,4 @@ )

this.returnValue = null
executor.scopes.pop()
return res

@@ -81,0 +111,0 @@ }

import {Ast} from './base.js'
export class Routine extends Ast {
constructor(params, consts, types, variables) {
constructor(params, consts, types, variables, routines) {
super()

@@ -10,3 +10,4 @@ this.params = params

this.variables = variables
this.routines = routines
}
}

@@ -241,4 +241,4 @@ import * as ast from "./ast"

}
routine_decls0(__arg_1__, __arg_2__, __arg_3__, __arg_4__) {
return new ast.Routine(__arg_1__.value, __arg_2__.value, __arg_3__.value, __arg_4__.value)
routine_decls0(__arg_1__, __arg_2__, __arg_3__, __arg_4__, __arg_5__) {
return new ast.Routine(__arg_1__.value, __arg_2__.value, __arg_3__.value, __arg_4__.value, __arg_5__.value)
}

@@ -245,0 +245,0 @@ routine_params0(__arg_1__, __arg_2__) {

import {EmptyVisitor} from './empty.js'
import {JungleError} from '../jungle/error.js'
class VariablesScope {
constructor() {
this.scopes = [{}]
}
get scope() {
return this.scopes[this.scopes.length - 1]
}
pushScope() {
this.scopes.push({})
}
popScope() {
if (this.scopes.length === 1)
throw new Error('Cannot pop last scope')
this.scopes.pop()
}
add(name, type) {
return this.scope[name] = {type: type, value: type.create()}
}
alias(name, expr) {
return this.scope[name] = expr
}
get(name) {
for (let i = this.scopes.length - 1; i >= 0; --i)
if (name in this.scopes[i])
return this.scopes[i][name]
throw new Error('Variable ' + name + ' non trouvée')
}
}
const binaryOps = {

@@ -92,2 +56,8 @@ '←': function(left, right) {

function checkArrayAccess(dim, pos, length) {
if (1 <= pos && pos <= length)
return
throw new JungleError("Accès hors des limites d'un tableau sur sa dimension " + dim + ': ' + pos + (pos < 1 ? ' < 1 ' : ' > ' + length))
}
export class Executor extends EmptyVisitor {

@@ -98,2 +68,6 @@ get routine() {

get variables() {
return this.scopes[this.scopes.length - 1]
}
array(arr) {

@@ -108,4 +82,4 @@ for (let i = 0; !this.routine.returnValue && i < arr.length; ++i)

this.variables = new VariablesScope()
this.routines = [algo]
this.scopes = []
this.heap = {}

@@ -166,11 +140,7 @@

const lastPos = positions.pop() - 1
const lastCell = positions.reduce((acc, dim, i) => {
if (dim < 1 || dim > acc.length)
throw new JungleError('Accès hors des limites d\'un tableau sur sa dimension ' +
(i + 1) + ': ' + dim + ' > ' + acc.length)
return acc[dim - 1]
const lastCell = positions.reduce((acc, pos, dim) => {
checkArrayAccess(dim + 1, pos, acc.length);
return acc[pos - 1]
}, res.value)
if (lastPos < 0 || lastPos >= lastCell.length)
throw new JungleError('Accès hors des limites d\'un tableau sur sa dimension ' +
(positions.length + 1) + ': ' + (lastPos + 1) + ' > ' + lastCell.length)
checkArrayAccess(positions.length + 1, lastPos + 1, lastCell.length)

@@ -278,7 +248,6 @@ return {

visitRoutineCall(routine) {
this.variables.pushScope()
const args = routine.args.map(arg => arg.accept(this))
this.routines.push(routine.toCall)
const res = this.routine.execute(this, routine.args.map(arg => arg.accept(this)))
const res = this.routine.execute(this, args)
this.routines.pop()
this.variables.popScope()
return res

@@ -285,0 +254,0 @@ }

@@ -8,5 +8,5 @@ import {EmptyVisitor} from './empty.js'

export class Scopes {
constructor() {
constructor(scopeRef) {
this.scopes = []
this.pushScope()
this.pushScope(scopeRef)
this.addType(new ast.Enum(['faux', 'vrai']).setName('booleen'))

@@ -28,4 +28,5 @@ this.addType(new types.Caractere())

pushScope() {
pushScope(scopeRef) {
this.scopes.push({
scopeRef: scopeRef,
consts: {},

@@ -47,2 +48,6 @@ types: {},

get prevScope() {
return this.scopes[this.scopes.length - 2]
}
getConst(name) {

@@ -144,3 +149,3 @@ for (let i = this.scopes.length - 1; i >= 0; --i) {

visitAlgorithm(algo) {
this.scopes = new Scopes()
this.scopes = new Scopes(algo)
super.visitAlgorithm(algo)

@@ -152,5 +157,11 @@ algo.typed = true

visitFunction(func) {
this.scopes.addRoutine(func)
this.scopes.pushScope()
func.type = this.scopes.getType(func.type)
if (this.typeMode === 'register') {
this.scopes.addRoutine(func)
this.scopes.pushScope(func)
func.type = this.scopes.getType(func.type)
func.decls.accept(this)
this.scopes.popScope()
return
}
this.scopes.pushScope(func)
this.scopes.addRoutine(new routines.Retourne(func))

@@ -161,11 +172,24 @@ super.visitFunction(func)

visitProcedure(func) {
this.scopes.addRoutine(func)
this.scopes.pushScope()
func.type = this.scopes.getType('<no value>')
if (this.typeMode === 'register') {
this.scopes.addRoutine(func)
this.scopes.pushScope(func)
func.type = this.scopes.getType('<no value>')
func.decls.accept(this)
this.scopes.popScope()
return
}
this.scopes.pushScope(func)
super.visitProcedure(func)
this.scopes.popScope()
}
visitRoutine(routine) {
routine.searchScopeIn = this.scopes.prevScope.scopeRef
super.visitRoutine(routine)
}
// Add values in scopes
visitAlgoDecls(decls) {
if (this.typeMode === 'register')
return
if (decls.consts.length)

@@ -175,3 +199,2 @@ this.array(decls.consts)

if (decls.types.length) {
const prevMode = this.typeMode
this.typeMode = 'register'

@@ -181,3 +204,2 @@ this.array(decls.types)

this.array(decls.types)
this.typeMode = prevMode
}

@@ -188,4 +210,8 @@

if (decls.routines && decls.routines.length)
if (decls.routines && decls.routines.length) {
this.typeMode = 'register'
this.array(decls.routines)
this.typeMode = 'check'
this.array(decls.routines)
}
}

@@ -225,5 +251,3 @@

}
this.scopes.pushScope()
super.visitRecord(record)
this.scopes.popScope()
}

@@ -288,3 +312,3 @@ visitPointer(pointer) {

if (!isArray && !isChaine)
throw new JungleError('Impossible d\'utiliser l\'opérateur [] sur une expression qui n\'est pas un tableau ou une chaine (type ' + array.array.resType.name + ')');
throw new JungleError('Impossible d\'utiliser l\'opérateur [] sur une expression qui n\'est pas un tableau ou une chaine (type ' + array.array.resType.name + ')')

@@ -291,0 +315,0 @@ if (isArray && array.positions.length != array.array.resType.dimensions.length)

{
"name": "algo-lang",
"version": "1.1.4",
"version": "1.2.0",
"engines": {
"node": ">=8"
},
"engineStrict": true,
"description": "Algorithmic language interpreter (in French only for now)",
"homepage": "https://bitbucket.org/lsystems/algo-lang/overview",
"dependencies": {
"chalk": "^2.0.1"
"chalk": "^2.4.1"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-preset-es2015": "^6.24.1"
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.6",
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
"@babel/preset-env": "^7.1.6",
"rimraf": "^2.6.2"
},

@@ -18,4 +24,4 @@ "bin": {

"scripts": {
"build": "babel --preset=es2015 --plugins=transform-es2015-modules-commonjs lib --out-dir build",
"prepublish": "npm run build && npm test",
"prepare": "rimraf build && babel lib --out-dir build",
"prepublishOnly": "npm test",
"test": "node build/algo-lang.js test/simple.algo && node build/algo-lang.js test/test.algo"

@@ -33,3 +39,18 @@ },

"author": "Quentin Raynaud",
"license": "MIT"
"license": "MIT",
"babel": {
"plugins": [
"@babel/plugin-transform-modules-commonjs"
],
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "8"
}
}
]
]
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc