-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptFunction.js
More file actions
35 lines (29 loc) · 1004 Bytes
/
scriptFunction.js
File metadata and controls
35 lines (29 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { ErrorHandler } = require('./ErrorHandler/errorHandler');
const { Environment } = require('./Environment/environment');
class ScriptFunction {
constructor(name, args, body, environment) {
const { Parser } = require('./parser');
this.errorHandler = new ErrorHandler();
this.environment = new Environment(environment);
this.parser = new Parser(this.environment);
this.name = name;
this.args = args;
this.body = body;
this.arity = args.length;
};
call(args) {
if (args.length != this.args.length) {
this.errorHandler.throw(
`INVALID NUMBER OF ARGUMENTS PASSED TO ${this.name}`,
)
};
for (let i = 0; i < args.length; i++) {
this.environment.define(this.args[i]['value'], args[i]);
};
this.parser.load(this.body);
this.parser.parse();
};
};
module.exports = {
ScriptFunction,
};