in Compiler Design edited by
6,688 views
22 votes
22 votes

In the following grammar

  • $X ::= X \oplus Y \mid Y$
  • $Y::= Z * Y \mid Z$
  • $Z::= id $

Which of the following is true?

  1. $\text{‘}\oplus\text{’}$ is left associative while $\text{‘}*\text{’}$ is right associative
  2. Both $\text{‘}\oplus\text{’}$ and $\text{‘}*\text{’}$ are left associative
  3. $\text{‘}\oplus\text{’}$ is right associative while $\text{‘}*\text{’}$ is left associative
  4. None of the above
in Compiler Design edited by
6.7k views

2 Answers

39 votes
39 votes
Best answer
It will be A. For multiple '$\oplus$', the derivation is possible only via '$X$' which is on left side of '$\oplus$' in the production. Hence it is left associative.

For multiple '$*$', the derivation is possible only via '$Y$' which is on the right side of '$*$' in the production. Hence it is right associative.

If both left and right derivations were possible, the grammar would have been ambiguous and we couldn't have given associativity.
edited by

4 Comments

@Lakshman Patel RJIT how can u say this ??

Any resources to study this topic.

0
0

@abir_banerjee Operator derived at the lowest level has the highest precedence.

Associativity and Precedence in CFGs - YouTube: This video will be helpful

1
1
1
1
0 votes
0 votes

Answer is A

1 comment

But easily we can check just by seeing if the Grammar is left recursive or Right recursive .
0
0
Answer:

Related questions