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}
Given the following knowledge base: a <- b^c. b <- d^e. b <- g^e. c <-...
Given the following knowledge base: a <- b^c. b <- d^e. b <- g^e. c <- e. d. e. ƒ <- a^g. Which of the following would be the trace of resolved atoms assuming a bottoms-up proof procedure? Select one: a. {a,b,c,e,g} b. {a,b,c,e,d} c. {g,e,b,e,c,a} d. None of these options Constraint Satisfaction Problem (CSP) is consists of a set of _________________. Select one: a. Variables, heuristics, and solutions b. Variables, domains, and backtracking c. Variables, domains, and constraints d....
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.
Suppose that A = D + E and that D/A = 0.68. Solve for A/E. Suppose...
Suppose that A = D + E and that D/A = 0.68. Solve for A/E. Suppose that A = D + E and that D/A = 0.24. Solve for D/E. Suppose that D + E = A, that N/A = .15 and that D/A = 0.72. Solve for N/E. Suppose that S/A = 8.4 and N/S = .0925. Solve for N/A. Suppose A – D = E, that N = 21,000, E/A = .75 and N/E = .40. Compute D/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!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT