|
Authored by: Nivag on Saturday, April 21 2012 @ 10:32 PM EDT |
You actually only need one pass through!
You first construct a symbol table. If you come across a definition you put in
an entry and link to the definition. If you come across a use of a function
first, then you create an empty entry and link the function use to that entry.
When you have parsed all the relevant source code available, you check that all
the entries have been completed appropriately. You can have a tree structure of
symbol tables to allow for the effects of scope rules.
There are variants, and the above is only an outline, so implementation details
would flesh it out. Such as interpretation versus compilations.
Multiple passes are an implementation detail, they are not intrinsically
required.
The above is vaguely related to what I remember about the B6700 Algol 68
compiler, coupled with my own current project that resembles a compiler in some
features.
[ Reply to This | Parent | # ]
|
|
|
|
|