1
votes

I'm new to ANTLR, and learnt the basics of the grammar and the tools. I was trying to parse a simple CPP source in example.txt which is:

int glob = 0;
int main() {
    return 0;
}

with the grammar: https://github.com/antlr/grammars-v4/blob/master/cpp/CPP14.g4

I tried grun CPP14 translationunit -gui < ./example.txt and received: No method for rule translationunit or it has arguments

Isn't translationunit the root of it?

1

1 Answers

1
votes

The TestRig needs the compiled Java source files to work.

From the terminal (assuming your CPP14.g4 and ANTLR JAR are in the present working directory), do the following:

Generate parser classes

java -cp antlr-4.8-complete.jar org.antlr.v4.Tool CPP14.g4

Compile generated parser classes

javac -cp .:antlr-4.8-complete.jar *.java

Run TestRig

java -cp .:antlr-4.8-complete.jar org.antlr.v4.gui.TestRig CPP14 translationunit -gui < example.txt

which resulted in the following on my machine:

enter image description here