1
votes

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    : 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...

1
Could you post the grammar? And the precise error message?Codie CodeMonkey
And what is your target language?Codie CodeMonkey
So my understanding is that you're generating code from this grammar (which look like the the basic calculator example). You mention that Test is in fact generated, but the ANTLRWorks debugger isn't finding it. I think the problem is probably something like ANTLRWorks isn't finding the class because it's not in your CLASSPATH or some similarly mundane problem. What about when you run from the command line? Does it work then?Codie CodeMonkey
Yes, it is simple example, but it must be CLASSPATH error. Even though, java -c while trying to run Test.java si making a fatal exception. On the other hand, my Java and Android development is working OK. I have tried to add .../output path to my enivironment variables, but no success. Still havuing the sameWaypoint

1 Answers

1
votes

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.