CS453 Intro and PA1 1CS453 Lecture Symbol Table 1Plan for TodaySymbol Table Uses– “pass info from declarations to uses”Scope– environments– static versus dynamic scope– scope examples– scoping for MiniJava Symbol Table Implementation– info maintained and basic operation– how type information is represented with SymTable and Type data structuresCS453 Lecture Symbol Table 2Scope Terms– environment– scope Example scopes– global scope– file scope– named space– package– unnamed scopes Scoping in MiniJavaCS453 Lecture Symbol Table 3Static 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 4SymTable and STE classes SymTable interface (DO NOT change the outputDot methods)– void insertAndPushScope(NamedScopeSTE ste)– void pushScope(String name)– void popScope()– STE lookup(String sym)– void insert(STE ste)– int outputDot(java.io.PrintStream out, int nodeCount)CS453 Intro and PA1 2CS453 Lecture Symbol Table 5Example 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 6Using the SymTable
View Full Document