19.05.2013 Views

Chapter 3 Context-Free Grammars, Context-Free Languages, Parse ...

Chapter 3 Context-Free Grammars, Context-Free Languages, Parse ...

Chapter 3 Context-Free Grammars, Context-Free Languages, Parse ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

44 CHAPTER 3. CONTEXT-FREE GRAMMARS AND LANGUAGES<br />

We claim that G ′ =(V1, Σ,P2 ∪ P3,S1) satisfies the conditions of the lemma. For example,<br />

S1 does not appear on the right-hand side of any production, since the productions in P3<br />

have right-hand sides from P1, andS1does not appear on the right-hand side in P1. It is<br />

also easily shown that L(G ′ )=L(G1) =L(G).<br />

Let us apply the method of lemma 3.3.2 to the grammar<br />

where P is the set of rules<br />

G3 =({E,T,F,+, ∗, (, ),a}, {+, ∗, (, ),a},P,E),<br />

E −→ E + T,<br />

E −→ T,<br />

T −→ T ∗ F,<br />

T −→ F,<br />

F −→ (E),<br />

F −→ a.<br />

We get IE = {T,F}, IT = {F }, andIF = ∅. The new grammar G ′ 3 has the set of rules<br />

E −→ E + T,<br />

E −→ T ∗ F,<br />

E −→ (E),<br />

E −→ a,<br />

T −→ T ∗ F,<br />

T −→ (E),<br />

T −→ a,<br />

F −→ (E),<br />

F −→ a.<br />

At this stage, the grammar obtained in lemma 3.3.2 no longer has ɛ-rules (except perhaps<br />

S ′ → ɛ iff ɛ ∈ L(G)) or chain rules. However, it may contain rules A → α with |α| ≥3, or<br />

with |α| ≥2andwhereα contains terminals(s). To obtain the Chomsky Normal Form. we<br />

need to eliminate such rules. This is not difficult, but notationally a bit messy.<br />

Lemma 3.3.3 Given a context-free grammar G =(V,Σ,P,S), one can construct a contextfree<br />

grammar G ′ =(V ′ , Σ,P ′ ,S ′ ) such that L(G ′ )=L(G) and G ′ is in Chomsky Normal<br />

Form, that is, a grammar whose productions are of the form<br />

A → BC,<br />

A → a, or<br />

S ′ → ɛ,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!