lec05-syntaxdirected

lec05-syntaxdirected - Syntax-Directed Translation Grammar...

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

View Full Document Right Arrow Icon
BİM454 Programming Language Concepts 1 Syntax-Directed Translation Grammar symbols are associated with attributes to associate information with the programming language constructs that they represent. Values of these attributes are evaluated by the semantic rules associated with the production 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 in fact, they may perform almost any activities. An attribute may hold almost any thing. a string, a number, a memory location, a complex record.
Background image of page 1

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

View Full DocumentRight Arrow Icon
BİM454 Programming Language Concepts 2 Syntax-Directed Definitions and Translation Schemes When we associate semantic rules with productions, we use two notations: Syntax-Directed Definitions Translation Schemes Syntax-Directed Definitions: give high-level specifications for translations 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. Translation Schemes: indicate the order of evaluation of semantic actions associated with a production rule. In other words, translation schemes give a little bit information about implementation details.
Background image of page 2
BİM454 Programming Language Concepts 3 Syntax-Directed Definitions A syntax-directed definition is a generalization of a context-free grammar in which: Each grammar symbol is associated with a set of attributes. This set of attributes for a grammar symbol is partitioned into two subsets called synthesized and inherited attributes of that grammar symbol. Each production rule is associated with a set of semantic rules. Semantic rules set up dependencies between attributes which can be represented by a dependency graph . This dependency graph determines the evaluation order of these semantic rules. Evaluation of a semantic rule defines the value of an attribute. But a semantic rule may also have some side effects such as printing a value.
Background image of page 3

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

View Full DocumentRight Arrow Icon
BİM454 Programming Language Concepts 4 Annotated Parse Tree A parse tree showing the values of attributes at each node is called an annotated parse tree . The process of computing the attributes values at the nodes is called annotating (or decorating ) of the parse tree. Of course, the order of these computations depends on the dependency graph induced by the semantic rules.
Background image of page 4
BİM454 Programming Language Concepts 5 Syntax-Directed Definition In a syntax-directed definition, each production A→α is associated with a set of semantic rules of the form: b=f(c 1 ,c 2 ,…,c n ) where f is a function, and b can be one of the followings: b is a synthesized attribute of A and c 1 ,c 2 ,…,c n are attributes of the grammar symbols in the production ( A→α ). OR
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/20/2009 for the course CENG PLC taught by Professor Anyone during the Fall '09 term at Anadolu University.

Page1 / 51

lec05-syntaxdirected - Syntax-Directed Translation Grammar...

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

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