[antlr-interest] Prediction DFA bug?

Markus Stoeger spamhole at gmx.at
Sat Mar 7 09:05:32 PST 2009


Hi,

Andreas seems to have the same problem that I've run into a few months 
ago. I also got FailedPredicateExceptions when I implemented keywords as 
identifiers + disambiguating semantic predicates.

Below are the links to my previous posts concerning these problems from 
december/january. I was able to reproduce the problem with a very simple 
grammar (see attachments containing grammar, dfa graphics).

http://www.antlr.org/pipermail/antlr-interest/2008-December/032188.html
http://www.antlr.org/pipermail/antlr-interest/2009-January/032202.html

Maybe someone with more ANTLR experience could explain why this is 
happening or verify that it's a bug in the generated lookahead DFA?

Regards,
Markus

Gavin Lambert schrieb:
> At 06:16 7/03/2009, Andreas Meyer wrote:
>  >The produced parser had some strange properties, namely, it
>  >was misled into wrong rules, and then complained about
>  >mismatched keywords, ie, while looking for a statement
>  >beginning with keyword_1, it decided to go for the
>  >statement rule beginning with keyword_2, which in turn
>  >raised a PredicateFailedException:
>  >
>  >keyword_2: {is_keyword2()}? IDENTIFIER;
>
> I believe you need to use a gated predicate instead for that to 
> work as you'd expect:
>
> keyword_2: {is_keyword2()}? => IDENTIFIER;
>
>
> But I'm still firmly of the opinion (which seemed to be backed up 
> by the rest of your message) that overusing predicates harms 
> performance, since they need to be re-evaluated quite frequently, 
> whereas regular token lookahead can be very quickly evaluated 
> using bitsets.  (I haven't done testing, though -- this is just a 
> gut feeling.)
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>   



More information about the antlr-interest mailing list