2

我尝试通过以下方式运行 ANTLR 3.4:

java -classpath "d:\extracted\antlrworks1.4.3" org.antlr.Tool %p%\parser.g -o %p%\output
or
java -classpath "%p%lib\antlrworks-1.4.3.jar" org.antlr.Tool %p%\parser.g -o %p%\output
or
java -classpath "%p%lib\antlr-3.4.jar;%p%lib\antlr-runtime-3.4.jar;%p%lib\ST4-4.0.4.jar" org.antlr.Tool %p%\parser.g -o %p%\output

Each of them resulted in the same error message;

Message ILLEGAL_OPTION_VALUE in locale en_US not found
Message ALL_OPS_NEED_SAME_ASSOC in locale en_US not found
ANTLR installation corrupted; English messages file en.stg incomplete
Exception in thread "main" java.lang.Error: ANTLR ErrorManager panic
    at org.antlr.tool.ErrorManager.panic(ErrorManager.java:918)
    at org.antlr.tool.ErrorManager.setLocale(ErrorManager.java:427)
    at org.antlr.tool.ErrorManager.<clinit>(ErrorManager.java:390)
    at org.antlr.tool.CompositeGrammar.createNFAs(CompositeGrammar.java:379)
    at org.antlr.Tool.process(Tool.java:466)
    at org.antlr.Tool.main(Tool.java:93)

知道如何解决这个问题吗?

4

2 回答 2

3

我不再使用 v3,除了回答一些问题。我用

$ export CLASSPATH=.:/usr/local/lib/antlr-3.4-complete-no-antlrv2.jar

一劳永逸,并用“编译”语法

$ java org.antlr.Tool Question.g

然后编译

$ javac Question*.java Test.java

然后执行

$ java Test

精度:文件 Test.java 包含:

import org.antlr.runtime.*;

public class Test {
    public static void main(String[] args) throws Exception {
        ANTLRInputStream input = new ANTLRInputStream(System.in);
        QuestionLexer lexer = new QuestionLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        QuestionParser parser = new QuestionParser(tokens);
        parser.question();
    }
}
于 2012-11-27T16:29:23.993 回答
0

我想通了。当前目录必须与 jar 的位置相同。

于 2012-11-27T18:23:24.903 回答