Home | Download | News | Wiki | About ANTLR | Feedback | Support | Bugs


Latest version is 2.7.7.
Download now! »

Download
» Home
» Download
» News
»Using ANTLR
» Documentation
» Wiki
» FAQ
» Articles
» Grammars
» File Sharing
» Code API
» Tech Support
» Bug Tracking
»About ANTLR
» What is ANTLR
» Why use ANTLR
» Showcase
» Testimonials
» Getting Started
» Software License
» ANTLR WebLogs
» ANTLR Workshops
»StringTemplate
»TML
»PCCTS
»Feedback
»Credits
»Contact


Support StringTemplate, ANTLR Project by making a donation! Terence often pays for things like the antlr.org server, conference travel, and this site design (that alone cost US$1000). Buy him a beer and pizza remotely ;)

Search



ANTLR v3

Introduction

April 12, 2007: Latest: ANTLR 3.0 beta 7 source release (includes jars)

ANTLR v3 is a complete rewrite of the ANTLR parser generator and is the culmination of over 15 years of experience building language tools. The software represents nearly four years of frantic coding and research effort. While there are significant enhancements based upon new and exciting research, the tool should feel very familiar to ANTLR v2 users. The ANTLR v3 software license is BSD.

The Definitive ANTLR Reference: Building domain-specific languages
Terence's ANTLR v3 book coming out in Early May, 2007. You can buy the PDF of it now. ANTLR v3 will ship before the book is printed.

The core tool is written by Terence Parr, the maniac behind the previous two versions, with code generation targets written by a variety of other folks (see the target list below). The goal of version 3 was to provide a really clean source base and to significantly clean-up the syntax and semantics of the meta-language. Along the way, some nice new technology was discovered thanks to discussions with the usual suspects: Loring Craymer, Ric Klaren, John Mitchell, Sriram Srinivasan, Monty Zukowski, and many many others from the antlr-interest mailing and the 2004, 2005 workshops. Jean Bovet has also proven an excellent research colleague and developer. His ANTLRWorks development environment rocks!

From the user perspective, they are two primary new features: significantly enhanced parsing strength via LL(*) parsing with arbitrary lookahead and vastly improved tree construction rewrite rules. Here is a look at a simple grammar:


grammar SimpleParser;
program : variable* method+ ;
variable: 'int' ID ('=' expr)? ';' ;
method  : 'method' ID '(' ')'
  '{'
      variable* statement+
  '}'
;
statement
  : ID '=' expr ';'
  | 'return' expr ';'
  ;
expr    : ID | INT ;
ID      : ('a'..'z'|'A'..'Z')+ ;
INT     : '0'..'9'+ ;
WS      : (' '|'\t'|'\n')+ {channel=99;}
;
Note that all literals are single-quoted and can be referenced easily in the parser w/o having to make a token rule. The parser/lexer have been integrated into a single spec, but can also be separate entities. All tokens go to the parser from the lexer, with tokens like whitespace and newlines etc... sent on different "channels". The channel=99 simply indicates that the WS tokens should be sent in a hidden channel to the parser. The tokens are available to actions but are not considered part of the parse.

To get started, please see the ANTLR v3 README file.

Here is an ANTLR v2 to v3 converter (in progress; send me fixes!).

LL(*) Parsing

Natural grammars are sometimes not LL(k) for any fixed k even if the k is usually small; e.g. C function declarations vs definitions. From the left edge, the lookahead is not fixed to see the ';' vs '{' to distinguish the cases:

func : type ID '(' arg* ')' ';'
     | type ID '(' arg* ')' '{' body '}'
     ;
We need arbitrary lookahead because of the arg*. If you have actions at ID, you can't easily refactor. The lookahead will be 5<=k<=10 usually for this decision.

Tree construction rewrite rules

Building trees with v2 for complicated rules was rather challenging and required free-form actions in the target language. In v3, I think you'll find that these rewrite rules cover almost all cases. Here is an example that builds trees for a simple language:

variable
    :   type declarator ';' -> ^(VAR_DEF type declarator)
    ;

functionHeader
    :   type ID '(' ( formalParameter ( ',' formalParameter )* )? ')'
        -> ^(FUNC_HDR type ID formalParameter+)
    ;

atom
    :  ...
    |  '(' expr ')' -> expr
    ;

Status

The latest version is 3.0b7 (April 12, 2007). Expect a full release in about May 2007. Done with the book and am fixing bugs for release.

Here is the list of known ANTLR v3 bugs and feature requests.

Download

ANTLR v3 source repository browsing using FishEye brought to you by Cenqua. You can get up-to-the-second development tarballs here.

ANTLR v2 to v3 converter (in progress; send me fixes!)

ANTLR 3.0 beta 7 source release
ANTLR 3.0 beta 6 source release
ANTLR 3.0 beta 5 source release
ANTLR 3.0 beta 4 source release
ANTLR 3.0 beta 3 source release
ANTLR 3.0 beta 2 source release
ANTLR 3.0 beta 1 source release
ANTLR 3.0 early access 10 source release
ANTLR 3.0 early access 9 source release
ANTLR 3.0 early access 8 source release
ANTLR 3.0 early access 7 source release

Software license

ANTLR v3 uses the BSD software license as opposed to the public domain license for v2. It says, in essence, do what you want with the software, but don't sue me if it wipes out all life on the planet. You must also put the copyright notice in your application's manual if you are using the runtime binaries. Read the license carefully.

Examples

ANTLR v3 sample grammars contains the following examples:

LL-star, cminus, dynamic-scope, fuzzy, hoistedPredicates, island-grammar, java, java-from-v2, python, scopes, simplecTreeParser, treeparser, tweak, xmlLexer.

Also check out Mantra Programming Language for a prototype (work in progress) using v3.

ANTLRWorks development environment

Jean Bovet has a very nice development environment that intreprets grammars, highlights ambiguous paths in syntax diagrams, debugs running parsers, ...

ANTLRWorks Grammar Development Environment for v3

Code generation targets

Check out the wiki: ANTLR v3 code generation targets.

Here is the ANTLR v3 core code generation template interface specification. It gives you an idea of the templates required to build a target for v3.

Documentation, info...

I have little documentation yet other than the examples, my presentations, and my blog entries though reality seems to outpace my ability to document the changes. ;) Please see the change list etc... in the ANTLR v3 README file.

Here is start of the ANTLR v3 documentation.

See the wiki ANTLR v3 FAQ.

ANTLR v3 Overview [ppt]; mp3 (40M and cut off a bit)
LL(*) Parsing Algorithm used by v3 [ppt].
Semantic predicate hoisting [ppt].

Bugs

Submit bugs to the antlr-interest list first for triage. I'll pick it up. Here is the official ANTLR v3 bug management system brought to you by the great folks at Atlassian Blogs

ANTLR v3 lookahead analysis
ANTLR v3 code generation
ANTLR v3 tree construction and parsing
ANTLR v3 lexer/parser integration
ANTLR v3 attributes, actions, rewriting
ANTLR v3 error reporting and recovery