![Page 1: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/1.jpg)
Semantic Analysis
![Page 2: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/2.jpg)
Find 6 problems with this code.These issues go beyond syntax.
![Page 3: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/3.jpg)
What kinds of questions does the semantic analysis/code generator need to answer?
![Page 4: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/4.jpg)
Semantic Analysis = Values/MeaningContext-Sensitive Analysis
![Page 5: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/5.jpg)
SCOPING: Consider the following code segment in a language with nested function definitions in which all parameters are passed by reference. • int a, b, c, d;• function f(int a, int x)• { int b = 0;• function g()• { int c = 3; • print (“in g:”,a,b,c,d,x);• call h(a,b,c);• print(“in g:”,a,b,c,d,x);• }• { /*in f*/• print(“in f:”,a,b,c,d,x);• call g(); • print(“in f:”,a,b,c,d,x); • a = 6;• }• function h(int x, int y, int z)• { int d = 2;• print(“in h:”,a,b,c,d,x,y,z);• x = 3; y= 4; z = 5;• }• function main()• { a = b = c = d = 99;
• call f(b,c); print(“in main”,a,b,c,d); call h(a,b,c); print(“in main”, a,b,c,d);• }
1. Show the output of this program assuming static scoping.
2. Show the output of this program assuming dynamic scoping.
![Page 6: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/6.jpg)
Exercise: Identifying the Scoping Rules of a PL
Using the Decaf spec,
1. List how new names are introduced
2. List rules for visibility of names
![Page 7: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/7.jpg)
Exercise: Semantic Checks
• Using Decaf handout, identify what semantic checks need to be done by the compiler. Runtime environment?
![Page 8: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/8.jpg)
A Symbol Table Entry
• For each kind of named object, what information is needed to– Perform semantic checks– Generate code efficiently (not have to traverse
AST for the information in faraway places
![Page 9: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/9.jpg)
Symbol Table Operations
What are the key operations to be performed on the symbol table?
![Page 10: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/10.jpg)
Implementing a Symbol Table
• What possible data structures could be used for storing a single scope?
• Exercise: Assigned a given data structure, create arguments to “sell” yours as the one to be used, and arguments to “not buy” the others
![Page 11: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/11.jpg)
A symbol table manager and data structure must implement:
• enter_scope() start a new nested scope• lookup (x) finds current x (or null)
via scoping rules• insert_symbol(x) add a symbol x to the table• local-lookup(x) determines if x in local scope• exit_scope() exit current scope
![Page 12: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/12.jpg)
But, we have to deal with scopes and scoping rules
• Separate table for each procedure (i.e., for each scope)
• At a given point have symbol table for each nesting level current nesting level
• Info is deleted as well as created
![Page 13: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/13.jpg)
Using a Symbol Table
● To process a portion of the program thatcreates a scope (block statements, functioncalls, classes, etc.)
● Enter a new scope.
● Add all variable declarations to the symbol table.
● Process the body of the block/function/class.
● Exit the scope.
● Much of semantic analysis is defined in termsof recursive AST traversals like this.
![Page 14: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/14.jpg)
Search from top of stack
When table not needed, delete the pointer to its symbol table else keep pointers to table - code generation, debugging - - delete only from active
symbol tableP3
1 P2
3 P4
2 P3
*
symboltableP1
symboltableP2
linear list
P3
P2
P1
active
0 P1
Top of stack:
![Page 15: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/15.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
![Page 16: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/16.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;protected int baseInt = 2; Base
}publicBaseInt 1
baseInt 2
![Page 17: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/17.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}}
Base
publicBaseInt 1
baseInt 2
![Page 18: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/18.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}}
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
![Page 19: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/19.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} >
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
![Page 20: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/20.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} >
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
![Page 21: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/21.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} >
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 22: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/22.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} >
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 23: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/23.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 24: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/24.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 25: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/25.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
2
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 26: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/26.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
2
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 27: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/27.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
23
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 28: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/28.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
23
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
![Page 29: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/29.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
23
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
publicBaseInt 6
![Page 30: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/30.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBaseInt);
}} > 4
23
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
publicBaseInt 6
![Page 31: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/31.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBaseInt);
}} > 4
236
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
publicBaseInt 6
![Page 32: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/32.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;
protected int baseInt = 2;}
public class Derived extends Base {public int derivedInt = 3;public int publicBaseInt = 4;
public void doSomething() {System.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
236
Base
publicBaseInt 1
baseInt 2
Derived
derivedInt 3
publicBaseInt 4
doSomething
publicBaseInt 6
![Page 33: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/33.jpg)
Scoping with InheritanceRoot Scope
public class Base {public int publicBaseInt = 1;protect
}
public claspublicpublic
Typically the scope would also
contain the names “Base” and
“Derived,” along with the function
name “doSomething.”
For
simplicity, I've left these out.
Base
publicBaseInt 1
baseInt 2
public vSystem.out.println(publicBaseInt);System.out.println(baseInt);System.out.println(derivedInt);
int publicBaseInt = 6;System.out.println(publicBase
Int);}} > 4
236
Derived
derivedInt 3
publicBaseInt 4
doSomething
publicBaseInt 6
![Page 34: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/34.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
Base
value 1
Derived
value 2
doSomething
value 3
![Page 35: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/35.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
Base
value 1
Derived
value 2
doSomething
value 3
![Page 36: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/36.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 37: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/37.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 38: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/38.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
>
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 39: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/39.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;System.out.println(value);
System.out.println(this.value);System.out.println(super.value);
}}
>
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 40: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/40.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;System.out.println(value);
System.out.println(this.value);System.out.println(super.value);
}}
> 3
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 41: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/41.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.va
lue);}}
> 3
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 42: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/42.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.va
lue);}}
> 32
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 43: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/43.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
> 32
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 44: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/44.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
> 321
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 45: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/45.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {public int value = 2;
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
> 321
Base
value 1
super
this Derived
Locals value 2
doSomething
value 3
![Page 46: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/46.jpg)
Explicit Disambiguation – no valueDeclared in Derived
Root Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 47: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/47.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
>
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 48: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/48.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;System.out.println(value);
System.out.println(this.value);System.out.println(super.value);
}}
>
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 49: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/49.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;System.out.println(value);
System.out.println(this.value);System.out.println(super.value);
}}
> 3
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 50: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/50.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.va
lue);}}
> 3
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 51: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/51.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.va
lue);}}
> 31
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 52: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/52.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
> 31
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 53: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/53.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
> 311
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 54: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/54.jpg)
Explicit DisambiguationRoot Scope
public class Base {public int value = 1;
}
public class Derived extends Base {
public void doSomething() {int value = 3;
System.out.println(value);System.out.println(this.value);System.out.println(super.value);
}}
> 311
Base
value 1
super
this Derived
Locals
doSomething
value 3
![Page 55: Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649ef65503460f94c0991b/html5/thumbnails/55.jpg)
Disambiguating Scopes
● Maintain a second table of pointers intothe scope stack.
● When looking up a value in a specificscope, begin the search from that scope.
● Some languages allow you to jump up toany arbitrary base class (for example,C++).