forked from sguise/BlockMirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecma_index.js
38 lines (27 loc) · 1.29 KB
/
ecma_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
window.antlr4 = require('./lib/antlr4/index');
window.ECMAScriptLexer = require('./lib/ECMAScript/ECMAScriptLexer.js');
window.ECMAScriptParser = require('./lib/ECMAScript/ECMAScriptParser.js');
// const ECMAScriptListener = require('./lib/ECMAScriptListener.js');
// const ECMAScriptVisitor = require('./lib/ECMAScriptVisitor.js');
// const PythonGenerator = require('./codegeneration/PythonGenerator.js');
// const ErrorListener = require('./codegeneration/ErrorListener.js');
const input = '{x: new Number(100)}';//input
const chars = new window.antlr4.InputStream(input);
const lexer = new window.ECMAScriptLexer.ECMAScriptLexer(chars);
lexer.strictMode = false;
const tokens = new window.antlr4.CommonTokenStream(lexer);
const parser = new window.ECMAScriptParser.ECMAScriptParser(tokens);
// const listener = new ErrorListener();
// const visitor = new ECMAScriptVisitor.ECMAScriptVisitor();
// const plistener = new ECMAScriptListener.ECMAScriptListener();
// parser.removeErrorListeners(); // Remove default ConsoleErrorListener
// parser.addErrorListener(listener); // Add custom error listener
console.log('JavaScript input:');
console.log(input);
console.log('output:');
try {
tree = parser.program();
console.log(tree.toStringTree(this,parser));
} catch (error) {
console.log(error);
}