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

Create successful ePaper yourself

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

30<br />

If the automat<strong>on</strong> has an ε - transiti<strong>on</strong> such as B ε A ,<br />

then the grammar rule will be A→B, but this must be removed, as already<br />

explained, so that the grammar will be regular.<br />

5<br />

10<br />

15<br />

20<br />

25<br />

In this way we can c<strong>on</strong>vert between Regular Grammars <strong>and</strong> Finite<br />

Automata in both directi<strong>on</strong>s.<br />

For example, the grammars<br />

automata are:-<br />

G 1 , G 2 corresp<strong>on</strong>ding to the previous two<br />

G 1 = ( { A, B}, {a,b}, P 1 , {A,B} ) where the rules in P 1 are<br />

A→Aa<br />

B→Bb<br />

A→ ε<br />

B→Ab<br />

G 2 = ( {A,B}, {a, b}, P 2 , {B} ) where the rules in P 2 are<br />

A→Aa<br />

B→Bb<br />

A→ε<br />

B→A<br />

<str<strong>on</strong>g>Notes</str<strong>on</strong>g>: 1) G 1 is a backward deterministic regular grammar.<br />

2) Eliminating B→A from G 2 will give us a regular grammar which is<br />

not in backward deterministic form.<br />

More analogies between finite automata <strong>and</strong> regular grammars:<br />

1) ε - transiti<strong>on</strong>s can always be eliminated - similar to removing rules of the<br />

form A→B from grammars.<br />

30<br />

2) A deterministic finite automat<strong>on</strong> has no transiti<strong>on</strong>s of the form<br />

a<br />

A C where B ≠ C.<br />

35<br />

a<br />

B<br />

40<br />

45<br />

It also has no ε - transiti<strong>on</strong>s <strong>and</strong> has at most <strong>on</strong>e initial state. Otherwise,<br />

the finite automat<strong>on</strong> is n<strong>on</strong>-deterministic (The first automat<strong>on</strong> we<br />

presented is deterministic, the sec<strong>on</strong>d is n<strong>on</strong>-deterministic).<br />

Deterministic finite automata corresp<strong>on</strong>d to backward deterministic<br />

regular grammars.

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

Saved successfully!

Ooh no, something went wrong!