中国高校课件下载中心 》 教学资源 》 大学文库

清华大学:《编译原理》课程教学资源_(英文译文)Chapter 6.3 The Symbol Table

文档信息
资源类别:文库
文档格式:PPT
文档页数:75
文件大小:264.5KB
团购合买:点击进入团购
内容简介
Symbol table: major inherited attribute and major data structure in a compiler Principal operations: – Insert: store the information provided by name declarations when processing these declarations – Lookup: retrieve the information associated to a name when that name is used in the associated code.
刷新页面文档预览

COMPILER CONSTRUCTION Principles and practice Kenneth C. louden

COMPILER CONSTRUCTION Principles and Practice Kenneth C. Louden

6. Semantic Analysis PART TWO

6. Semantic Analysis PART TWO

Contents Part One 6. 1 Attributes and Attribute grammars 6.2 Algorithms for Attribute Computation Part two 6.3 The Symbol Table 6.4 Data Types and Type Checking 6.5 A Semantic analyzer for the tiny language

Contents Part One 6.1 Attributes and Attribute Grammars 6.2 Algorithms for Attribute Computation Part Two 6.3 The Symbol Table 6.4 Data Types and Type Checking 6.5 A Semantic Analyzer for the TINY Language

6.3 The Symbol Table

6.3 The Symbol Table

Symbol table: major inherited attribute and major data structure in a compiler Principal operations: Insert: store the information provided by name declarations when processing these declarations Lookup: retrieve the information associated to a name when that name is used in the associated code Delete: remove the information provided by a declaration when that declaration no longer applies · Information stored: Include data type information, information on region of applicability(scope), and information on eventual location in memory

• Symbol table: major inherited attribute and major data structure in a compiler • Principal operations: – Insert: store the information provided by name declarations when processing these declarations – Lookup: retrieve the information associated to a name when that name is used in the associated code. – Delete: remove the information provided by a declaration when that declaration no longer applies. • Information stored: – Include data type information, information on region of applicability (scope), and information on eventual location in memory

6.3.1 The Structure of The Symbol Table

6.3.1 The Structure of The Symbol Table

Typical dictionary data structure Linear list Provide easy and direct implementations of the three basic operations Operation time is linear in the size of the list Good for a compiler implementation in which speed is not a major concern such as a prototype or experimental compiler or an interpreter for a very small program Various search tree structures (binary search trees, AVL trees, B trees) Don,'t provide best case efficiency The delete operation is very complexity Less useful

Typical dictionary data structure • Linear list – Provide easy and direct implementations of the three basic operations; – Operation time is linear in the size of the list; – Good for a compiler implementation in which speed is not a major concern such as a prototype or experimental compiler or an interpreter for a very small program. • Various search tree structures – (binary search trees, AVL trees, B trees) – Don't provide best case efficiency; – The delete operation is very complexity; – Less useful

Hash tables All three operation can be performed in almost constant time Most frequently in practice, best choice Main idea An array of entries(called buckets), indexed by an Integer range a hash function turns the search key into an integer hash value in the index range and the item corresponding to the search key is stored in the bucket at this index The efficiency greatly depends on the design of the hash function Main problem Collision resolution: two keys are mapped to the same index by the hash function

• Hash tables – All three operation can be performed in almost constant time – Most frequently in practice, best choice • Main idea – An array of entries (called buckets), indexed by an integer range – A hash function turns the search key into an integer hash value in the index range – And the item corresponding to the search key is stored in the bucket at this index – The efficiency greatly depends on the design of the hash function • Main problem – Collision resolution: two keys are mapped to the same index by the hash function

The methods to deal with the collision Open addressing Inserting the collided new items in successive buckets Will cause a significant degradation in performance and make delete operation difficult Separate chaining Each bucket is a linear list; collisions are resolved by inserting the new item into the bucket list Perhaps it is the best scheme for compiler construction

The methods to deal with the collision • Open addressing – Inserting the collided new items in successive buckets – Will cause a significant degradation in performance and make delete operation difficult • Separate chaining – Each bucket is a linear list; collisions are resolved by inserting the new item into the bucket list • Perhaps it is the best scheme for compiler construction

6.3.2 Declarations

6.3.2 Declarations

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档