[antlr-interest] Antlr syntax reference
Steven D. Vormwald
sdvormwa at mtu.edu
Tue Jun 24 11:46:07 PDT 2008
Sam Kuper wrote:
> Dear all,
>
> I am looking for an exhaustive guide to Antlr 3.0.1 syntax (I am using
> AntlrWorks 1.1.7); I'll explain why. My grammar so far looks like this:
>
> grammar DCP;
> options {
> language=Python;
> }
> dcp : DOCUMENT* EOF;
> DOCUMENT : HEADERS;
> HEADERS : YEAR_HEADER MONTH_HEADER ;
> YEAR_HEADER : '*Y 18\n';
> MONTH_HEADER : '*M October\n';
>
> Notice that in this grammar, I have used \n to denote new lines. But
> although I have not declared what \n is, Antlr's lexical analyser
> recognises that it denotes a newline; in other words, \n is a
> pre-defined token in Antlr grammar. I'm guessing there are others, and
> I want to be conscious of them as I work, but I have so far been
> unable to find a document that lists all the pre-defined tokens in
> Antlr's grammar. Presumably one exists somewhere. If you know where,
> please could you tell me?
>
> Many thanks,
>
> Sam
I could be wrong about this, but I believe ANTLR recognizes the same
character escapes in strings that java does:
'\n' is newline
'\r' is carriage return
'\t' is tab
'\uXXXX' is the unicode character at codepoint XXXX (in hex)
'\\' is backslash
and so on. From http://www.antlr.org/wiki/display/ANTLR3/Grammars
(Lexer Rules section), you can see examples of the '\t' and '\uXXXX'
being used. I don't think this is a rule, as much as a convention for
inserting "special" characters in strings.
Steven Vormwald
More information about the antlr-interest
mailing list