-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (41 loc) · 1.07 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
// here is a sample runner for loading up your lambda expressions
// from a file and running them all
var fs = require('fs');
var Expr = require('./lib/expr');
function usage() {
var s = "\
Usage: \n\
node index.js normalization_strategy input_file \n\
\n\
normalization_strategy can be either of\n\
* cbv, Call by Value\n\
* cbn, Call by Name\n\
\n\
Example: \n\
node index.js cbv example.lc \n\
node index.js cbn example.lc \n";
process.stderr.write(s);
process.exit(1);
}
if (process.argv.length != 4) {
usage();
}
if (process.argv[2] == 'cbv') {
var strategy = Expr.Strategy.CALL_BY_VALUE;
} else if (process.argv[2] = 'cbn') {
var strategy = Expr.Strategy.CALL_BY_NAME;
} else {
usage();
}
var lines = fs.readFileSync(process.argv[3], 'utf8').split(/\n/);
lines = lines.filter(function(n){ return n !== "" });
lines.forEach(function (line, no) {
try {
var e = Expr.parse(line);
} catch(e) {
console.log((no+1) + ': ' + e)
return;
}
console.log((no+1) + ': ' + e.pretty() + ' => ' +
e.normalize(strategy).pretty());
});