Syntax Directed TranslationFinal_Presentation

download Syntax Directed TranslationFinal_Presentation

of 24

Transcript of Syntax Directed TranslationFinal_Presentation

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    1/24

    Syntax Directed Translation

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    2/24

    Presented by

    Md. Chhafrul Alam Khan (Rayhan)

    Batch: 30th,

    ID: 200910142And

    Jinnat Sultana Jeny

    Batch: 30th,

    ID: 200911097

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    3/24

    Overviewy Syntax Directed Translation (SDT)

    y Syntax Directed Definitions (SDD)

    y

    Attributesy Synthesized Attributes

    y Inherited Attributes

    y Annotated Parse Tree

    y Dependency Graph

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    4/24

    Syntax Directed Translations

    y The translation of infix expressions into postfixnotation

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    5/24

    Syntax Directed Definitions (SDD)

    y

    SDD associated set of attributes partitioned into twosubsets called the synthesized and inherited attributes

    y An attribute can represent anything we choose: a

    string, a number, a type, a memory location, orwhatever.

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    6/24

    Synthesized Attributes

    y X at a parse tree node N is defined by a semantic rule

    associated with the production at N

    y Node N is defined only in terms of attribute values atthe children of N and at N itself.

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    7/24

    Synthesized Attributes

    y Example:

    y The given production rule is a synthesized attribute

    Production Semantic Rules

    L E L.val = E.val

    L En L.val = E.val

    T T1 * F T.val = T1.val * F.val

    F (E) F.val = E.val

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    8/24

    Inherited Attributesy B at a parse-tree node N is defined by a semantic rule

    associated with the production at the parent of N.

    y The production must have B as a symbol in its body.

    y At node N is defined only in terms of attribute valuesat N s parent, N itself, and N s siblings.

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    9/24

    Inherited Attributes

    y Example:

    y The given production is an inherited attribute.

    Production Semantic Rules

    T FT` T`.inh = F.val

    T` *FT1` T1`.inh = T`.inh * F.val

    F (E) E.val = F.val

    E E1 + T T.inh = E1.val + E.val

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    10/24

    Annotated Parse-Tree

    y Parse-tree that also shows the values of the attributesat each node.

    y Values of Attributes in nodes of annotated parse-treeare either,

    y

    initialized to constant values or by the lexical analyzer.y determined by the semantic-rules.

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    11/24

    Dependency Graphy Depicts the flow of information among the attribute

    instances in a particular parse tree

    y An edge from one attribute instance to another meansthat the value of the first is needed to compute thesecond.

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    12/24

    Annotated Parse-Tree

    L

    E n

    Production Semantic Rules

    Lp En L.Val = E.val

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    Fp digit

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    13/24

    Annotated Parse-Tree

    L

    E n

    Production Semantic Rules

    Lp En

    Ep E1+T

    L.Val = E.val

    E.Val = E1.val + T.val

    EpT E.Val = T.val

    Tp T1*F

    Tp F

    Fp (E)

    Fp

    digit

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval T

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    14/24

    Annotated Parse-TreeL

    E n

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    TpT1*F T.Val = T.val * F.val

    Tp F

    Fp (E)

    Fp

    digit

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    T

    *T1 F

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    15/24

    Annotated Parse-TreeL

    E n

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    Tp F T.Val = F.val

    Fp (E)

    Fp

    digit

    F.Val = E.val

    F.Val = digit.lexval

    T

    *T1 F

    F

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    16/24

    Annotated Parse-TreeL

    E n

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    Fpdigit F.Val = digit.lexval

    T

    *T1 F

    F

    digit

    digit

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    17/24

    Annotated Parse-TreeL.val

    E.val n

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    Fp digit

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    T.Val

    *T1.val F.Val

    F.val

    digit.lexval

    digit.lexval

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    18/24

    Annotated Parse-Tree & Dependency GraphL.val

    E.val n

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    Fp digit

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    T.Val

    *T1.val F.Val = 5

    F.Val = 3

    digit.lexval = 3

    digit.lexval = 5

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    19/24

    Annotated Parse-Tree & Dependency Graph

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    Fp digit

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    L.val

    E.val n

    T.Val

    *T1.val = 3 F.Val = 5

    F.val=3

    digit.lexval = 3

    digit.lexval = 5

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    20/24

    Annotated Parse-Tree & Dependency Graph

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    Fp digit

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    L.val

    E.val n

    T.Val = 3*5

    = 15

    *T1.val = 3 F.Val = 5

    F.val=3

    digit.lexval = 3

    digit.lexval = 5

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    21/24

    Annotated Parse-Tree & Dependency Graph

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    Fp digit

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    L.val

    E.Val = 15 n

    T.Val = 3*5

    = 15

    *T1.val = 3 F.Val = 5

    F.val=3

    digit.lexval = 3

    digit.lexval = 5

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    22/24

    Annotated Parse-Tree & Dependency Graph

    Production Semantic Rules

    Lp En

    Ep E1+T

    Ep T

    Tp T1*F

    Tp F

    Fp (E)

    Fp digit

    L.Val = E.val

    E.Val = E1.val + T.val

    E.Val = T.val

    T.Val = T.val * F.val

    T.Val = F.val

    F.Val = E.val

    F.Val = digit.lexval

    L.Val = 15

    E.Val = 15 n

    T.Val = 3*5

    = 15

    *T1.val = 3 F.Val = 5

    F.val=3

    digit.lexval = 3

    digit.lexval = 5

    Input string : 3 * 5n

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    23/24

    Conclusion

    y Conclusion

  • 8/7/2019 Syntax Directed TranslationFinal_Presentation

    24/24

    Thank you