[antlr-interest] Why doesn't this work?
Cameron Esfahani
dirty at apple.com
Wed Jun 6 20:23:53 PDT 2007
I've spent a few hours trying to figure out why this test grammar
doesn't work. If I use ANTLRWorks to debug it, starting at rule
"number_size", with an input of 100.UW, I end up getting a
NoViableAltException error.
If I remove the IDENTIFIER rule, it seems to work.
And, if I add a space to the input (100.U W), then it seems to work
as well. Obviously I don't want that to work, 100.U W shouldn't be
legal. Why is it allowing it?
I can't wrap my head around it, but it seems like the UW portion of
the input isn't matching to size_qualifier, it's matching to
IDENTIFIER? That can't be right, as IDENTIFIER doesn't contain a
period character.
grammar Test;
options {
output = AST;
ASTLabelType = CommonTree;
}
tokens {
SIZE_DEFAULT;
SIZE_8;
SIZE_16;
SIZE_32;
SIZE_64;
}
size_qualifier
: '.' ('U')? ('B') -> SIZE_8
| '.' ('U')? ('W') -> SIZE_16
| '.' ('U')? ('L') -> SIZE_32
| '.' ('U')? ('Q') -> SIZE_64
;
number_size
: NUMBER size_qualifier -> size_qualifier NUMBER
| NUMBER -> SIZE_DEFAULT NUMBER
;
NUMBER
: '-'? ( '0' | '1'..'9' '0'..'9'*)
;
fragment LETTER
: 'a'..'z'
| 'A'..'Z'
;
IDENTIFIER
: LETTER ( LETTER | '-' | '_' | '0'..'9' )*
;
Cameron Esfahani
dirty at apple.com
"In the elder days of Art, Builders wrought with greatest care each
minute and unseen part; For the gods see everywhere."
"The Builders", H. W. Longfellow
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070606/32c3b3d0/attachment.html
More information about the antlr-interest
mailing list