1 / 10

SYNTAX DIRECTED TRANSLATION

SYNTAX DIRECTED TRANSLATION. 11CS30011. Types of Attributes. There are two types of attributes for non-terminals :- Synthesized Attributes : For a non-terminal X at a parse-tree node T , the synthesized attribute is defined only in terms of attribute values at the children of T .

amara
Download Presentation

SYNTAX DIRECTED TRANSLATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SYNTAX DIRECTED TRANSLATION 11CS30011

  2. Types of Attributes There are two types of attributes for non-terminals :- • Synthesized Attributes : For a non-terminal X at a parse-tree nodeT , the synthesized attribute is defined only in terms of attribute values at the children of T.

  3. Types of Attributes • Inherited Attributes : For a non-terminal X at a parse-tree nodeT , the synthesized attribute is defined only in terms of attribute values at the T’s parent , T itself and T’s siblings.

  4. Example : - T -> FT’ T’ -> *FT’ T’ -> ɛ F -> id T T’ F T F * ɛ id id PARSE TREE

  5. Let val be the synthesized attribute of F and T. Let inh be the inherited attribute of T’ and let syn be the synthesized attribute of T’. Let lexval be the synthesized attribute of id ,which is an integer value returned by the lexical analyzer. Let the input string be 4 * 5

  6. The Symantic Rules corresponding to each production is :- T -> FT’ T’.inh = F.val T.val = T’.syn T’-> *FT’’ T’’.inh = T’.inh * F.val T’.syn = T’’.syn T’-> ɛ T’.syn = T’.inh F-> valF.val = id.lexval

  7. Annotated Parse Tree after applying the semantic rules:- T T.val = 4*5 T.inh = 4*5 T.syn = 4*5 T’ F F.val = 4 T’ F * T.inh = 4*5 T.syn = 4*5 F.val = 5 ɛ id id id.lexval = 4 id.lexval = 5

  8. S-attributed SDD A syntax-directed definition (SDD) that involves only synthesized attributes is called S-attributed SDD. In an S-attributed SDD, each rule computes an attribute for the nonterminal at the head of a production from attributes taken from the body of the production.

  9. S-attributed SDD Evaluation of S-attributed Parse Trees:- When an SDD is S-attributed , its attributes can be evaluated in any bottom up order of the nodes of the parse tree. The attributes can be evaluated by performing a post-order traversal of the parse tree and evaluating the attributes at a node N when the traversal leaves N for the last time.

  10. L-attributed SDD In a L-attributed SDD each attribute must be either synthesised or inherited but there are some conditions:- For a production A->X1 X2 X3….Xn The rule associated with this production used for computing an inherited attribute Xi.a may use: a)Inherited attributes associated with the head. b)Either inherited or synthesized attributes associated with the occurrences of symbols X1, X2,. . . , Xi-1 located to the left of Xi. c) Inherited or synthesized attributes associated with this occurrence of Xi itself, but only in such a way that there are no cycles in a dependency graph formed by the attributes of this Xi.

More Related