开发者

ANTLR test program hangs

开发者 https://www.devze.com 2023-03-19 06:08 出处:网络
I downloaded the latest version of ANTLR (AntlrWorks 1.4.2 with ANTLR 3.3). I started the AntlrWorks UI, and entered the sample expression evaluator grammar. Next I generated code from the AntlrWork

I downloaded the latest version of ANTLR (AntlrWorks 1.4.2 with ANTLR 3.3).

I started the AntlrWorks UI, and entered the sample expression evaluator grammar. Next I generated code from the AntlrWorks UI. Next I selected the debug menu option to generate the input file and __Test___.java

All is fine till now, however, when I run __Test___ from the command line, ANTLR just hangs. I put some System.out's in th开发者_如何学Goe Java code, and it seems that the program hangs in the following line from __Test___.java

ExprParser g = new ExprParser(tokens, 49100, null);

I also tried printing the token stream, but it does not print anything.

Does anyone have a clue what might be going wrong? I tried multiple grammars, but get the same result.

I am running 64 bit Ubuntu, with OpenJDK.


The debugger creates a socket and waits for a connection that is made from within ANTLRWorks. So you can only run this auto generated __Test__.java class from within ANTLRWorks. If you want to create a test-class from the command line, use the following class:

import org.antlr.runtime.*;

public class Main {
  public static void main(String[] args) throws Exception {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream("4 + 5 * 6\n"));
    ExprParser parser = new ExprParser(new CommonTokenStream(lexer));
    parser.prog();
  }
}
bart@hades:~/Programming/ANTLR/Demos/Expr$ java -cp antlr-3.3.jar org.antlr.Tool Expr.g 
bart@hades:~/Programming/ANTLR/Demos/Expr$ javac -cp antlr-3.3.jar *.java
bart@hades:~/Programming/ANTLR/Demos/Expr$ java -cp .:antlr-3.3.jar Main
34
0

精彩评论

暂无评论...
验证码 换一张
取 消