Question

In: Computer Science

A → A a b | B d B → b d | b e (upper...

A → A a b | B d

B → b d | b e

(upper cases are nonterminals; lower cases are terminals)

Remove the left recursion in the grammar?

Perform left factoring if there exists some common prefix among choices?

Solutions

Expert Solution

1. To remove left recursion,

A Aa | b (Left recursive grammar)

After removing left recursion,

A bA'

A' aA' |

Apply this on above grammar,

A A a b | B d

B b d | b e

here A Aab has left recusrion, we can write it as a

A B d A'

A' a b A' |

Now no any production rule has left recursion.

The grammar will be,

A B d A' | B d

A' a b A' |

B b d | b e

2. In given grammar there exists left factoring as we have a production rule,

B b d | b e

Here, parser can't decide which production rule must be chosen to parse string in hand.

process to remove left factoring,

A a1 | a2 | a3

will change to

A aA'

A' 1 | 2 | 3

Apply this in above grammar,

A B d A' | B d

A' a b A' |

B b d | b e

Consider A B d A' | B d

After removing left factoring,

A B d X

X A' |

Consider B b d | b e

After removing left factoring,

B b B'

B' d | e

Combining all production rules,we get

A B d X

X A' |

A' a b A' |

B b B'

B' d | e

the grammar withoot left ecursion and left factoring


Related Solutions

Consider the cross: A/a; b/b; C/c; D/d; E/e x A/a; B/b; c/c; D/d; e/e a) what...
Consider the cross: A/a; b/b; C/c; D/d; E/e x A/a; B/b; c/c; D/d; e/e a) what proportion of the progeny will phenotypically resemble the first parent? b) what proportion of the progeny will genotypically resemble neither parent?
Let A = {a, b, c, d} and B = {b, d, e}. Write out all...
Let A = {a, b, c, d} and B = {b, d, e}. Write out all of the elements of the following sets. (a) B ∩ ∅ (b) A ∪ B (c) (A ∩ B) × B (d) P(A\B) (e) {X ∈ P(A) | |X| ≤ 3}
Find the proof of the following ((a ∧ b) ∨ (c ∧ d)), (a → e),...
Find the proof of the following ((a ∧ b) ∨ (c ∧ d)), (a → e), (b → f), (c → f), (d → e) ⊢ e
please i need the solve for A&B&C&D&E ESPECIALLY B&C&D&E Company Information Wood Work Ltd manufacture specialist...
please i need the solve for A&B&C&D&E ESPECIALLY B&C&D&E Company Information Wood Work Ltd manufacture specialist wood furniture and sell their products all over Saudi  Arabia. The company was established three  years ago in Jeddah and is performing well to date. Wood work Ltd have three main product lines; TV tables, dining table and chairs. The following financial information has been provided.   Financial Information TV tables dining Tables Chairs Selling Price per unit SAR 1,000 SAR 5,000 SAR 700 Direct Materials (wood...
There are four critical paths in a network. A-B-C-D-E, A-F-E, A-B-H-J-K-E and A-S-T-E. Each activity in...
There are four critical paths in a network. A-B-C-D-E, A-F-E, A-B-H-J-K-E and A-S-T-E. Each activity in this network can be crashed by a maximum of 2 weeks. The crashing cost (per week), for the first week, for activity A is: $540, E is $545 and all other activities is : $135 (per week per activity). The crashing cost, second week and onwards, for activity A is $1080 per week, E is $1350 per week and for all other activities is...
Suppose that D and E are sets, and D ⊆ E. Let A = P(E). Recall...
Suppose that D and E are sets, and D ⊆ E. Let A = P(E). Recall that P(E) denotes the set of all subsets of E. Define a relation R on A by R = {(X, Y) ∈ A × A: [(X − Y) ∪ (Y − X)] ⊆ D}. So, XRY if and only if [(X−Y) ∪ (Y −X)] ⊆ D. Prove that R is an equivalence relation on A.
Find A, B, C, D, E such that the rule Af(a − 2h) + Bf(a −...
Find A, B, C, D, E such that the rule Af(a − 2h) + Bf(a − h) + Cf(a) + Df(a + h) + Ef(a + 2h) approximates f"'(a) with the error O(h^p) for the largest order of convergence p. What is this p equal to? Please be clear and show all steps, thanks!
Find A, B, C, D, E such that the rule Af(a − 2h) + Bf(a −...
Find A, B, C, D, E such that the rule Af(a − 2h) + Bf(a − h) + Cf(a) + Df(a + h) + Ef(a + 2h) approximates f"'(a) with the error O(h^p) for the largest order of convergence p. What is this p equal to? Please be clear and show all steps, thanks!
If there are 7 total notes C, D, E, F, G, A, and B and if...
If there are 7 total notes C, D, E, F, G, A, and B and if a five-note melody is selected at random (so that all melodies counted in part (a) are equally likely to be chosen), what is the probability that the melody will include exactly two “A” notes, but no other repeated notes? (A few allowable examples: AACEG, ACAEG, DFACA, EAABC, etc.)
1) Provide a set of payoffs in this format a, b      |    c, d e,...
1) Provide a set of payoffs in this format a, b      |    c, d e, f     |     g, i for a 2x2 game that illustrated the problem of free access to guns. 2) Provide a set of payoffs in this format a, b      |    c, d e, f     |     g, i for a 2x2 version of the Battle of the Sexes. 3. In what sense is the Battle of the Sexes a "social dilemma"?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT