[antlr-interest] token precedence (and an ANTLRworks question)
davyd at fugro-fsi.com.au
Mon Nov 17 00:54:11 PST 2008
I am having what looks like a problem with rule precedence.
I have lexer rules that look as following:
: CHAR (CHAR | DIGIT)*
: '\n' // Line feed
| '\r' // Carriage return
| '\u2028' // Line separator
| '\u2029' // Paragraph separator
: 'A' .. 'Z'
| 'a' .. 'z'
: '0' .. '9'
I'm trying to use it to parse the following text ('**' and '/' appear in
the parser rules):
Into a token stream:
But instead what I'm ending up with is:
This suggests to me that it's wrong of me to assume that the first rule
will be matched first. I can't find much discussion of precedence rules
in the ANTLR book.
Also, the ANTLRworks debugger can show you the token stream with little
red boxes around each token, but I can't seem to work out how to find
out the token type for that token, is there something I'm missing here?
Thanks in advance,
Davyd Madeley Software Engineer
Fugro Seismic Imaging, Perth Australia
More information about the antlr-interest