O'Reilly logo

The Definitive ANTLR 4 Reference, 2nd Edition by Terence Parr

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Grammar Lexicon

The lexicon of ANTLR is familiar to most programmers because it follows the syntax of C and its derivatives with some extensions for grammatical descriptions.

Comments

There are single-line, multiline, and Javadoc-style comments.

 
/** This grammar is an example illustrating the three kinds
 
* of comments.
 
*/
 
grammar​ T;
 
 
/* a multi-line
 
comment
 
*/
 
 
/** This rule matches a declarator for my language */
 
decl : ID ; ​// match a variable name

The Javadoc comments are sent to the parser and are not ignored. These are allowed only at the start of the grammar and any rule.

Identifiers

Token names always start with a capital letter and so do lexer rules as defined by Java’s Character.isUpperCase method. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required