17.01.2015 Views

Course Notes on Formal Languages and Compilers

Course Notes on Formal Languages and Compilers

Course Notes on Formal Languages and Compilers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

14<br />

Proof Let F = {A∈N: A⇒ + ε}. Assume F can be c<strong>on</strong>structed from G.<br />

(Finding a method is an exercise)<br />

5<br />

10<br />

15<br />

20<br />

25<br />

Let G=(N,T,P,S) <strong>and</strong> G'=(N',T',P',S') where N' = N, T' = T.<br />

S' is obtained from S by:<br />

1) Initializing S' to S.<br />

2) Deleting members of F from elements of S' in all possible ways <strong>and</strong><br />

adding the new elements formed to S'.<br />

e.g., if ABC∈S' <strong>and</strong> A,B,C∈F, then this will result in AB, AC, BC,<br />

A,B,C,ε being added to S'<br />

Similarly P' is obtained from P by:-<br />

1) Initializing P' to P<br />

2) For each rule A→y in P' we examine y <strong>and</strong>, as before, delete<br />

elements of F from y in all possible ways. Let y 1 ,..,y n be the strings<br />

obtained, then add A→y 1 ,.., A→y n , to P'. For example,<br />

if D→ABC is in P' <strong>and</strong> A,B,C,∈F<br />

then add the lollowing rules to P':<br />

D→BC, D→AB, D→AC,<br />

D→A, D→B, D→C, D→ε.<br />

3) Delete all rules of the form A→ε from P'.<br />

The previous result allows us to use the c<strong>on</strong>text sensitive recogniti<strong>on</strong><br />

method for c<strong>on</strong>text free grammars. The next two results will help us in<br />

obtaining improved recogniti<strong>on</strong> methods for c<strong>on</strong>text free grammars.<br />

Lemma: Removing rules of the form A→B<br />

30<br />

35<br />

40<br />

45<br />

Let G be a c<strong>on</strong>text free grammar. Then it is possible to c<strong>on</strong>struct an<br />

equivalent c<strong>on</strong>text free grammar G' having no rules of the form A→B where<br />

A,B∈N' <strong>and</strong> such that L(G')=L(G).<br />

Proof Let G=(N,T,P,S) <strong>and</strong> G'=(N',T',P',S') where N'=N, T'=T, <strong>and</strong> S'=S..<br />

By the previous lemma we may assume there are no rules of the form A→ε.<br />

P' is obtained from P as follows:-<br />

1) P' is initialized to P with rules A→B removed, A,B∈N.<br />

2) If A⇒ + B in G <strong>and</strong> B→y is in P', add A→y to P'<br />

Repeat (2) till nothing further can be added to P'.<br />

<str<strong>on</strong>g>Notes</str<strong>on</strong>g>:<br />

1) The problem of determining if A⇒ + B in G is an exercise.<br />

2) If the grammar G is like a regular grammar but with extra rules of the<br />

form A→B, the above procedure will work without removing rules of the form<br />

A→ε, <strong>and</strong> in this case we obtain a regular grammar G' equivalent to G.

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

Saved successfully!

Ooh no, something went wrong!