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.

8<br />

2) P is a finite set of rules (replacement rules, producti<strong>on</strong>s) each of which<br />

has the form x→y where x, y∈(N ∪ T)*.<br />

5<br />

3) S is the starting set (initial set) of the grammar <strong>and</strong> is a finite subset of<br />

(N ∪ T)* that is S ⊆ (N ∪ T)*.<br />

Derivati<strong>on</strong>s <strong>and</strong> language of a Grammar<br />

10<br />

15<br />

Let G=(N,T,P,S) be any phrase structure grammar <strong>and</strong> let u,v∈(N∪T)*. We<br />

write u⇒v <strong>and</strong> say v is derived in <strong>on</strong>e step from u by the rule x→y, providing<br />

that u = pxq <strong>and</strong> v = pyq. (Here the rule x→y is used to replace x by y in u<br />

to produce v. Note that p,q∈(N∪T)*.)<br />

If u 1 ⇒u 2 ⇒u 3 ......⇒ u n we say u n is derived from u 1 in G <strong>and</strong> write u 1 ⇒ + u n .<br />

Also if u 1 =u n or u 1 ⇒ + u n we write u 1 ⇒ * u n<br />

20<br />

25<br />

30<br />

L(G) the language of G is defined by:<br />

L(G) = {t∈T*: Z⇒ * t for some Z∈S}<br />

= {t∈T*:t∈S or Z⇒ + t for some Z∈S}.<br />

So the elements of L(G) are those elements of T* which are elements of S<br />

or which are derivable from elements of S.<br />

Classificati<strong>on</strong> of Phrase Structure Grammars<br />

The following table describes the various types of grammars, <strong>and</strong> their<br />

relative advantages <strong>and</strong> disadvantages. Historically this classificati<strong>on</strong> of<br />

grammars arose because of the need to find efficient recogniti<strong>on</strong> algorithms<br />

for the languages of grammars.

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

Saved successfully!

Ooh no, something went wrong!