Re: Handling Scope in a C Compiler

"Tina Falkenberg" <>
20 Oct 2002 22:51:41 -0400

          From comp.compilers

Related articles
Handling Scope in a C Compiler (Bart T.) (2002-10-18)
Re: Handling Scope in a C Compiler (Tina Falkenberg) (2002-10-20)
Re: Handling Scope in a C Compiler (VBDis) (2002-10-25)
| List of all articles for this month |

From: "Tina Falkenberg" <>
Newsgroups: comp.compilers
Date: 20 Oct 2002 22:51:41 -0400
Organization: AT&T Worldnet
References: 02-10-075
Keywords: C, symbols
Posted-Date: 20 Oct 2002 22:51:41 EDT

when I had the scope problem in my Compiler, I did the following:
I defined a list of used variables the list had several entries, one was the
name of the variable, the other
was the scope. Now the compiler could run through the code and each time
when it found a new variable
definition assign the scope to the variable.
Let me give an example:

int a()
    int a;
    for (i =0; i<99; i++)
            int a; ...

The function name is a so I created a new "function" variable with the
actual scope:

name: a scope : something

The parser now enters the function a, so the scope will be set to
something_a, just attaching the actual function
name to the actual scope.

Next step, the parser finds int a and the list entry is:
name a: scope: something_a

the for loop is an other scope, since there might be a second for loop, just
add a number to the for scope for example: something_a_for1

So the next variable a is

name: a ; scope : something_a_for1


"Bart T." <> wrote in message
> I'm writing a compiler for a subset of the C89 language (I'm not sure
> how limited this subset will be just yet -- but I'll probably just
> omit floating point support) and was wondering how variable scope
> could be handled.

Post a followup to this message

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