[antlr-interest] Bug in Antlr - confusion on ANTLR grammar syntax???

John MccLain jmcclain at tcshealthcare.com
Thu Dec 9 08:44:43 PST 2004


I am not understanding this at all. I am building a grammar
to parse powerbuilder. Here is all of the parser grammar - I reduced it down
to localize
the confusion

expression: simpleexp ((LE|GE|NE|EQ|LT|GT) simpleexp )?
;

simpleexp:term
;

term: factor
;

factor: NUM
;
and the lexer grammar (k = 4) for NUM is:

NUM: ('0'..'9')+
{System.out.println("2" + getText());}
;

What I dont understand is the ANTLR grammar syntax (I think).
Given an input of "1" (without the quotes), The rule 'simpleexp
((LE|GE|NE|EQ|LT|GT) simpleexp )?'
causes the parser to process then hang inside the parser, and not exit.
However, when I change the rule to
just 'simpleexp', the parser does not hang, and I exit gracefully out of
main. The parser start rule is 'expression'.
My question is - why does 'simpleexp ((LE|GE|NE|EQ|LT|GT) simpleexp )?' not
work? the parenthetic stmt is OPTIONAL - I wouldn't think it should cause a
different behavior than just 'simpleexp'. If I use 'simpleexp | simpleexp
((LE|GE|NE|EQ|LT|GT) simpleexp )?', all is well, but I don't understand why
I should have to do this???

John McClain
Senior Software Engineer
TCS Healthcare
jmcclain at tcshealthcare.com
(530)886-1700x235
"Before you criticize someone, walk a mile in their shoes.
That way, you'll be a mile from them, and you'll have their shoes."



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list