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 ...
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.