[antlr-interest] AST, value manipulation.

Bharath Sundararaman bharath.sundararaman at starthis.com
Wed Nov 17 09:32:49 PST 2004


Hi Antlers,

I generated an AST from my parser and I am extending TreeParser to
perform type checking. How are the values of the variables
stored/retrieved? For example, let's say I have a declaration of the
form:

VAR
v: INT := 2;
a: ARRAY[1..10] OF INT;
END_VAR

And I have a statement 

a[v] := 200;

In my type checking code, I can ensure that the type of variable "v" is
INT, because I store the (name,type) of variable "v" in the symbol
table. But, I also want to check if index "v" is within bounds, which
means I need to retrieve the value of "v" and make sure it does not
exceed the range 1..10 

How is the value of "v" stored? Should I store it in the symbol table or
should I fetch it from the AST node, where it was originally declared? 

Thanks!

Bharath.

-----Original Message-----
From: Terence Parr [mailto:parrt at cs.usfca.edu] 
Sent: Wednesday, November 17, 2004 11:37 AM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] tree parsers and stacks



On Nov 15, 2004, at 12:24 PM, John Allen Green wrote:
> I haven't looked into the source, but is there an option in the tree
> parser generator so that the resulting parser keeps a stack of the
head
> nodes, as the tree is descended? That would allow you to climb up the
> tree at any point within the tree parser, to find the enclosing
> expression, statement, function, etc. It might save you from some of
> the effort of writing actions in the grammar manually, for keeping
> stacks for scopes and whatnot.
>
> I'm using the tree parser for analysis, but not transforms, so I just
> use an AST with additional "back" and "up" links. So... I don't really
> need it, I'm just curious.  :)

Hi John,

You could add the UP pointer yourself in a subclass and then change the 
ast factory to set the up pointer maybe.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!





 
Yahoo! Groups Links



 





 
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