Download - Assignment 1 2015

Transcript

C O M P I L E R D E S I G N

ASSIGNMENT I

Floating date: 26th Feb 15

Submission date: 16th March 15Exercise 1: Describe the languages denoted by the following regular expressions:

a) a* ba* ba* ba* .

b) (a+b) + ab (a+b) *Exercise 2: Write regular definitions for the following languages:

a) All strings of a's and b's with an even number of a's and an odd number of b's.

b) All strings of a's and b's that do not contain the substring abb.

c) All strings of a's and b's that do not contain the subsequence abb.

Exercise 3: Design finite automata (deterministic or nondeterministic) for each of the languages of Exercise 2.Exercise 4: Convert the following regular expressions to deterministic finite automata, using algorithms:

a* ba* ba* ba+Exercise 5: Consider the context-free grammar:

S( SS+ | SS* |a

and the string aa+a*.

a) Give a leftmost derivation for the string.

b) Give a rightmost derivation for the string.

c) Give a parse tree for the string.

d) Is the grammar ambiguous or unambiguous? Justify your answer.

e) Describe the language generated by this grammar.

Exercise 6: Repeat Exercise 5 for each of the following grammar and strings:

a) S ( +S S | * S S | a (with string +*aaa ).

b) S ( S (S) S | ( with string (()()) ).

c) S ( aSbS | bSaS | ( with string aabbab ).

Exercise 7: Compute FIRST and FOLLOW for the grammar of Exercise 5 and 6.