Removing Left Recursion Using Terminals

How to remove left recursion by the following rule:

S → aSAbb | aa

I understand how to do this on S → SA | AND

which becomes S → A | AS'; S '-> A | AS ', but the terminals throw me away in this matter.

EDIT:

Sorry, apparently, I was confused about what remained of the recursion. I had to ask how to remove the left hand symbol from the right side.

+3
source share
1 answer

The rule

S -> aSAbb | aA

does not remain recursive. The left recursive rule has the form

A -> Au

where u is the sequence of terminals and non-terminals. To remove the character Son the right side of the rules S, consider:

S => aSAbb
  => a(aSAbb)Abb
  => a^n(aA)(Abb)^n

S . :

S -> aKAbb | aA
K -> aSAbb | aA

,

S => aSAbb
  => a(aSAbb)Abb
  => a(a(aSAbb)Abb)Abb

S => aKAbb
  => a(aSAbb)Abb
  => a(a(aKAbb)Abb)Abb

aA ( : , , ).

+1

Source: https://habr.com/ru/post/1780307/


All Articles