L9-SDT - Introduction to Compiler Design Semantic Analysis:...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Compiler Design Semantic Analysis: Syntax-Directed Translation ection 2.3, Chapter 5) (Section 2.3, Chapter 5) rofessor i ing You Professor Yi-Ping You Department of Computer Science ttp://www cs nctu edu tw/~ypyou/ Page 1 Introduction to Compiler Design, Spring 2010 http://www.cs.nctu.edu.tw/~ypyou/
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline Overview of Semantic Analysis Syntax-Directed Definition Applications of Syntax-Directed Translation Syntax-Directed Translation Scheme Implementing SDD’s Implementing S-Attributed SDD’s Implementing SDD’s by Traversing An nnotated Parse Tree Annotated Parse Tree Eliminating Left Recursion From SDT’s plementing L ttributed SDD’s Page 2 Introduction to Compiler Design, Spring 2010 Implementing L-Attributed SDD’s
Background image of page 2
Need for Semantic Need for Semantic Analysis Analysis Not all program properties can be represented using context-free grammars E.g.: “ variables must be declared before use ” is not a context-free property Choices Use context-sensitive grammars Parsing context-sensitive grammars is expensive Use context-free grammars with attributes and semantic rules or semantic actions Syntax-directed definitions (SDD) Syntax-directed translation scheme (SDT) – A complementary notation to SDD Page 3 Introduction to Compiler Design, Spring 2010
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Attributes The attributes are usually for identifiers Attribute values may represent Literal constants (numbers or strings) Returned by the scanner A data type for type checking of expressions Scoping information for local declarations emory locations such as a frame index of a Memory locations, such as a frame index of a local variable or function argument Intermediate program representations Page 4 Introduction to Compiler Design, Spring 2010
Background image of page 4
Syntax Syntax-Directed Translation Directed Translation Grammar symbols are associated with attributes to ssociate information with the programming associate information with the programming language constructs that they represent alues of these attributes are evaluated by the Values of these attributes are evaluated by the semantic rules associated with the production rules valuation of these semantic rules: Evaluation of these semantic rules: may generate intermediate codes may put information into the symbol table may perform type checking may issue error messages may perform some other activities Page 5 Introduction to Compiler Design, Spring 2010 in fact, they may perform almost any activities
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Syntax Syntax-Directed Definitions and Translation Schemes Directed Definitions and Translation Schemes When we associate semantic rules with productions, we use two notations: Syntax-Directed Definitions Syntax-Directed Translation Schemes Syntax-Directed Definitions (SDD): give high-level specifications for translations ide many implementation details such as order of evaluation of hide many implementation details such as order of evaluation of semantic actions We associate a production rule with a set of semantic actions, and we do not say when they will be evaluated
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/25/2010 for the course ALL 0204 taught by Professor 79979 during the Spring '10 term at National Chiao Tung University.

Page1 / 73

L9-SDT - Introduction to Compiler Design Semantic Analysis:...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online