Download presentation
Presentation is loading. Please wait.
Published byDaryl Currington Modified over 10 years ago
1
1 Symbol Tables
2
2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice Grammars and Parsing Grammars and Parsing LL(1) Parsing LL(1) Parsing Lex and yacc Lex and yacc LR Parsing LR Parsing Semantic Processing Semantic Processing Symbol Tables Symbol Tables Run-time Storage Organization Run-time Storage Organization Code Generation and Local Code Optimization Code Generation and Local Code Optimization Global Optimization Global Optimization
3
3 A Symbol Table Interface
4
4
5
5 A Symbol Table Interface (contd.)
6
6
7
7 Basic Implementation Techniques Unordered List Unordered List Ordered List Ordered List Binary Search Trees Binary Search Trees The expected search time is O(log(n)) The expected search time is O(log(n)) For a balanced tree, the worst-case performance is O(n). For a balanced tree, the worst-case performance is O(n).
8
8 Basic Implementation Techniques (contd.) Hash Tables Hash Tables Hash function Hash function Resolving collisions Resolving collisions Linear Linear If position h(n) is occupied, try (h(n)+1) mod m If position h(n) is occupied, try (h(n)+1) mod m Add-the-hash rehash Add-the-hash rehash If position h(n) is occupied, try (2*h(n)) mod m If position h(n) is occupied, try (2*h(n)) mod m Quadratic rehash Quadratic rehash If position h(n) is occupied, try (h(n)+1**2) mod m If position h(n) is occupied, try (h(n)+1**2) mod m Collision resolution by chaining Collision resolution by chaining
9
9 Basic Implementation Techniques (contd.) String Space Arrays String Space Arrays A fixed-size array A fixed-size array
10
10 Basic Implementation Techniques (contd.) Segmented String Space Arrays Segmented String Space Arrays A dynamic-allocation array A dynamic-allocation array
11
11 Block-Structured Symbol Tables Block structured languages Block structured languages
12
12 Block-Structured Symbol Tables (contd.) Visibility rules Visibility rules
13
13 Block-Structured Symbol Tables (contd.) An Individual Table for Each Scope An Individual Table for Each Scope
14
14 Block-Structured Symbol Tables (contd.)
15
15 Block-Structured Symbol Tables (contd.)
16
16 Block-Structured Symbol Tables (contd.)
17
17
18
18
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.