-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesign.txt
10 lines (7 loc) · 1.07 KB
/
design.txt
1
2
3
4
5
6
7
8
9
10
Milestone 5
Scope and Variables
The basic idea of the implementation I will be using is defining nodes in the parse tree to be "scope edges". Scope edge nodes will contain the definitions of the variables local to that scope and those definitions will simply be the following:
Pretranslation identifier spelling (ie variable name)
Posttranslation identifier spelling (ie globally unique variable name for use in gforth)
Type
These three pieces of information along with the implicit variable scope stack produced by associating scopes with nodes in the tree are all we need to implement block scope variables. When a variable is declared, an entry is added to the variable table in the first scope edge node above the let statement. When a variable is referenced, we ask the forst scope edge node above the reference for the posttranslation name or type, depending upon what we are looking for. If a scope edge node does not have an entry for the requested variable, it asks the scope edge above itself, all the way up until an entry is found or the topmost node reports there is no entry.