syntaxdirected translations

syntaxdirected translations - Syntax Directed Translation 1...

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

View Full Document Right Arrow Icon
1 Syntax Directed Translation
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Semantic analysis Collecting type information may involve "computations" What is the type of x+y given the types of x and y? Tool: attribute grammars Each grammar symbol has a number of associated attributes: The type of a variable or expression The value of a variable or expression The code for a statement Etc. The grammar is augmented with special equations (called semantic actions ) that specify how the values of attributes are computed from other attributes. The process of using semantic actions to evaluate attributes is called syntax-directed translation .
Background image of page 2
3 Conceptual View Conceptual view of Syntax directed translation ( parse tree is ready ) Traverse tree as needed to evaluate the semantic rules As a result of the evaluations generate code modify symbol table issue error messages as a result of type checking compute information needed by other rules input parse tree dependency graphs evaluation order for semantic rules
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Syntax Directed Definitions Generalization of a context-free grammar in which each grammar symbol has an associated set of attributes 2 types synthesized attributes inherited attributes Each node in a parse tree has a record with fields holding attribute values
Background image of page 4
5 Two Types of Attributes c 1 c 2 c 3 c 4 P Synthesized attributes : values are computed from the children nodes Synthesized of P = f(c 1 , c 2 , c 3 , c 4 ) S 1 S 2 S 3 S 4 P Inherited attributes : values are computed from attributes of the siblings and parent of the node Inherited of S 4 = f(P, S 1 , S 2 , S 3 ) semantic rules create dependencies between attributes represent the dependencies as a graph from the graph, derive evaluation order for semantic rules
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Attributed Grammar Each grammar production A α has semantic rule of the form b = f(c 1 , c 2 , c 3 , . .., c k ) Either 1. b is synthesized attribute of A and c 1 , c 2 , c 3 , . .., c k are attributes of grammar symbols of RHS 2. b is an inherited attribute of one of the grammar symbols of RHS of production and c i ’s are attribute of A and/or other symbols on the RHS i.e A α { b}
Background image of page 6
7 Example Terminal symbols – have synthesized attributes only which are usually provided by the lexical analyzer no rules for synthesized attributes of terminals Start symbol – is assumed not to have any inherited attributes D E F A D E F A b is synthesized attribute of A A DEF c i ’s attributes of D, E, F b is inherited attribute of D A DEF c i ’s attributes of A, E, F
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 S-attributed Synthesized attributes used extensively in practice A syntax directed definition that only used synthesized attributes S-attributed definition
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/20/2010 for the course CS 101 taught by Professor Aga during the Spring '10 term at Jaypee University IT.

Page1 / 31

syntaxdirected translations - Syntax Directed Translation 1...

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

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