[antlr-interest] comments on suggestion to reduce tree construction code size

Ric Klaren klaren at cs.utwente.nl
Thu Dec 27 06:09:06 PST 2001


Hi,

On Mon, Dec 24, 2001 at 04:54:45PM -0800, Terence Parr wrote:
> Somebody suggested removing the syn pred gate around tree construction 
> actions.  The rationale is that an invoked rule can build whatever tree 
> it wants during guess mode, because the invoker will ignore the result 
> in the try block.  Later, if pred was successful, it will be re-executed 
> with "actions on" and the return ast will be used.
..snip..
> I just removed the gates on a test version of ANTLR and ran it on the 
> java grammar.  Parsing all of ANTLR code itself without gates is 17sec 
> on my G4 450Mhz OS X box versus the regular 19sec.  Roughly 10% one 
> could say.  Code size is reduced from 5551 lines to 4709 lines of java 
> code for JavaRecognizer.  134388k vs 115163k characters.  In lines of 
> code it's about 17% smaller.  The JavaRecognizer.class file falls from 
> 54092 to 47296 bytes (14% reduction).  I couldn't learn much from the 
> various profiling options on the interpreter to see what the cost in 
> memory allocation was.  Sorry.

Weird numbers. Not what I'd expect, then again it's java =)

I would like to look at this before it might go into C++ mode. My
experience with these kind of guards is that in a non critical loop the
overhead is usually neglectible. Object creation can be very costly in C++.

Also it would depend very much on the grammar and the amount of guessing
occuring. Does this work in the general case?

It also depends on coding style in antlr. If you spread around a lot of
actions which could be bundled in one action block, you'll end up with a
lot of 'guards'.

> So, how do you vote? 

In java mode I'd vote blank (leaving it to the experts), In C++ mode I'd
say no for now untill I do some experimenting.

Cheers,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
     Human beings, who are almost unique in having the ability to learn
   from the experience of others, are also remarkable for their apparent
         disinclination to do so. --- Douglas Adams, Last Chance to See



More information about the antlr-interest mailing list