Compiler Design: Assignment
1) In the following, a number-string is a non-empty sequence of decimal digits, i.e., something in the
language defined by the regular expression [0-9]+. The value of a number-string is the usual interpretation
of a number-string as an integer number. Note that leading zeroes are allowed. Make for each of the
following languages a regular expression that describes that language.
a) All number-strings that have the value 42.
b) All number-strings that do not have the value 42.
c) All number-strings that have a value that is strictly greater than 42.
2) Construct Transition diagrams for each of the following regular languages. In all cases the alphabet is
{a, b}.
a) The set of strings that has exactly 3 bs (and any number of as).
b) The set of strings where the number of bs is a multiple of 3 (and there can be any number of as).
3) Write a grammar for the language:
All sequences of as and bs that contain the same number of as and bs (in any order).
4) Show that the grammar
A → -A
A → A -id
A → id
is ambiguous by finding a string that has two different syntax trees.
5) Calculate Nullable, FIRST and FOLLOW for the nonterminals A and B in the grammar
A→ BAa
A→ε
B → bBc
B → AA
6) Consider the context-free grammar S SS | SS *| a
a) show that the string aa a * can be generated by this grammar.
b) construct a parse tree for the string.
7) Consider the grammar
S ( L )| a
L L,S |S
a) What are the terminals, non- terminals and start symbol?
b) Find the parse tree for the following sentences
i) ( a, ( a, a )) ii) (a, ((a, a ), (a, a )))
c) Construct the left most derivation for each of the sentences in(b).
d) Construct the right most derivation for each of the sentences in(b).