CS453 Intro and PA1 1CS453 Lecture Symbol Table 1Plan for Today Attributes– Inherited– Synthesized Calculating line and position for each AST node Scope– environments– static versus dynamic scope– scope examples– scoping for MiniJava Symbol Table– info maintained and basic operation– the SymTable class you will be implementingCS453 Lecture Symbol Table 2Calculating Lines and PositionsCS453 Lecture Symbol Table 3Example of calculating lines and positionsCS453 Lecture Symbol Table 4Scope Terms– environment– scope– visibility Example scopes– global scope– file scope– named space– package– unnamed scopes Scoping in MiniJavaCS453 Intro and PA1 2CS453 Lecture Symbol Table 5Static versus Dynamic Scope Static Scope– also called lexical scope because can determine scoping by analyzing theprogram– each use of a variable is bound to a location statically Dynamic Scope– each use of a variable is bound to the most recently visible defined valuefor that same variable nameint x = 0;int f () { return x; }int g () { int x = 1; return f(); }CS453 Lecture Symbol Table 6SymTable and STE classes SymTable interface (DO NOT change the SymTable members or interface)– SymTable pushClassScope(String classname)– SymTable pushMethodScope(String methodname)– SymTable popScope()– STE lookup(String sym)– void insert(STE ste)– int outputDot(java.io.PrintStream out, int nodeCount)CS453 Lecture Symbol Table 7Example SymTable dot outputclass VarError1{ public static void main(String[] a){ System.out.println(1); } }class Class1 { public int foo() { if (a) {} else {} return 0; }}CS453 Lecture Symbol Table 8Using the SymTable
View Full Document