Compiling ANTRL4 Output

From the final ANTLR4 link, I skipped the first example and created a JAVA target. In the C: \ JavaLib directory, I have antlr-4.5-complete.jar when I try to compile it with

javac -classpath C:\JavaLib *.java 

It generates the following error messages:

 helloBaseListener.java:13: error: class HelloBaseListener is public, should be declared in a file named HelloBaseListener.java public class HelloBaseListener implements HelloListener { ^ helloListener.java:9: error: class HelloListener is public, should be declared in a file named HelloListener.java public interface HelloListener extends ParseTreeListener { ^ helloParser.java:12: error: class HelloParser is public, should be declared in a file named HelloParser.java public class HelloParser extends Parser { ^ helloBaseListener.java:3: error: package org.antlr.v4.runtime does not exist import org.antlr.v4.runtime.ParserRuleContext; ^ helloBaseListener.java:4: error: package org.antlr.v4.runtime.misc does not exist import org.antlr.v4.runtime.misc.NotNull; ^ helloBaseListener.java:5: error: package org.antlr.v4.runtime.tree does not exist import org.antlr.v4.runtime.tree.ErrorNode; .... 

What am I doing wrong?

+5
source share
1 answer

There were 2 problems. One of them is a file that should be named "Hello.g4" and not "hello.g4" because the grammar is listed as "Hello." The second is the class path, this requires the path and jar file name, as well as the current directory. The following command worked:

 javac -classpath .;C:\JavaLib\antlr-4.5-complete.jar *.java 
+5
source

All Articles