Deprecated: Implicit conversion from float-string "1522867515.457" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1522867515.457" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1522867515.457" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1522867515.457" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1522867515.457" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1528979178.859" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1528979178.859" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1528979178.859" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1528979178.859" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1528979178.859" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594
Compiler Design: Attribute Grammar
749 views

1 Answer

1 votes
1 votes

Attribute Grammer:

  • An attribute grammar is a context-free grammar that has been extended to provide context- sensitive information by appending attributes to some of its nonterminals.
  • Each distinct symbol in the grammar has associated with it a finite, possibly empty, set of attributes.

        • Each attribute has a domain of possible values.
        • An attribute may be assigned values from its domain during parsing.
        • Attributes can be evaluated in assignments or conditions.

Classes of Attribute:
    1. Syntheized attributes
    2. Inherited attributes

Syntheized attributes: 
    1. Value is computed from values of Children's attribute.
    2. Evaluted during Bottom Up parsing
    3. S-attributed grammer contains only syntheized attributes.

Inherited attributes:
    1. Value is computed/inherited from either Parent or siblings.
    2. Evaluted by transversing parse tree from Left to Right, Top to bottom parsing.
    3. L-attributed grammer contains Inherited attributes.

S-attribute Grammers:
    1. Syntheized attributes 
    2. Semantic actions placed only to the right end of productions. (offers less flexibility)
    3. Bottom up parsing


    Examples:
        1. $A → BCD$
           $then, A.S → f(B.S,C.S,D.S)$ ==> value of A deriving from children's attribute only.
        2.  $Expr → Expr + Term\\  Expr → Term\\ Term → Term * Factor\\ Term → Factor\\ Factor → "(" Expr ")"\\ Factor → integer$

        Both grammers use only Syntheized values, therfore they are S-attribute grammers.

L-attribute Grammers:
        1. Syntheized and Inherited (parent and Left siblings only) attributes 
        2. Semantic actions placed anywhere productions.
            (offers more flexibility)
        3. Left to Right, Bottom Up parsing

 Examples:


            1.$A → xyz; then, { y.S = A.S; y.S = x.S;}$
                   Above grammer is L-attribute because, y dervies its value only from parent and siblings to the left.
            But,
                $A → xyz; then, { y.S = A.S; y.S = z.S;}$
                   In contrast to above grammar, here y evaluates its value from 'z', which is right sibling of 'y'. therfore, it's not a L-attributed grammer.

Related questions


Deprecated: Implicit conversion from float-string "1650142415.439" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1650142415.439" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1650142415.439" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1650142415.439" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1548509309.456" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1548509309.456" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1548509309.456" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1548509309.456" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1546420443.529" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1546420443.529" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1546420443.529" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1546420443.529" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1544313919.804" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1544313919.804" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1544313919.804" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1544313919.804" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803
8.6k
views
2 answers
2 votes
Subhrangsu asked Apr 16, 2022
8,552 views
Is the following grammar LL(1) ?S→ aABbCD | ϵA→ ASd | ϵB→ Sac| hC | ϵC→ Sf |CgD→ aBD | ϵDraw the LL(1) parsing table for the given grammar.
4.0k
views
1 answers
0 votes
abc1 asked Jan 26, 2019
3,999 views
consider the grammar G: S->A|B A->a|c B->b|c where {S,A,B} are non-terminals,{a,b,c} are terminals.Does LR(1) can parse all strings that are generated by gr...
940
views
1 answers
1 votes
susgir2 asked Jan 2, 2019
940 views
Grammar. S → Aa | B A → Ac | Aad | bd | epsilon . .
256
views
0 answers
0 votes
2019_Aspirant asked Dec 9, 2018
256 views
Operator precedence parser even parses ambiguous grammars that are in form of operator grammars. I am inquiring about the nature of the ambiguous grammar. Could the langu...