Go to file
Sam Harwell 4d3da87119 Ant build.xml: Move mkdir task to antlr3 target, where the grammars are actually compiled 2013-01-06 15:28:13 -06:00
antlr4-maven-plugin Rename master artifact to antlr4-master 2012-12-04 12:57:56 -06:00
runtime/Java Clarify number of allowed transitions leaving a state 2013-01-05 14:34:16 -06:00
tool Maven build: reference jUnit 4.10, ANTLR 3.5 final, ST 4.0.7 final 2013-01-05 06:08:12 -06:00
.gitignore Ant build.xml: allow user settings in user.build.properties 2013-01-06 15:28:07 -06:00
CHANGES.txt Update CHANGES.txt 2013-01-02 13:58:42 -06:00
LICENSE.txt update README, date on license. 2013-01-01 13:43:15 -08:00
README.txt update README, date on license. 2013-01-01 13:43:15 -08:00
build.xml Ant build.xml: Move mkdir task to antlr3 target, where the grammars are actually compiled 2013-01-06 15:28:13 -06:00
contributors.txt Signed CLA 2012-11-23 10:55:21 -08:00
pom.xml Maven builds: if mvn is not run with -Psonatype-oss-release, then 1) javadocs are not generated, 2) source jar is not generated, 3) artifacts are not signed, 4) shaded (complete) jar is not generated. Development cycle install ~4:1 faster, clean+install ~2:1 faster 2013-01-05 05:40:11 -06:00

README.txt

ANTLR v4 release candidate 1

Terence Parr, parrt at cs usfca edu
ANTLR project lead and supreme dictator for life
University of San Francisco

INTRODUCTION

Hi and welcome to the Honey Badger 4.0 release of ANTLR!

INSTALLATION

UNIX

0. Install Java (version 1.6 or higher)

1. Download

   $ cd /usr/local/lib
   $ curl -O http://www.antlr4.org/download/antlr-4.0-rc-1-complete.jar

   Or just download in browser using URL:

       http://www.antlr4.org/download/antlr-4.0-rc-1-complete.jar

   and put it somewhere rational like /usr/local/lib.

2. Add antlr-4.0-rc-1-complete.jar to your CLASSPATH:

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

   Is also a good idea to put this in your .bash_profile or whatever your
   startup script is.

3. Create aliases for the ANTLR Tool, and TestRig.

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

WINDOWS (Thanks to Graham Wideman)

0. Install Java (version 1.6 or higher)

1. Download http://antlr.org/download/antlr-4.0-rc-1-complete.jar
   Save to your directory for 3rd party Java libraries, say C:\Javalib

2. Add antlr-4.0-rc-1-complete.jar to CLASSPATH, either:

 * Permanently: Using System Properties dialog > Environment variables >
   Create or append to CLASSPATH variable

 * Temporarily, at command line:
   SET CLASSPATH=C:\Javalib\antlr-4.0-rc-1-complete.jar;%CLASSPATH%

3. Create short convenient commands for the ANTLR Tool, and TestRig,
   using batch files or doskey commands:

 * Batch files (in directory in system PATH)

   antlr4.bat: java org.antlr.v4.Tool %*
   run.bat:   java org.antlr.v4.runtime.misc.TestRig %*

 * Or, use doskey commands:

   doskey antlr4=java org.antlr.v4.Tool $*
   doskey grun  =java org.antlr.v4.runtime.misc.TestRig $*

TESTING INSTALLATION

Either launch org.antlr.v4.Tool directly:

$ java org.antlr.v4.Tool
ANTLR Parser Generator Version 4.0
    -o ___              specify output directory where all output is generated
    -lib ___            specify location of .tokens files
...

or use -jar option on java:

$ java -jar /usr/local/lib/antlr-4.0-rc-1-complete.jar
ANTLR Parser Generator Version 4.0
    -o ___              specify output directory where all output is generated
    -lib ___            specify location of .tokens files
...


EXAMPLE

In a temporary directory, put the following grammar inside file Hello.g4:

// Define a grammar called Hello
// match keyword hello followed by an identifier
// match lower-case identifiers
grammar Hello;
r : 'hello' ID ;
ID : [a-z]+ ;
WS : [ \t\n]+ -> skip ; // skip spaces, tabs, newlines

Then run ANTLR the tool on it:

$ cd /tmp
$ antlr4 Hello.g4
$ javac Hello*.java

Now test it:

$ grun Hello r -tree
hello parrt
^D
(r hello parrt)

(That ^D means EOF on unix; it's ^Z in Windows.) The -tree option prints
the parse tree in LISP notation.

BOOK SOURCE CODE

http://pragprog.com/titles/tpantlr2/source_code