|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:||"Bart T." <firstname.lastname@example.org>|
|Date:||18 Oct 2002 23:45:18 -0400|
|Posted-Date:||18 Oct 2002 23:45:18 EDT|
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.
Holub ("Compiler Design in C") shows an interesting way of doing it
with the symbol manager by creating a new scope level each time a
block is entered and deleting all variables of that scope when the
block is done.
As far as I can tell, this method only works if the compiler is
working with 1 block at a time (parses 1 block, generates the code for
1 block, repeat.) Is there a better way of doing it which would allow
me to parse everything in 1 big phase, then pass control to the
optimizer and finally to the back end?
This is my first compiler project, so I still don't have a full and
clear picture of how everything will work. I was planning on
separating the compiler into 3 parts: front end, optimizer, and back
end. Each of these parts would do all of its work before moving on to
the next. Perhaps there would be a 4th part, an intermediate code
generator which would do its work right before the optimizer. The
front end would pass an AST to the I-code generator, the generator
would pass the intermediate code to the optimizer, etc.
Is this the approach I should be taking? How can scope be handled?
Thanks in advance. Sending copies of replies to email@example.com would
be very much welcome :)
Return to the
Search the comp.compilers archives again.