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..

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+14 votes

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?

- '$\oplus$' is left associative while '$*$' is right associative
- Both '$\oplus$' and '$*$' are left associative
- '$\oplus$' is right associative while '$*$' is left associative
- None of the above

+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.

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.

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

- All categories
- General Aptitude 1.6k
- Engineering Mathematics 7.5k
- Digital Logic 3k
- Programming & DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6k
- Compiler Design 2.1k
- Databases 4.2k
- CO & Architecture 3.5k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.5k
- Admissions 585
- Exam Queries 572
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,126 questions

53,251 answers

184,757 comments

70,502 users