0
votes

Following this question, I'm trying to learn how to use the TestRig / grun tool. Consider the grammar file in this repo. I ran the below commands :

export CLASSPATH=".:/usr/local/Cellar/antlr/&ltversion&gt/antlr-&ltversion&gt-complete.jar:$CLASSPATH"
antlr &ltgrammarName&gt.g4
javac &ltgrammarName&gt*.java

but when I run

grun <grammarName> <inputFile>

it gets stuck without returning any error messages. I have tested this with other examples as well to no avail. I would appreciate it if you could help me know what is the problem and how I can resolve it.

1

1 Answers

1
votes

the normal grun alias takes the grammarName and startRule as parameters and expects the input from stdin:

grun <grammarName> <startRule> < <inputFile>

example:

grun ElmerSolver sections -tree  < examples/ex001.sif

If you want to run just the Lexer, you can use the "pseudo-startrule" "tokens":

grun ElmerSolver tokens -tokens  < examples/ex001.sif

With your sample, this gives me:

[@0,0:9='Simulation',<'Simulation'>,1:0]
[@1,11:13='End',<'End'>,2:0]
[@2,16:24='Equation ',<'Equation '>,4:0]
[@3,25:25='1',<Integer>,4:9]
[@4,27:29='End',<'End'>,5:0]
[@5,30:29='<EOF>',<EOF>,5:3]

(That's using the grammar changes I made in the previous answer, but should demonstrate the results)