[antlr-interest] Re: Reparsing a subtree. Or another solution?

lgcraymer lgc at mail1.jpl.nasa.gov
Tue Nov 16 14:11:06 PST 2004



In general, there are three approaches to this type of problem.
1.)  Multiple passes over the full tree--that has the advantage of
clarity, and the navigation overhead is usually minimal.

2.)  Duplicate the subtrees of interest, and have different walkers
(distinguished by actions, not by tree syntax) for the duplicates. 
This may have maintainability advantages.

3.)  For the second pass, walk the tree in an action.  That is:

subTreeTest
    :
    #( a:A B C ) { secondPass(#a); }
    ;

secondPass
    :
    #( A B C )
    ;

These are roughly ordered by increasing speed (although the speed
differential will be small unless the tree being walked is quite large
and the subtrees only a small fraction of the full tree) and
decreasing maintainability.

--Loring

--- In antlr-interest at yahoogroups.com, Joan Pujol <joanpujol at g...> wrote:
> Hello,
> 
> The small question is:
> 
> How can I reparse a subtree when parsing the complete AST using a
treeparser?
> 
> I need this, because, is the best form I have found to solve this
problem.
> 
> I have:
> expression[rvalue]:
> 	procedurecall(expressionlist[BitSet])
>     |IDENT { Code to check if ident is initialized and other checks}
> 	;
> 	
> 	expressionlist[Bitset]: (expression[rvalue])+ //Each rvalue is fixed
> acording a position in the BitSet.
> 	
> 
> The problem is that I have input,output and input/output parameters in
> procedurecalls. For the output parameters I have to mark rvalue as
> false. But the problem is that I can't do it because I can't determine
> wich is the procedure to call until I have parsed the expressionlist
> (Then I can't determine if the parameter is an output one).
> And then I have though that I need to parse one time to get the types
> and another to do the checks. But I want to only parse this part of
> the tree.
> This is the best solution? Or there is something wrong in my design?
> 
> Also I though that I have to add a parameter to expression -->
> expression[rvalue,noerrors]. To set noerrors to true in the first
> pass. To avoid to report the errors twice.
> 
> A lot of thanks in advance,
> -- 
> Joan Jesús Pujol Espinar





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list