[antlr-interest] Question about factories

Ric Klaren klaren at cs.utwente.nl
Thu Jul 10 02:28:53 PDT 2003


Hi,

On Wed, Jul 09, 2003 at 03:46:53PM -0400, Tiller, Michael (M.M.) wrote:
> Note: I'm using antlr-2.7.2 and C++ code generation...
>  
> I noticed that the initializeASTFactory() method for my generated parser is
> not static.  Why?

Dunno ;) It probably grew that way when I was implementing the stuff. But
you have a point it could probably be static.

> Even better, it would also be possible to generate a derived factory class
> from ASTFactory that just calls the static initializeASTFactory on itself
> in its constructor. This way, I'd just have instantiate the factory type
> specific to my parser (no manual initialization required).

The problem with the factory is that it needs to be the same thing for a
complete lexer/parser/treewalker/rewriter chain. Trying to do all factory
initializations intelligently might prove cumbersome. At the time I
couldn't think of a failproof way of guaranteeing the right initializations
in a complete chain of (tree)parsers (without having to hack too much into
antlr).

Furthermore I wanted it to crash if people tried to see how far they'd get
without reading the release notes/docs. It is very easy to screw up your
project by not initializing the factory correctly. Going on the amount of
mail I got about crashes due to no RTFM I think that was a good decision ;)

Basically I'm still of the opinion that trying to do heterogenous AST's
with ANTLR 2 is not a good idea. At least one should be prepared to run
into vague bugs oversights etc. More than once I've been on the verge of
just ripping it out, (motto: if you can't do it well don't do it).

I'll look at making the thing static and the subclass idea when I have some
more time (next weekish probably).

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  "You can't expect to wield supreme executive power just because some
   watery tot throws a sword at you!"
  --- Monty Python and the Holy Grail


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list