COMP 520: Compilers!
Lecture 9: Identification
1
Announcements + Logistics
2
Identification
3
What is identification?
4
Three scopes in miniJava
5
Defining context in miniJava
How does this work in Java?
6
A perfectly legal Java program
7
Defining context in miniJava
Anything in the 2+ category cannot override anything else in 2+. Other than that, higher scope levels can override lower scope levels.
8
Identifiers
9
Identifiers
10
Contextual analysis: Identification
11
Identifiers make sense in context
12
Forward declarations?
13
Where is a.b.c.x’s declaration?
14
Where is a.b.c.x’s declaration?
15
What about types…
a: a is of type “A”
a.b: b in context of “A”, type is “B”
a.b.c: c in context of “B”, type is “C”
a.b.c.x: x in context of “C”
16
Identification Theory
17
Context Visibility
{“ID c”} x {“CTX B”} → FieldDecl
is unavailable when inside C.fun
18
Context Invisibility
19
Scoped Identification
20
How to determine the definition that applies to a reference?
21
Implementation: Identification
22
Identification Table Implementation Details
23
Scoped Identification Table
Question: When should you open/close a scope?
24
Parameters to the identification process
25
Identification Traversal
26
Example
27
Example
28
Identification Traversal – Method Body
29
Identification Traversal – Method Body
30
Scoped Identification – Stack Visualization
31
Scoped Identification – Stack Visualization
32
Scoped Identification – Stack Visualization
33
Scoped Identification – Stack Visualization
34
Scoped Identification – Stack Visualization
35
Scoped Identification – Stack Visualization
36
Scoped Identification – Stack Visualization
37
Scoped Identification – Stack Visualization
38
Logical order of Contextual analysis / PA3: Option 1
1. Identification:
2. Type checking
39
Logical order of Contextual analysis / PA3: Single Traversal
40