Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

antlr4-Can't load Hello as lexer or parser

Tags:

antlr4

I recently have to use parser to do a project. I download ANTLR4 and follow the steps described in the book The Definitive ANTLR4 Reference. The following are the steps I type in command line:

 1. export CLASSPATH=".:/<Mydirectory>/antlr-4.2.2-complete.jar:$CLASSPATH"  2. alias antlr4='java -jar /<My directory>/antlr-4.2.2-complete.jar'  3. alias grun='java org.antlr.v4.runtime.misc.TestRig'  4. antlr4 Hello.g4 

All the things work fine, it generates java files that I need. However, after I enter

 5. grun Hello r -tokens 

It reports

Can't load Hello as lexer or parser.

I google some info, but still cannot figure out what happened.

like image 961
user3162707 Avatar asked Apr 26 '14 19:04

user3162707


1 Answers

You generated Java source files by running ANTLR on the grammar, but TestRig is looking for compiled .class files. You need to run the Java compiler on the source files before using TestRig.

like image 62
Sam Harwell Avatar answered Sep 16 '22 15:09

Sam Harwell