[antlr-interest] Multiple pass tree walking Q

Hill, Robert rhill03 at eds.com
Wed Oct 4 01:59:11 PDT 2006


Yay - a Reply! I was thinking my mails weren't getting through for a
minute there ;)

Hmm, I considered this originally, but I think I only need 3 passes, so
while it's a big hassle, using grammars has take out a huge wodge of
time in getting it up and running , whereas I feel that walking the
tree's manually would probably have taken a fair bit longer. With 8
passes , unless there's another way to skip branches in the tree, then I
think you definitely made the right choice. I think 3 passes with a
grammar isn't all that bad, 4 passes is definitely borderline.

Ahhh mid-email ah-ha moment!.... maybe.. I think I've got it. Grammar
inheritance. (that is if it's working in 3.0b4.) maintain a base class
tree grammar, and then override the relevant branches for each pass. -
unless your parser grammar changes a branch you've overridden, you'll
only have the base class to implement the standard walk in. 
Yeah, I think that should do it.... Off to give it a go now. 

Cheers for the input anyway Paul!

Rob



--
Rob Hill
EDS - Hallamshire Business Park
F1E/045
Sheffield	
T:	+44 (0) 114 291 1928
M:	+44 (0) 791 732 1227
E:	rhill03 at eds.com

 

>-----Original Message-----
>From: Paul Johnson [mailto:gt54-antlr at cyconix.com] 
>Sent: 04 October 2006 09:13
>To: Hill, Robert
>Cc: ANTLR Interest
>Subject: Re: [antlr-interest] Multiple pass tree walking Q
>
>Hill, Robert wrote:
>> I've pretty much gone down the multiple tree parser routes, 
>its a real 
>> pain in the ass though, as if you modify your parser, you 
>then have to 
>> modify all the tree parser grammars too. I must be missing something 
>> here. :( there must be a rule that ignores a whole branch, but I've 
>> tried all sorts and haven't succeeded ,
>>  
>> ignoreme : ^(.*) ... if only :)
>>  
>> which is why i ended up with 3 tree parse phases. I just get this 
>> nagging feeling im missing the point.
>
>You won't like this reply, but this is why I don't use tree grammars. 
>I've got 8 passes, each of which needs to modify the AST. I 
>manually parse the tree, and cut out branches when I've 
>finished with them (or replace nodes, or whatever).
>
>The recursive tree parse in each pass is (almost) trivial, so 
>a grammar would buy me little. I do have occasional 
>complications with having to find my context in the tree, 
>parsing node lists right-to-left instead of left-to-right, and 
>so on, but no major problems, and certainly nothing that would 
>justify maintaining 8 different grammars. One major advantage 
>is that I can trivially add extra passes that do almost 
>nothing, except maybe some cleaning up for the next pass.
>
>Disclaimer: I've never actually tried the tree grammar route, 
>so I (too) may have missed easy ways to do what I'm now doing manually.
>
>There's a lot on this in the archives - have a look. You could 
>start with Andy Tripp's reply in the "How much use is ANTLR 
>for manipulating ASTs?" thread (18/06/2005).
>
>Paul
>


More information about the antlr-interest mailing list