Re: How to handle qualified identifiers such as x.y in a Pascal-like language

noitalmost <noitalmost@cox.net>
Thu, 23 Jun 2011 12:43:27 -0400

          From comp.compilers

Related articles
How to handle qualified identifiers such as x.y in a Pascal-like langu noitalmost@cox.net (noitalmost) (2011-06-20)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l torbenm@diku.dk (2011-06-22)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l DrDiettrich1@aol.com (Hans-Peter Diettrich) (2011-06-22)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l gene.ressler@gmail.com (Gene) (2011-06-22)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l noitalmost@cox.net (noitalmost) (2011-06-23)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l DrDiettrich1@aol.com (Hans-Peter Diettrich) (2011-06-24)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l uu3kw29sb7@snkmail.com (\[Linux Magazine\]) (2011-06-24)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l gneuner2@comcast.net (George Neuner) (2011-06-24)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l gene.ressler@gmail.com (Gene) (2011-06-24)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l DrDiettrich1@aol.com (Hans-Peter Diettrich) (2011-06-25)
Re: How to handle qualified identifiers such as x.y in a Pascal-like l gneuner2@comcast.net (George Neuner) (2011-06-25)
[10 later articles]
| List of all articles for this month |

From: noitalmost <noitalmost@cox.net>
Newsgroups: comp.compilers
Date: Thu, 23 Jun 2011 12:43:27 -0400
Organization: Compilers Central
References: 11-06-037
Keywords: storage, code
Posted-Date: 23 Jun 2011 20:36:15 EDT

On Monday, June 20, 2011 03:43:24 pm John wrote:
>> Is this a reasonable way to approach the problem?
> [Pretty much. The standard way to handle references to an enclosing
> scope is with a display, the calling procedure passes the enclosing
> stack frame addresses as hidden parameters. If your language doesn't
> allow variable sized declarations or recursion, P.x will be at a fixed
> distance below the current stack frame so you can address it directly,
> but in a more general case, you need the display. See any 1970s
> compiler text for details. -John]


My language does allow recursion, so my approach won't work as
written. So the AST node for an Ident should have a field for
enclosing scope levels, not stack levels?


I looked at Aho's description of displays. Currently, my interpreter
is using a more abstract stack. It's a stack of pointers, so the first
declared variable in a scope goes at frame offset 0, the second at
offset 1, etc. I was thinking of dedicating offset 0 to be a pointer
to all the bookkeeping info, such as enclosing scope pointers. Will
this work as my language matures, or are there some glaring gotchas?
[You more or less need a static place to pick up a pointer to the
stack frame for the current invocation of each lexically enclosing
routine. I don't see any reason that pointer to the display in a fixed
place wouldn't work. It's covered in detail in any compiler text
written when people still worried about compiling Pascal. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.