small medium large xlarge

08 Nov 2012, 14:42
Mads Nielsen (1 post)

I’m quite eager to get started on this topic. However, I’m a bit confused regarding version 3 vs 4. I can’t find any information about version 4 on When is there a chance this will be released?

I surely want to be able to experiment as I learn, so a book on a yet unreleased version is not too useful.

On the other hand, there is no point in learning stuff about version 3 that has been made irrelevant by version 4.

So, what should I really do in this case?

11 Nov 2012, 10:54
Bernard Kaiflin (14 posts)

As per November 10th 2012, v4 beta 3 is available. You can download antlr-4.0b3-complete.jar here :

or, at least on OS X, the installation is very easy :

1) download

$ cd /usr/local/lib
$ curl -O --silent

The book says : On UNIX, /usr/local/lib is a good directory to store jars like ANTLR’s. On Windows, there doesn’t seem to be a standard directory so you can simply store it in our project directory.

2) define the CLASSPATH environment variable

$ export CLASSPATH=".:/usr/local/lib/antlr-4.0b3-complete.jar:$CLASSPATH"

3) check the installation

$ java -jar /usr/local/lib/antlr-4.0b3-complete.jar


$ java org.antlr.v4.Tool

You should see :

ANTLR Parser Generator Version 4.0b3 …

4) define aliases

$ alias antlr4='java -jar /usr/local/lib/antlr-4.0b3-complete.jar'
$ alias grun='java org.antlr.v4.runtime.misc.TestRig'

5) write a grammar, file extension .g4 (this is code/install/Hello.g4 from the book’s code)

grammar Hello;
r : 'hello' ID ;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;

6) “compile” the grammar

$ cd /tmp/test or your directory
$ antlr4 Hello.g4

7) compile the generated lexer and parser

$ javac *.java

8) execute

$ grun Hello r -tokens
➾ hello <your name>
➾ EOF # type ctrl-D on UNIX or ctrl-Z on Windows

You should see :

[@1,6:10='<your name>',<4>,1:6]

HTH Bernard

10 Nov 2012, 21:07
Terence Parr (52 posts)

4.0 will be out certainly by Christmas.

You must be logged in to comment