当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

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

资源类别:文库,文档格式:PPT,文档页数:85,文件大小:663.5KB,团购合买
6.1 Attributes and Attribute Grammars 6.1.1 Attribute Grammars 6.1.2 Simplifications and Extensions to Attribute Grammars 6.2 Algorithms for Attribute Computation 6.2.1 Dependency graphs and evaluation order 6.2.2 Synthesized and Inherited Attributes 6.2.3 Attributes as Parameters and Returned Values 6.2.4 The Use of External Data Structures to Store Attributes Values 6.2.5 The Computation of Attributes during Parsing 6.2.6 The Dependence of Attributes Computation on the Syntax
点击下载完整版文档(PPT)

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 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

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

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共85页,可试读20页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有