开发者

ANTLR - test class not found error when debugging

I am getting error of Test class not found error, even when I have made it via command

java org.antlr.Tool something.g

when debugging via ANTLRworks. I have been searching this on the web, but no success with it. Do you know, how to solve my problem?

Thanks

Edit - grammar:

grammar Expr;

prog    :   stat+ ;

stat    :   expr NEWLINE
    |   ID '=' expr NEWLINE
    |   NEWLINE
    ;

    expr   开发者_Python百科 : multExpr (('+' |'-' ) multExpr)*;

    multExpr: atom ('*' atom)*
        ;

    atom    : INT
        | ID
        | '(' expr ')'
        ;

    ID : ('a'..'z' |'A'..'Z' )+ ;
    INT : '0'..'9' + ;
    NEWLINE:'\r' ? '\n' ;
    WS : (' ' |'\t' |'\n' |'\r' )+ {skip();} ;

Error message:

When debugging with imput text 3*4 makes output - "Error: Could not find or load main class Test" While, Test is generated in subfolder /output...


Since you commented in the comments that running a test class from the console also failed, here's one that works:

import org.antlr.runtime.*;

public class Main {
  public static void main(String[] args) throws Exception {
    ExprLexer lex = new ExprLexer(new ANTLRStringStream("1 + 2 - 3 * 4 - E\n"));
    CommonTokenStream tokens = new CommonTokenStream(lex);
    ExprParser parser = new ExprParser(tokens);
    parser.prog();
  }
}

Now put your ANTLR JAR (v3.3 in my example) in the same directory as Main.java and Expr.g and run the main class from your console like this:

java -cp antlr-3.3.jar org.antlr.Tool Expr.g
javac -cp antlr-3.3.jar *.java
java -cp .;antlr-3.3.jar Main

The fact that nothing is printed to your console means that the parsing went without any problems.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜