-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
77 lines (58 loc) · 1.26 KB
/
test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var inet = require("./index");
var fs = require("fs");
var file = process.argv[2];
function obj2mlc(obj)
{
var node;
if (!obj)
obj = this;
node = obj.node;
if ("atom" == node)
return obj.name;
if ("abst" == node) {
var body = obj2mlc(obj.body);
var sep;
if ("abst" == obj.body.node)
sep = ", ";
else
sep = ": ";
return obj.var + sep + body;
}
if ("appl" == node) {
var left = obj2mlc(obj.left);
var right = obj2mlc(obj.right);
if ("abst" == obj.left.node)
left = "(" + left + ")";
if ("abst" == obj.right.node)
right = "(" + right + ")";
if ("appl" == obj.right.node)
right = "(" + right + ")";
return left + " " + right;
}
return "[ ]";
}
function format(data)
{
if ("object" == typeof data)
return obj2mlc(data);
else if ("number" == typeof data)
return data.toString();
else
return data;
}
if (file) {
var input = fs.readFileSync(file, "utf8");
var eqn;
inet.prepare(input, format);
while (eqn = inet.debug1())
console.log(eqn);
} else {
var example = fs.readFileSync("example.in", "utf8");
var output = inet(example);
var total = output.total;
var beta = output.beta;
var redtime = output.redtime;
var nf = obj2mlc(output.nf);
console.info("%s(%s), %s ms", total, beta, redtime);
console.log(nf);
}