The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+14 votes
1.1k 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.8k points)
edited by | 1.1k views

1 Answer

+29 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.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$
Answer:

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,126 questions
53,251 answers
184,757 comments
70,502 users