Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives:...

9
Chapter 3: Symbol T able 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol Table Hash Functions & Types of Hash Functions Dr. Mohsen Chitsaz

Transcript of Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives:...

Page 1: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 1

Compiler Designs and Constructions

Chapter 3: Symbol Table

Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol Table Hash Functions & Types of Hash Functions

Dr. Mohsen Chitsaz

Page 2: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 2

Implementation Techniquesinsert & search

Unordered List Index+1 index bucket O(n)

Ordered List Find location O(log2n)

Binary Tree

Hash Table

Page 3: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 3

Hash Functions

1-How to use Hash Functions:

2-Hash Functions:

Index = f(token)

3-Characteristics of hash functions

Page 4: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 4

Hash function Methods

a. Digital Selectionabcdefgh efh

b. Divisiondigits MOD prime_Number

c. Multiplicationabcd * defg

d. Folding

ab+cd+de+ef

Page 5: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 5

Resolving Collisions

a. Closed Hashing Leaner Resolution

Quadratic Probing

Double Hashing

Page 6: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 6

Resolving Collisions

b. Open Hashing Chaining

Page 7: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 7

Symbol Table Operators:

CreateASymbolTable(size)

Insert(Token)

Lookup(Token)

Delete(Token)

GetAttributes( Token, … )

AddAttributes( Token, …. )

Page 8: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 8

Symbol Table

Symbol Table Entry:

Scope Rules:

Block:

Symbol Table Types: Static Dynamic

Page 9: Chapter 3: Symbol Table 1 Compiler Designs and Constructions Chapter 3: Symbol Table Objectives: (7.6) Introduction to Symbol Table Implementation of Symbol.

Chapter 3: Symbol Table 9

Symbol Table

Summary:

Token Name

TokenValue

TokenType

TokenScope

MaxSizeArray