in Compiler Design edited by
1,248 views
3 votes
3 votes
Consider the following operator grammar

E->AaBcD

A->bA|e

B->bB|e

D->eD|g

Which of the following precedence relation is incorrect from the above grammar? Assume x<•y is used to represent x is having less precedence than y and in the expression x appears first and y appears next.

a) a<•b b) c<•g c) a<•e d) c<•b
in Compiler Design edited by
1.2k views

1 Answer

2 votes
2 votes

In Operator Grammar we are looking next token forward only but not backward.

In SLR(1) and LR(1) we look one token advance according to that actions(Shift or Reduce) actions performed.

In LR(K) lookahead K symbols.

One more is bottom level tokens having higher precedence that top level in parse tree. 

Remember these two key points ,now first draw parse tre for any one string

 In above prase tree a and c are at same level and having equall precedence.

a<.b ---b is bottom level and a is top level so it is correct.

c<.g---g is bottom level and c is top level.

a<.e---it is also correct.

c<.b---b is bottom level and c is top level but b is backward to c,so c may not look b.it is incorrect.

Hence Option should be D

1 comment

Can you please explain it more clearly...I didn't understood 'b is backward to c'
0
0