[antlr-interest] Re: syntactic predicates and semantic predicates

Terence Parr parrt at cs.usfca.edu
Wed Aug 24 15:32:40 PDT 2005

PCCTS (ANTLR v1) was smart enough to know when the lookahead  
predicate was fixed and it used a non-exception mechanism. :)  Back  
to the future for v3? ;)

On Aug 24, 2005, at 2:36 PM, Bryan Ewbank wrote:

> So, does anyone have a similar syntactic->semantic transform for tree
> parsers?  I'm currently using
>     { _t->getType() == BLEAH }? do_me_now
> to replace the more expensive:
>     ( BLEAH ) => do_me_now
> What's really amusing is that in quite a few cases, the predicate I'm
> adding is a duplicate of generated code...
> On 8/24/05, Bill Canfield <canfield at computer.org> wrote:
>>> From: Bryan Ewbank <ewbank at gmail.com>
>>> 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:
>> That's a good observation.  I had a similar epiphany a few weeks ago,
>> due to TokenStreamSelector::retry().  retry() is just a wrapper  
>> around a
>> throw(), so if you switch streams a lot, you'll want to have  
>> something
>> besides retry() to stitch them all together.
>> Bill

CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com

More information about the antlr-interest mailing list