Docsity

Homework on Regular Languages and BNF Definitions, Assignments of Programming Languages

Toggle sidebar
bg1
22C:111 — Fall 2005
page 1 of 2
Homework I
1. [15 points]
Take character set C = {a, b}, and languages S = {b, aba} and T = {e, bb}.
(a) what is the language T2?
(b) what is the language T*?
(c) what is the language S•T*? [note: this means S•(T*) not (S•T)*]
(d) what is the language (S•T)*?
(e) what is the language (S*)*?
2. [20 points]
Take character set C = {a, b}, and consider languages R = { a2}* (infinite -- all
even nos. 'a'), S = {a}•{ a2}* (infinite -- all odd nos. 'a'). Justify your answers to
each of the following questions:
(a) what is the language R»S?
(b) what is the language R•S?
(c) what is the language R*?
(d) what is the language S*?
3. [30 points]
For C = {a, b}, write a regular expression that describes each of the languages
below, and justify that your answer describes exactly the required strings --
these are set equality demonstrations, every required string must be described
by your regular expression, and
no
other string can be.
(a) {e, a3, a5, a6, a9, a10, a12, a15, … } -- all and only strings of 'a's whose
length is either a multiple of 3 or a multiple of 5
(b) all and only strings that either (i) begin with 'aa' and have no 'a' following a
'b', or (ii) begin with 'bb' and have no 'b' following an 'a'
(c) {a, a2, a4, a5, a7, a8, … } -- all and only strings of 'a's whose length is not a
multiple of 3.
4. [15 points]
For the BNF definition X ::= b | aaaXa | aaXaa, determine whether or not the
string below is in L(X), and justify your answer — either a derivation if yes, or
what makes it impossible if no.
(a) a7ba5
(b) a6ba4
(c) a8ba4
pf2

Partial preview of the text

Download Homework on Regular Languages and BNF Definitions and more Assignments Programming Languages in PDF only on Docsity!

22C:111 — Fall 2005

page 1 of 2

Homework I

1. [15 points]

Take character set C = {a, b}, and languages S = {b, aba} and T = {e, bb}.

(a) what is the language T

2

?

(b) what is the language T

(c) what is the language S•T

? [note: this means S•(T

) not (S•T)

]

(d) what is the language (S•T)

(e) what is the language (S

2. [20 points]

Take character set C = {a, b}, and consider languages R = { a

2

}* (infinite -- all

even nos. 'a'), S = {a}•{ a

2

}* (infinite -- all odd nos. 'a'). Justify your answers to

each of the following questions:

(a) what is the language R»S?

(b) what is the language R•S?

(c) what is the language R

(d) what is the language S

3. [30 points]

For C = {a, b}, write a regular expression that describes each of the languages

below, and justify that your answer describes exactly the required strings --

these are set equality demonstrations, every required string must be described

by your regular expression, and no other string can be.

(a) {e, a

3 , a

5 , a

6 , a

9 , a

10 , a

12 , a

15 , … } -- all and only strings of 'a's whose

length is either a multiple of 3 or a multiple of 5

(b) all and only strings that either (i) begin with 'aa' and have no 'a' following a

'b', or (ii) begin with 'bb' and have no 'b' following an 'a'

(c) {a, a

2 , a

4 , a

5 , a

7 , a

8 , … } -- all and only strings of 'a's whose length is not a

multiple of 3.

4. [15 points]

For the BNF definition X ::= b | aaaXa | aaXaa, determine whether or not the

string below is in L(X), and justify your answer — either a derivation if yes, or

what makes it impossible if no.

(a) a

7

ba

5

(b) a

6

ba

4

(c) a

8

ba

4

22C:111 — Fall 2005

page 2 of 2

5. [20 points]

Given the BNF definition X ::= e | XaXbX, determine whether or not each of the

following strings are in L(X) and justify your answer -- either a derivation if yes, or

what makes it impossible if no.

(a) aabbab

(b) abaaab

(c) abbaab

(d) aaabbb