《编译原理 Compiler Construction》课程教学资源(PPT讲稿)语义分析 Semantic Analysis(Attributes and Attribute Grammars、Algorithms for Attribute Computation)

6. Semantic Analysis PART ONE
6. Semantic Analysis PART ONE

Semantic Analysis phase Purpose: compute additional information needed for compilation that is beyond the capabilities of Context Free Grammars and standard parsing algorithms Static semantic analysis: Take place prior to execution (Such as building a symbol table, performing type inference and type checking Classification analysis of a program required by the rules of the programming language to establish its correctness and to guarantee proper execution Analysis performed by a compiler to enhance the efficiency of execution of the translated program
• Semantic Analysis Phase – Purpose: compute additional information needed for compilation that is beyond the capabilities of ContextFree Grammars and Standard Parsing Algorithms – Static semantic analysis: Take place prior to execution (Such as building a symbol table、performing type inference and type checking) • Classification – Analysis of a program required by the rules of the programming language to establish its correctness and to guarantee proper execution – Analysis performed by a compiler to enhance the efficiency of execution of the translated program

Description of the static semantic analysis Attribute grammar identify attributes of language entities that must be computed and to write attribute equations or semantic rules that express how the computation of such attributes is related to the grammar rules of the language Which is most useful for languages that obey the principle of syntax-Directed Semantics Abstract syntax as represented by an abstract syntax tree
• Description of the static semantic analysis – Attribute grammar • identify attributes of language entities that must be computed • and to write attribute equations or semantic rules that express how the computation of such attributes is related to the grammar rules of the language – Which is most useful for languages that obey the principle of Syntax-Directed Semantics – Abstract syntax as represented by an abstract syntax tree

Implementation of the static semantic analysis Not as clearly expressible as parsing algorithms because of the addition problem caused by the timing of the analysis during the compilation process Multi-pass(more common) or single pass lead to totally different process Emphasis Attributes and attribute grammars Algorithms for attribute computation The symbol table Data types and type checking a semantic analyzer for the tiNy language
• Implementation of the static semantic analysis: – Not as clearly expressible as parsing algorithms because of the addition problem caused by the timing of the analysis during the compilation process – Multi-pass (more common) or single pass lead to totally different process • Emphasis: – Attributes and attribute grammars – Algorithms for attribute computation – The symbol table – Data types and type checking – 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
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.1 Attributes and attribute Grammars
6.1 Attributes and Attribute Grammars

Attributes Any property of a programming language construct such as The data type of a variable The value of an expression The location of a variable in memory The object code of a procedure The number of significant digits in a number Binding of the attribute The process of computing an attribute and associating its computed value with the language construct in question Binding time The time during the compilation/execution process when the binding of an attribute occurs Based on the difference of the binding time, attributes is divided nto Static attributes (be bound prior to execution and dynamic attributes (be bound during execution)
• Attributes – Any property of a programming language construct such as • The data type of a variable • The value of an expression • The location of a variable in memory • The object code of a procedure • The number of significant digits in a number • Binding of the attribute – The process of computing an attribute and associating its computed value with the language construct in question • Binding time – The time during the compilation/execution process when the binding of an attribute occurs – Based on the difference of the binding time, attributes is divided into Static attributes (be bound prior to execution) and Dynamic attributes (be bound during execution)

Example: The binding time and significance during compilation of the attributes Attribute computations are extremely varied ype checker In a language like C or Pascal, is an important part of semantic analysis While in a language like LiSP, data types are dynamic, LISP compiler must generate code to compute types and perform type checking during program execution The values of expressions Usually dynamic and the be computed during execution But sometime can also be evaluated during compilation (constant folding)
• Example: The binding time and significance during compilation of the attributes. – Attribute computations are extremely varied – Type checker • In a language like C or Pascal, is an important part of semantic analysis; • While in a language like LISP , data types are dynamic, LISP compiler must generate code to compute types and perform type checking during program execution. – The values of expressions • Usually dynamic and the be computed during execution; • But sometime can also be evaluated during compilation (constant folding)

Example: the binding time and significance during compilation of the attributes Attribute computations are extremely varied The allocation of a variable Either static(such as in FORTRAN77)or dynamic(such as in LISP) Sometimes it is a mixture of static and dynamic(such as in C and Pascal) depending on the language and properties of the variable itself. Object code of a procedure A static attribute, which is computed by the code generator Number of significant digits in a number Often not explicitly treated during compilation
• Example: the binding time and significance during compilation of the attributes. – Attribute computations are extremely varied – The allocation of a variable: • Either static (such as in FORTRAN77 ) or dynamic (such as in LISP), • Sometimes it is a mixture of static and dynamic (such as in C and Pascal) depending on the language and properties of the variable itself. – Object code of a procedure: • A static attribute, which is computed by the code generator – Number of significant digits in a number: • Often not explicitly treated during compilation

6.1.1 Attribute grammars
6.1.1 Attribute Grammars
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《嵌入式系统开发》课程PPT教学课件(讲稿)第一章 嵌入式系统概述.ppt
- 《数据库基础》课程PPT教学课件(SQL Server)第4章 T-SQL与可编程对象.ppt
- 软件配置管理和项目管理工具(PPT讲稿)Software Configuration Management and Project Management Tool.ppt
- 《计算机系统结构》课程教学资源(PPT课件讲稿)第五章 存储层次.ppt
- 四川大学:《数据库技术》课程教学资源(PPT课件讲稿)第4章 数据库查询.ppt
- 四川大学:《操作系统 Operating System》课程教学资源(PPT课件讲稿)Chapter 7 Memory Management.ppt
- 香港浸会大学:并行输入输出(PPT讲稿)Parallel I/O.ppt
- 香港浸会大学:Kickstart Tutorial/Seminar on using the 64-nodes P4-Xeon Cluster in Science Faculty.ppt
- Essential Cluster OS Commands.ppt
- 《图像处理与计算机视觉 Image Processing and Computer Vision》课程教学资源(PPT课件讲稿)Chapter 07 Mean-shift and Cam-shift.pptx
- 香港中文大学:Image processing and computer vision(PPT课件讲稿)Edge detection and image filtering.pptx
- 《图像处理与计算机视觉 Image Processing and Computer Vision》课程教学资源(PPT课件讲稿)Chapter 05 Hough transform.pptx
- GD-Aggregate:A WAN Virtual Topology Building Tool for Hard Real-Time and Embedded Applications.ppt
- Introduction to Internet and TCPIP(PPT讲稿)IP转发 IP FORWARDING.pptx
- 《图像处理与计算机视觉 Image Processing and Computer Vision》课程教学资源(PPT课件讲稿)Chapter 10 Pose estimation by the iterative method.pptx
- 《操作系统》课程教学资源(PPT课件讲稿)Chapter 8 Virtual Memory.ppt
- 《操作系统》课程教学资源(PPT课件讲稿)Chapter 6 Concurrency Deadlock and Starvation.ppt
- 《操作系统》课程教学资源(PPT课件讲稿)Chapter 1 and 2 Computer System and Operating System Overview.ppt
- 印第安纳大学:《Informatics》课程PPT教学课件(信息学)08 网络爬虫 Web Crawling.ppt
- 《Java编程导论》课程教学资源(PPT课件讲稿)Chapter 8 Strings and Text I/O.ppt
- 四川大学:《Linux操作系统》课程教学资源(PPT课件讲稿)第6章 Linux系统调用.ppt
- 《数据库技术》课程教学资源(PPT课件讲稿)第3章 SQL语言基础及数据定义功能(主讲:曾晓东).ppt
- 四川大学:.NET and .NET Core:Languages, Cloud, Mobile and AI(PPT课件讲稿)NET for Data Science and AI.pptx
- 四川大学:《Matlab程序设计》课程教学资源(教学大纲)Programming in Matlab.pdf
- 电子科技大学:《计算系统与网络安全 Computer System and Network Security》课程教学资源(PPT课件讲稿)第4章 网络基础(网络概述、协议).ppt
- 电子科技大学:《计算系统与网络安全 Computer System and Network Security》课程教学资源(PPT课件讲稿)第7章 协议安全技术(安全协议实例).ppt
- 电子科技大学:《计算系统与网络安全 Computer System and Network Security》课程教学资源(PPT课件讲稿)第5章 网络隔离技术.ppt
- 电子科技大学:《计算系统与网络安全 Computer System and Network Security》课程教学资源(PPT课件讲稿)第2章 信息安全数学基础(计算复杂性).ppt
- 《计算机系统结构》课程教学资源(PPT课件讲稿)第五章 存储系统.ppt
- 《操作系统》课程教学资源(PPT课件讲稿)Chapter 03 Process Description And Control.ppt
- 电子科技大学:《面向对象程序设计语言C++》课程教学资源(PPT课件讲稿)第九章 多态性(主讲:丘志杰).ppt
- 《计算机体系结构》课程教学资源(PPT课件讲稿)第七章 多处理机系统.ppt
- 《操作系统原理》课程教学资源(PPT课件讲稿)Chapter 05 并发性——互斥和同步(Concurrency - Mutual Exclusion and Synchronization).ppt
- 《计算机系统结构》课程教学资源(PPT课件讲稿)第八章 多计算机系统.ppt
- 《计算机系统结构》课程教学资源(PPT课件讲稿)第一章 计算机系统结构的基本概念.ppt
- 《数学建模》课程教学资源(PPT讲稿)SAS基础培训(生成SAS数据集、加工SAS数据集)Statistical Analysis System.ppt
- 《数字图像处理》课程教学资源(PPT课件讲稿)第8章 彩色图像处理.ppt
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第8章 因特网上的音频/视频服务.ppt
- 《数字图像处理》课程教学资源(PPT课件讲稿)第4章 图像增强.ppt
- 郑州大学:《计算机组成原理》课程教学资源(PPT课件讲稿,共八章,任课教师:石磊).ppt