• edited by
11,573 views

3 Answers

Best answer
52 52 votes

(b) As it is the case of indirect recursion so let first make it a direct recursion then apply rules of removal of left recursion.

to make it a direct recursion first production remains unchanged while in second production substitutes the right-hand side of the first production wherever it comes. In the question $S$ comes in the middle of $A$ so substitute the right-hand side of production $S$.Now after substituting it looks like this:

  • $A \rightarrow  Ac\mid Aad \mid bd \mid \epsilon$

Now remove direct recursion from it

For removal of direct recursion rule:

  • $A \rightarrow A\alpha_1 \mid \ldots \mid A\alpha_n \mid \beta_1 \mid \ldots \mid \beta_m$

Replace these with two sets of productions, one set for $A:$

  • $A \rightarrow \beta_1A^\prime \mid \ldots \mid \beta_mA^\prime$

and another set for the fresh nonterminal $A^{\prime}$  

  • $A^\prime \rightarrow \alpha_1A^\prime \mid \ldots \mid \alpha_nA^\prime \mid \epsilon$

After applying these rules we'll get:

  • $A \rightarrow  bdA'\mid A'$
  • $A' \rightarrow cA'\mid adA' \mid \epsilon$

Now complete production without left recursion is:

  • $S \rightarrow Aa \mid b$
  • $A \rightarrow  bdA'\mid A'$
  • $A' \rightarrow cA'\mid adA' \mid \epsilon$
• edited by
9 9 votes

This is not the usual way for eliminating left recursion. I have find language then applied brain to get grammar :)

8 8 votes
  • S →Aa∣b
  • A →Ac∣Sd∣ϵ

Remove indirect recursion first:-

A-> Ac | Aad | bd |ϵ

I have replace S production with RHS in above . Now we have got the grammer with direct left recursion.

Now let us remove left recursion

S →Aa∣b

A -> bd A' | A'

A' -> cA' | ad A' | ϵ 

• edited by
Position:
Show:

Related questions

17 17 votes
4 answers 4 answers
8.6k
8.6k views
Kathleen asked Sep 26, 2014
8,551 views
Let $G_1 = (N, T, P, S_1)$ be a CFG where, $N=\{S_1, A, B\},T=\{a, b\}$ and $P$ is given by$$\begin{array}{l|l}S_1 \rightarrow a S_1 b &S_1 \rightarrow a B b \\S_1 \right...
27 27 votes
1 answers 1 answer
15.2k
15.2k views
Kathleen asked Sep 26, 2014
15,158 views
Let the attribute ‘$val$’ give the value of a binary number generated by $S$ in the following grammar:$S \rightarrow L.L \mid L$$L \rightarrow LB \mid B$$B \rightarrow 0 ...
29 29 votes
2 answers 2 answers
6.4k
6.4k views
Kathleen asked Sep 26, 2014
6,426 views
An identifier in a programming language consists of up to six letters and digits of which the first character must be a letter. Derive a regular expression for the identi...
37 37 votes
2 answers 2 answers
13.4k
13.4k views
Kathleen asked Sep 25, 2014
13,350 views
Faster access to non-local variables is achieved using an array of pointers to activation records called a stackheapdisplayactivation tree