Compiling sample ANTRL4 output
Asked Answered
S

2

9

From the Definitive ANTLR4 reference I have run through the first example and it has generated the JAVA target. In the directory C:\JavaLib I have antlr-4.5-complete.jar When I attempt to compile it with;

javac -classpath C:\JavaLib *.java

It creates 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?

Supper answered 6/7, 2015 at 6:8 Comment(0)
S
8

There was 2 problems. One was the file has to be named "Hello.g4" not "hello.g4" because the grammar is specified as Hello. The second was the classpath, it requires the path and name of the jar file, as well as the current directory. The following command worked;

javac -classpath .;C:\JavaLib\antlr-4.5-complete.jar *.java
Supper answered 7/7, 2015 at 2:23 Comment(1)
Am I correct to assume you need to use the colon separator instead of a semi-colon on a Linux system?Chlorine
B
5

With regard to the above query re the colon separator then the answer is yes. I installed via the debian packages and used the command before working out how to set CLASSPATH

javac -classpath /usr/share/java/antlr4-runtime.jar  Expr*.java

Before this I got a load of compile errors. Also it seems to be worth noting on debian at the moment my .bash_profile never gets loaded so I needed to put this in .bashrc

Burnside answered 15/10, 2020 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.