[antlr-interest] Re: Summary of ANTLR Issues

lgcraymer lgc at mail1.jpl.nasa.gov
Wed Jul 9 11:05:45 PDT 2003

Actually, immediate invocation of an AST method is something that 
ANTLR 3 probably won't support--we are likely to change the way ASTs 
are constructed to optimize away the problem of excessive AST node 
allocation (creating a node and then never using it).  The idea is 
that ANTLR would construct a list of AST operations (node creation, 
add sibling, make root) and then apply them at the end of a rule.  You 
would have to have "MyMethod" called by the constructor.


--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> wrote:
> Hi,
> On Tue, Jul 08, 2003 at 04:04:06PM -0400, Tiller, Michael (M.M.) 
> -----snip---
> tokens {
> 	BLOCK<AST=My_AST>; // imaginary token
> }
> block
> 	:	LCURLY! ( statement )* RCURLY!
> 		// add imaginary BLOCK node on top of statement list
> 		{
>             #block = #([BLOCK, "BLOCK"], #block);
>             // I told ANTLR that a BLOCK had type "MyAST" so
>             // I should be able to do this:
>             #block->MyMethod();
>         }
> 	;
> ----snip----
> There is one issue with the block rule, which cannot be fixed easily 
> require a 2nd pass over the action blocks in a rule). ANTLR has no 
way of
> knowing that you will use the block rules return AST with a custom 
> type. This is why the MyMethod call will fail. The return AST types 
> hardcoded to or the default RefAST or the default custom AST for the
> parser. A work around could be (but you probably found it already):
> { RefMyAST b = #([BLOCK, "BLOCK"]); ## = #( b, #block ); 
b->MyMethod(); }
> Under the hood #([BLOCK,"BLOCK"]) seems to generate the right AST 
type, so
> that's good.
> Then there's the issue with the initializeFactory which is a bit 
> and does not make me happy because it is in a piece of the code that 
is a
> horrible hack already. I'm thinking about a different solution 
> cleaner.
> >   You mention above that you think this is a bug if it isn't
> >   supported.
> I was more refering to the ##->MyMethod() in that case (or whatever 
you had
> as example there. Not the rule<AST=MyAST> that's of course not 
> Though I was incorrect in that the ##->somemethod would function in 
> case. I guess I was still in a (homogeneous) custom AST type thought 
> To summarize. 
> This particular use of ##->somemethod on the return AST of a rule is 
> guess something for ANTLR 3, or I have to rearchitect a number of 
things in
> the codegenerator setup (which also forces me to touch java and C# 
> I'm afraid you have to do with the workaround here for now :(
> The missing factory init I'll fix in the next snapshot.
> Cheers,
> Ric
> --
>     ---- Ric Klaren ----- j.klaren at u... ----- +31 53 4893722  ----
>   Quidquid latine dictum sit, altum viditur.
>                  (Whatever is said in Latin sounds profound.)


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

More information about the antlr-interest mailing list