|Handling Scope in a C Compiler email@example.com (Bart T.) (2002-10-18)|
|Re: Handling Scope in a C Compiler firstname.lastname@example.org (Tina Falkenberg) (2002-10-20)|
|Re: Handling Scope in a C Compiler email@example.com (VBDis) (2002-10-25)|
|From:||"Tina Falkenberg" <firstname.lastname@example.org>|
|Date:||20 Oct 2002 22:51:41 -0400|
|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:
for (i =0; i<99; i++)
int a; ...
The function name is a so I created a new "function" variable with the
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." <email@example.com> 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.
Return to the
Search the comp.compilers archives again.