【发布时间】:2016-07-31 06:31:21
【问题描述】:
Node.js 版本:
jj5@orac:~/test/antlr4-js$ node --version
v5.10.1
Java 版本:
jj5@orac:~/test/antlr4-js$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-1~deb8u1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
ANTLR4 版本:
jj5@orac:~/test/antlr4-js$ java -jar ./antlr-4.5.3-complete.jar | head -n 1
ANTLR Parser Generator Version 4.5.3
我的测试脚本:
jj5@orac:~/test/antlr4-js$ cat run.sh
#!/bin/bash
cd "`dirname $0`"
rm ECMAScript????* 2>/dev/null
export CLASSPATH=".:`pwd`/antlr-4.5.3-complete.jar"
java -jar ./antlr-4.5.3-complete.jar -Dlanguage=JavaScript -visitor ECMAScript.g4
node antlr4/run.js
错误发生在最后一行node antlr4/run.js,其中Node.js 运行run.js:
jj5@orac:~/test/antlr4-js$ ./run.sh
[irrelevant warnings elided]
/home/jj5/repo/svn/pcrepo/jj5-test/antlr4-js/ECMAScriptLexer.js:881
private boolean strictMode = true;
^^^^^^^
SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/home/jj5/repo/svn/pcrepo/jj5-test/antlr4-js/antlr4/run.js:2:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
所以 ANTLR4 似乎产生了一些“强类型”的 JavaScript 和 Node.js 阻塞。我该如何解决这个问题..?
注意:如果你安装了 Node.js 和 Java,你可以像这样重现:
cd /tmp
svn co https://www.progclub.org/svn/pcrepo/jj5-test/trunk/antlr4-js/
antlr4-js/run.sh
【问题讨论】:
标签: javascript node.js antlr4 lexical-analysis strong-typing