[antlr-interest] beta6, alternation produces non compiling code.
Jim Idle
jimi at intersystems.com
Tue Feb 27 21:11:29 PST 2007
Clinton,
I will let Ter comment as to whether this SHOULD work, but intuitively
(at least to me ;-), you are trying to do to much in the parser. Of
course, this could be just a simplified example you are using to show
the issue. But, if not the:
Grammar list;
list : ELEM (COMMA ELEM)* ;
COMMA : ',' ;
ELEM : 'a'..'z' | 'A'..'Z' ;
(There isn't any need to create COMMA really, it is just my own force of
habit).
Jim
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Clinton Roy
Sent: Tuesday, February 27, 2007 5:11 PM
To: ANTLR List
Subject: [antlr-interest] beta6, alternation produces non compiling
code.
Hi guys,
I'm sure someone has come across this before, but I couldn't spot
anything.
list.g:
------
grammar list;
list : elem (',' elem)* ;
elem : 'a'..'z'|'A'..'Z' ;
------
generates this for elem:
------
public void elem() throws RecognitionException {
try {
// list.g:3:6: ( ('a'..'z'|'A'..'Z'))
// list.g:3:8: ('a'..'z'|'A'..'Z')
{
if ( ) {
input.consume();
errorRecovery=false;
}
------
In debugging mode the empty if predicate is actually an
<empty-set-expr>. I can seemingly work around this problem with some
redundant bracketing around one of the alternatives.
I feel like I must be doing something silly :)
--
Clinton Roy
www.acqao.org - ARC Centre of Excellence for Quantum-Atom Optics
www.humbug.org.au - Brisbane Unix Group
azure.humbug.org.au/~croy/blog - Blog
www.flickr.com/photos/croy/ - Photos
More information about the antlr-interest
mailing list