清华大学:《编译原理》课程教学资源_(英文译文)Chapter 6.1 Attributes and AttributeGrammars

COMPILER CONSTRUCTION Principles and practice Kenneth C. louden
COMPILER CONSTRUCTION Principles and Practice Kenneth C. Louden

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
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 7.4 Dynamic Memory.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 7.1 Memory Organization During Program Execution.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 1.1 Why? A Brief History.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 4.1 Top-Down Parsing byRecursive-Descent.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 4.1 Top-Down Parsing by Recursive-Descent.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 5.3 SLR(1)Parsing.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 5.1 Overview of Bottom-UpParsing.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 8.6 Code Generation in Commercial Compilers:Two Case Studies.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 8.1 Intermediate Code and Data.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 8 Code Generation.ppt
- 《NFS报文分析》讲义.doc
- 华中科技大学:《IT项目管理》(本科)(英文版)What makes a good manager.doc
- 华中科技大学:《IT项目管理》(本科)(英文版)Ten attributes of a good employee.doc
- 华中科技大学:《IT项目管理》(本科)(英文版)Topic:9 Project Procurement Management.ppt
- 华中科技大学:《IT项目管理》(本科)(英文版)Topic:8 Project Risk Management.ppt
- 华中科技大学:《IT项目管理》(本科)(英文版)Topic:7 Project Communication Management.ppt
- 华中科技大学:《IT项目管理》(本科)(英文版)Topic:6 Project HR Management.ppt
- 华中科技大学:《IT项目管理》(本科)(英文版)Topic:5 Project Cost Management.ppt
- 华中科技大学:《IT项目管理》(本科)(英文版)Topic:4 Project Time Management.ppt
- 华中科技大学:《IT项目管理》(本科)(英文版)Topic:3 Project Scope Management.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 6.3 The Symbol Table.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 3.1 The Parsing Process.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 2.1 The Scanning Process.ppt
- 清华大学:《编译原理》课程教学资源_(英文译文)Chapter 2.4 From Regular Expression To DFAs.ppt
- 《多媒体技术》课程教学资源(PPT课件讲稿).ppt
- 《JAVA基础实例200题》Java例题(一).pdf
- 《JAVA基础实例200题》Java例题(二).pdf
- 《JAVA基础实例200题》Java例题(三).pdf
- 《JAVA基础实例200题》Java例题(四).pdf
- 《JAVA基础实例200题》Java例题(五).pdf
- 《JAVA基础实例200题》练习题.pdf
- 长江大学:《微型计算机技术及应用课件》第一章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第七章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第三章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第九章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第二章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第五章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第八章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第六章习题答案(李华贵).doc
- 长江大学:《微型计算机技术及应用课件》第十章习题答案(李华贵).doc