Question
Consider the grammar defined by the following production rules, with two operators and
Which one of the following is TRUE?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2014 answer key
Solution
Analyze the grammar productions for left-recursion and right-recursion associated with each operator.
-
Production Rules for :
In the recursive rule , the non-terminal appears as the leftmost symbol on the right-hand side. This is left recursion, which enforces left associativity for operator .
-
Production Rules for :
In the recursive rule , the non-terminal appears on the right of . This is right recursion, which enforces right associativity for operator .
-
Conclusion:
is right associative, while is left associative, which corresponds to option (B).
B
Assuming standard arithmetic associativity rules instead of reading the recursion structure directly from the grammar.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 2
- Question
- 27 of 65, printed as CS Q.17
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.