The Gateway to Computer Science Excellence
+17 votes
1.3k views

In the following grammar $$\begin{align*} X &::= X \oplus Y \mid Y \\ Y&::= Z * Y \mid Z\\ Z&::= id \end{align*}$$Which of the following is true?

  1. '$\oplus$' is left associative while '$*$' is right associative
  2. Both '$\oplus$' and '$*$' are left associative
  3. '$\oplus$' is right associative while '$*$' is left associative
  4. None of the above
in Compiler Design by Veteran (52.2k points)
edited by | 1.3k views

1 Answer

+31 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.
by Boss (19.9k points)
edited by
0
When we create parse tree for the above grammar then  * is computed after x-or. So whether this is correct or not if the answer is 3..
0

A is the most apt answer.
But, * is left associative

https://www.programiz.com/c-programming/precedence-associativity-operators

0
U hav to calculate the associativity on the basis of given grammar  ....
0
understood, thanks :)
0
If both left and right derivations were possible, the grammar would have been ambiguous and we couldn't have given associativity.this is nice point gate keeda
0
What will be the answer A or D.
0
$A)$ is the correct answer.

and precedence$:\ast > \oplus$

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,648 questions
56,441 answers
195,294 comments
100,083 users