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.

6<br />

1. LANGUAGES AND GRAMMARS<br />

We shall now formalize the noti<strong>on</strong> of language <strong>and</strong> grammar.<br />

5<br />

10<br />

15<br />

Strings <strong>and</strong> sets of strings<br />

If V is a set, then V* denotes the set of all finite strings of elements of V<br />

including the empty string which will be denoted by ε.<br />

e.g. {0,1}* = {ε, 0, 1, 00, 01, 10, 11, 000, 001,... }<br />

The set of all n<strong>on</strong> empty strings of elements of V is denoted by V+.<br />

Usually, V+ = V* \ {ε}, but when ε∈V, V+ = V*.<br />

e.g. {0,1}+ = {0, 1, 00, 01, 10, 11, 000, 001,... }<br />

but {ε, 0, 1}+ = {0,1}* = {ε, 0, 1, 00, 01, 10, 11, 000, 001,... }<br />

If x∈V* <strong>and</strong> y∈V* then xy will denote their c<strong>on</strong>catenati<strong>on</strong>, that is, the string<br />

c<strong>on</strong>sisting of x followed by y.<br />

20<br />

If x∈V* then x n = xxx.....x<br />

n-times<br />

n≥0<br />

We assume x 0 = ε the empty string.<br />

25<br />

30<br />

e.g. {a}* = {ε, a, a 2 , a 3 , ...a n ,.....} = { a n : n ≥ 0}<br />

{a}+ = {a, a 2 , a 3 , ....a n , ....} = { a n : n ≥ 1}<br />

Similarly, if X, Y are sets of strings, then their c<strong>on</strong>catenati<strong>on</strong> is also denoted<br />

by XY. Of course XY={xy: x∈X <strong>and</strong> y∈Y}.<br />

Also, X n = XXX.....X n≥0. Of course X 0 = {ε}.<br />

n-times<br />

e.g. {0, 1} {a, b, c} = {0a, 0b, 0c, 1a ,1b, 1c}<br />

{0, 1} 3 = {000, 001, 010, 011, 100, 101, 110, 111}<br />

35<br />

If x is a string, then |x| denotes the length of x, <strong>and</strong> this is the number of<br />

indivisible symbols in x. Of course |ε| = 0.<br />

Exercises<br />

40<br />

1) Determine the following sets.<br />

(a) {0,1} {ε, a, ba} (b) {b, aa}*<br />

2) Let V be a set of strings. Does V+ = V V* <br />

45

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

Saved successfully!

Ooh no, something went wrong!