[antlr-interest] Definite (but manageable) bug in antlr

Harmon Nine hnine at isis.vanderbilt.edu
Mon Nov 19 14:23:39 PST 2007


Thanks.  3b1 does not have the bug (also found the post from July 3rd,
doh!).

BTW, is it normal to have to decrease the value of k (say from '*' to 2)
when using syntactic predicates in order to get the generated parser to
work correctly?

Thanks again.
-- Harmon

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Terence Parr
> Sent: Monday, November 19, 2007 1:38 PM
> To: antlr-interest Interest
> Subject: Re: [antlr-interest] Definite (but manageable) bug in antlr
> 
> Hi. Looks familiar.  Can you try 3.1beta?
> 
> http://www.antlr.org/download/build/antlr-2007-10-29.14.tar.gz
> 
> Ter
> On Nov 19, 2007, at 8:42 AM, Harmon Nine wrote:
> 
> > Hello.
> >
> > I've found a bug in antlr -- in particular, a necessary set of
> > parentheses is not being generated in the output java code.
> >
> > Suppose you have a grammar that, in part, looks like this.
> >
> > statement
> > : ( reference ASSIGN )=> reference ASSIGN expr
> > | expr
> >       ;
> >
> > reference
> >       : IDENTIFIER ( {X || Y || Z}?=> paren_arglist )
> >       ;
> >
> > expr  : reference
> >       | INTEGER
> >       ;
> >
> > In the generate Java code, the syntactic predicate "( reference
> > ASSIGN )" is tested using a method "synpred1".  Due to lookahead,
> > the syntactic and semantic predicates are combined into a single
> > antecedent in an "if" expression:
> >
> > if ( synpred1() && X || Y || Z ) { ... }
> >
> > Note the problem:  the semantic predicate "X || Y || Z" needs to be
> > enclosed in parentheses for the antecedent to be processed
> > properly, due to the precedence of "&&" over "||".  Antlr currently
> > does not generate these parentheses.
> >
> > A workaround is, of course, to put the parentheses in manually in
> > the semantic predicate:
> >
> > reference
> >       : IDENTIFIER ( { (X || Y || Z) }?=> paren_arglist )
> >
> >
> > NOTE:  antlr WILL generate proper debug code, i.e. when executing
> > antlr with the "-debug" option.  This is because the debug code
> > looks like this:
> >
> > if (  synpred1() && evalPredicate( X || Y || Z )  ) { ... }
> >
> > This, due to the implicit grouping of "X || Y || Z" as an argument
> > of the method call "evalPredicate," evaluates the antecedent
properly.
> >
> >
> > Cheers
> > -- Harmon
> >



More information about the antlr-interest mailing list