edited by
6,646 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
edited by

2 Answers

Best answer
39 votes
39 votes
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
0 votes
0 votes

Answer is A

Answer:

Related questions

19 votes
19 votes
4 answers
4
Kathleen asked Sep 29, 2014
7,084 views
Heap allocation is required for languages.that support recursionthat support dynamic data structurethat use dynamic scope rulesNone of the above