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.

34<br />

So clearly L 0 ij can be defined by a regular expressi<strong>on</strong> for all i, j.<br />

5<br />

Inductive step: Let us suppose that all the sets L k ij can be defined by a<br />

regular expressi<strong>on</strong>.<br />

What about the sets L (k+1) ij <br />

10<br />

15<br />

In fact L (k+1) ij = L k ij | (L k i (k+1) (L k (k+1) (k+1))* L k (k+1) j)<br />

which is in fact is a regular expressi<strong>on</strong> built from the regular expressi<strong>on</strong>s for<br />

L k ij.<br />

Hence by inducti<strong>on</strong>, L k ij can be defined by a regular expressi<strong>on</strong> for<br />

k = 0,1,2...m.<br />

Now recall that A e is the <strong>on</strong>ly n<strong>on</strong> terminal for which A e →ε <strong>and</strong> that<br />

S ={A 1 , A 2 , .....A s }<br />

20<br />

25<br />

30<br />

35<br />

40<br />

So L(G) = {t∈T*: A j ⇒*t for 1≤ j ≤s}<br />

= {t∈T*: A j ⇒*A e t⇒t for 1≤ j ≤s}<br />

(This is because the last step must use A e →ε.)<br />

= L m e1 | L m e2 ... | L m es<br />

which is a regular expressi<strong>on</strong>.<br />

Q.E.D.<br />

Exercise: It is highly desirable not to c<strong>on</strong>vert the grammar to backward<br />

deterministic form in the above, as the set c<strong>on</strong>structi<strong>on</strong> can create large<br />

grammars. Explain how you would rewrite the previous proof without having<br />

to assume that the grammar is backward deterministic.<br />

Hint: Assume that that the n<strong>on</strong> terminals are numbered A 1 , A 2 , ..., A m in<br />

such a way that S = {A 1 , ..., A s } <strong>and</strong> {A: A→ε} = {A e , A e+1 , ..., A f }. Why is this<br />

always possible Now how do we proceed<br />

Example: C<strong>on</strong>sider the grammar G=( {A 1 , A 2 }, {d}, P, {A 1 } ) where P c<strong>on</strong>sists<br />

of<br />

A 1 →A 1 d A 1 →A 2 d A 2 →ε<br />

G is backward deterministic <strong>and</strong> the n<strong>on</strong> terminals are numbered as<br />

required by the theorem. Of course m = 2, e = 2, s=1.

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

Saved successfully!

Ooh no, something went wrong!