Question
Consider the following expression grammar :
Which of the following grammars is not left recursive, but is equivalent to ?
Official answer and solution
- Official answer
- C
- From
- Official GATE 2017 answer key
Solution
Eliminate immediate left recursion from each non-terminal in grammar using the standard transformation rule.
The standard rule to eliminate immediate left recursion is:
Apply this to the given grammar :
- For production :
Here , , . Replacing with variable name : - For production :
Here , , . Replacing with variable name : - For production :
This rule contains no left recursion and remains unchanged.
The resulting grammar without left recursion is:
This is completely equivalent to and identical to option C.
C
Option B eliminates left recursion only from , leaving still left-recursive.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 2
- Question
- 32 of 65, printed as CS Q.32
- 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.