|
Home |
Download |
News |
Wiki |
About ANTLR |
Feedback |
Support |
Bugs
|
|
|
Latest version is 2.7.7. Download now! » |
|
|
ANTLR v3 IntroductionApril 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 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(*) ParsingNatural 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 rulesBuilding 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
;
StatusThe 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. DownloadANTLR 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 Software licenseANTLR 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.ExamplesANTLR 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 environmentJean 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 targetsCheck 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)
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
|
|||||||||||||||||||||||||||||||||||||||||||||||||