search
Log In
0 votes
469 views

Suppose that we have a production $A\rightarrow BCD$. Each of the four nonterminals $A, B, C,$ and $D$ have two attributes: $s$ is a synthesized attribute, and $i$ is an inherited attribute. For each of the sets of rules below, tell whether

  1. the rules are consistent with an S-attributed definition
  2. the rules are consistent with an L-attributed definition, and
  3. whether the rules are consistent with any evaluation order at all?

 

  1. $A.s=B.i+C.s.$
  2. $A.s=B.i+C.s$ and $D.i=A.i+B.s.$
  3. $A.s=B.s+D.s$
  4. $A.s=D.i,B.i=A.s+C.s,C.i=B.s,$ and $D.i=B.i+C.i.$ 
in Compiler Design 469 views

1 Answer

0 votes
$A\rightarrow BCD$
a. $A.s=B.i+C.s$

    This is L attributed SDD. Attributes of parent node can take values from their children

b. $A.s=B.i+C.s,$ $D.i=A.i+B.s$

    A cannot have inherited attribute. Since, there is nothing present on the LHS of A. So this SDD is neither S attributed nor L attributed

c. $A.s=B.s+D.s$

    A's synthesized attribute is a function of synthesized attributes of its children. This confirms to S attributed definition. Every S attributed SDD is also L attributed SDD

d. $A.s=D.i,$ $B.i=A.s+C.s,$ $C.i=B.s,$ $D.i=B.i+C.i$

   In the rule B.i=A.s+C.s. Here B's inherited attributed is taking values from its right sibling C. This violates L-attributed definition which says that inherited attributes are limited to take values from its parents or left siblings only. Hence, this SDD is not L-attributed

edited by
0
Please explain b little more in detail>
0
which part u didn't get?
0

 i'm not convinced with explanation of b 

A cannot have inherited attribute. Since, there is nothing present on the LHS of A. So this SDD is neither S attributed nor L attributed

The third condition of L-attributed SDD is 

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

Is it neccessary that some non-terminal to be at the LHS of A? Cannot $A_i$ take value from $A_s$? 

0

watch this 

 

and

0

 are these questions solved? or just concepts?

0
questions from ullman?
0
I'm talking about that video
0
mostly concepts

Related questions

0 votes
0 answers
1
83 views
Implement Algorithm $3.23$, which converts a regular expression into a nondeterministic finite automaton, by an L-attributed SDD on a top-down parsable grammar. Assume that there is a token char representing any character, and that char.$lexval$ is the character it ... that is, a state never before returned by this function. Use any convenient notation to specify the transitions of the $NFA$.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 83 views
0 votes
1 answer
2
210 views
This grammar generates binary numbers with a "decimal" point: $S\rightarrow L.L\mid L$ $L\rightarrow LB\mid B$ $B\rightarrow 0\mid 1$ Design an S-attributed SDD to compute $S.val$, the decimal-number value of an input string. For example, the translation of string $101.101$ should be the decimal number $5.625$.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 210 views
0 votes
0 answers
3
188 views
This grammar generates binary numbers with a "decimal" point: $S\rightarrow L.L\mid L$ $L\rightarrow LB\mid B$ $B\rightarrow 0\mid 1$ Design an L-attributed SDD to compute $S.val$ ... be the decimal number $5.625$. Hint: use an inherited attribute $L.side$ that tells which side of the decimal point a bit is on.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 188 views
...