[antlr-interest] tree parser rule referencing other parts of the tree

Monty Zukowski monty at codetransform.com
Mon May 17 14:36:28 PDT 2004


On May 17, 2004, at 2:07 PM, excel_robot wrote:

> Hi Guys,
> I finished a small example of writing a source to source translator.
> You can find it at
> http://www.wumpa.com/antlr/antlr_example.html
>
Thanks for sharing that!

>
> The T-SQL AST is modified to the PL/SQL AST by ASTPass1.g
> The problem lies in referencing the "INTO" node when in the rule
> which recognizes the SELECT_LIST.
> I could
> 1)pass a reference of the INTO sub tree down to the rule.
>  **but this may pass through several rules in real life.
>  **lots of messy parameters.
>  **might have to pass lots of different trees around.
> 2)use a global variable to hold reference to the INTO tree.
>  **but problems may exist with nested select statements which would
> overwrite my 1 member variable.
> 3)build some type of tree walker utility.
>  **the rule would call a utility to walk back up the tree to get
> my "INTO" node reference.
>  **I like this idea. Are there any utilities to do this?
> 4)create a big rule which encompasses everything I need, including
> the INTO part of the tree.
>  **might have to "turn off" all the rules it encompases in the super
> grammar.
>
> Am I going about this all wrong? Is that how you use the tree? Is
> there a best approach?
>

You might consider using a symbol table--a hash table with scopes.  You 
have to push/pop scopes from your tree grammar.  See my C grammar for 
examples of that.

Also there

Monty Zukowski

ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit -- 
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html



 
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