-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand.js
43 lines (39 loc) · 1.09 KB
/
rand.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
var escodegen = require("escodegen");
var esprima = require("esprima");
var parse = require("./parse");
var generate = require("./generate");
var fs = require("fs");
fs.readFile("parse.js", 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var sourceSyntax = esprima.parse(data);
var model = parse.parseSyntax(sourceSyntax);
try
{
var syntax = generate.generateProgram(model);
if (process.argv.length > 2 && process.argv[2] == 'trees')
{
//print out the model & syntax if an extra param is passed in
console.log(JSON.stringify(model, null, 4));
//console.log(JSON.stringify(syntax, null, 4));
}
else
{
try
{
console.log(escodegen.generate(syntax));
}
catch (e)
{
console.log(JSON.stringify(syntax, null, 4));
console.log(e.stack);
}
}
}
catch (e)
{
console.log(JSON.stringify(model, null, 4));
console.log(e.stack);
}
});