Cat1 Model1
Cat1 Model1
Cat1 Model1
2. (a) A new programming language is being designed that includes decimal numbers with [4]
no exponent. A decimal number has a period to separate the integer and fractional parts of the number and must
have at least one digit both before and after the decimal point. Furthermore, a decimal number must not have any
superfluous leading or trailing 0’s. Some examples of legal decimal numbers are 3.14, 0.01, 17.0, 0.0,
123.00321. Some examples of illegal decimal numbers are 00.0, .5, 17, 17., 003.01, 0.0012300 (this last
example is illegal because of the trailing 0’s; the 0 before the decimal point is required).
Write a regular expression (or collection of regular expressions) to generate legal decimal numbers.
(b) There are two rooms A and B with lights, but with a single control switch for both [6]
rooms. Hence lights in rooms are both on or both off at any point. The goal is to build an automatic control
system that manages this switch. There is a sensor that detects motion in the two rooms and sends data to the
controller; the controller reads these two signals and then instructs whether the switch should be turned on or off.
We would like the controller to turn the lights on when motion is detected in either room, and turns them off if
both rooms are empty for two consecutive signals from the sensor. Assume that the system starts from the state
when lights are off. The sequence of events and actions is represented by the alphabet Σ = {yes,no,on,off}.
Sequences accepted are of the form: r1 s1 t1 r2 s2 t2 ... rn sn tn where each ri ∈ {yes,no} and stands for the signal
coming from Room A, each si ∈ {yes,no} stands for the signal coming from room B, and each ti ∈ {on,off} stands
for the instruction the controller gives to the switch.
Design a DFA that accepts precisely the sequences that conform to the behavior of the controller. Example of
good sequences:
(a) no, no, off
(b) yes, yes, on, yes, no, on, no, no, on, no, no, off
(c) no, yes, on, no, no, on, no, yes, on
(d) yes, no, on, no, no, on, no, yes, on
Example of bad sequences:
(a) yes, no, on, no
(b) no, no, yes
(c) yes, yes, off
Page 1 of 2
3. (a) Consider the set of strings on {0,1} in which, every substring of 3 symbols has at [4]
most two zeros. For example, 001110 and 011001 are in the language, but 100010 is not. All strings of length
less than 3 are also in the language. A partially completed DFA that accepts this language is shown below.
(Without proper justification no marks will be given)
(b) The symmetric difference of languages L and M, which we shall denote SD(L,M), [6]
is the set of strings that are in exactly one of L and M. For example, if L = {00, 101} and
M = {11, 00}, then SD(L,M) = {11, 101}.
(a) Suppose L = L(0*1*) and M = L(1*0*). What are all the strings of length 3 or
less in SD(L,M)?
(b) Write a regular expression for SD(L,M).
(c) Write a formula for SD(L,M) in terms of familiar operations
4. (a) Give state diagrams of NFAs with the specified number of states recognizing each of the following languages.
In all parts the alphabet is {0,1}. [4]
(a) The language {w | w ends with 001 with three states}
(b) The language 1*(001+)* with three states
(b) For languages A and B, let the shuffle of A and B be the language {w |w = a 1b1···akbk, [6]
where a1···ak ∈A and b1···bk ∈B, each ai,bi ∈Σ∗}. Show that the class of regular languages
is closed under shuffle.
5. (a) Give the formal idea for the following statements: [6]
(a) Prove that if we add a finite set of strings to a regular language, the result is a regular language.
(b) Prove that if we remove a finite set of strings from a regular language, the result is a regular
language.
(c) Prove that if we add a finite set of strings to a nonregular language, the result is a nonregular
language
(b) For the given expression id=(id1*id2)-(id3*id4) show the output of syntax, semantic, code
optimization phase of the compiler? [4]
Page 2 of 2