-1

I wanted to ask a question regrading elimination of left factoring and recursion in grammar. I've solved such problems in the past but the grammar in this one looks really tricky and it is beyond my comprehension. I personally think there's left recursion present in line 2 and 4. However, I'm not able to identify it well enough to remove both of the mentioned things (especially in the last line with numbers 1-9). I'll attach a picture of the grammar because pasting it is treating like a code and not enabling me to process.

Can anyone kindly help me understanding the language generated by grammar below along with how I can know if left factoring and left recursion is present and how to remove it from here:

R --> D DX DP EX 
DX --> D DX | empty
DP --> '.' D DX | empty
EX --> 'E' S D DX | empty
S --> + | - | empty
D --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 

grammar

Nimantha
  • 6,405
  • 6
  • 28
  • 69

1 Answers1

1

A production is directly left recursive if it has the form N ← N β where β is any sequence of zero or more terminals or non-terminals. No production in your grammar has that form.

More generally, a production is indirectly left recursive if there is some non-terminal N which can derive the sequence N β in one or more steps.

In the case of your grammar, it's pretty clear that is not the case. All productions start with a terminal or the non-terminal D, and D can only derive a single terminal. Since D cannot derive the empty sequence, that's it: starting from any non-terminal, we derive a sentential firm starting with a terminal in just two steps.

So it's impossible to remove left-recursion because there is no left-recursion to remove.

Left-factoring is possible because several productions start with the same symbol.

rici
  • 234,347
  • 28
  • 237
  • 341