The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+13 votes
828 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
asked in Compiler Design by Veteran (59.5k points)
edited by | 828 views

1 Answer

+27 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.
answered by Boss (19.7k 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
Answer:


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

39,512 questions
46,664 answers
139,704 comments
57,481 users