[antlr-interest] syntactic predicates and semantic predicates

Bryan Ewbank ewbank at gmail.com
Wed Aug 24 07:08:46 PDT 2005


I've been doing some profiling (generating C++ code), and come to the
conclusion - no real surprise - that throwing exceptions are very
expensive.

How this works out in ANTLR is that I'm replacing syntactic predicates
with semantic predicates whereever possible:

   // the old code
   ( (LP) => bleah
   | ....


   // the new code
   ( { LA(1) == LP }? bleah
   | ...

This makes a big difference in processing time because it eliminates
the use of exceptions to evaluate the predicate.

Perhaps v3.0 can detect syntactic predicates that don't need exceptions?

Hope this helps others,
- Bryan


More information about the antlr-interest mailing list