0% found this document useful (0 votes)
12 views

Tutorial 1

Uploaded by

Meghana K
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Tutorial 1

Uploaded by

Meghana K
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Date:

Ramaiah Institute of Technology


(Autonomous Institute, Affiliated to VTU)
Department of Computer Science and Engineering(AI&ML)

Subject: Automata Theory and Compiler Design Subject code: CI53/CY53

Tutorial 1

I. Describe the languages denoted by the following regular expressions:

1. a(a|b)*a

2. ((ε|a)b*)*

3. (a|b)*a(a|b)(a|b)

4. a*ba*ba*ba*

5. (aa|bb)*((ab|ba)(aa|bb)*(ab|ba)(aa|bb)*)*

Answer
1. String of a's and b's that start and end with a.
2. String of a's and b's.

3. String of a's and b's that the character third from the last is a.

4. String of a's and b's that only contains three b.

5. String of a's and b's that has a even number of a and b.

II. Most languages are case sensitive, so keywords can be written only one way, and
the regular expressions describing their lexeme is very simple. However, some
languages, like SQL, are case insensitive, so a keyword can be written either in
lowercase or in uppercase, or in any mixture of cases. Thus, the SQL keyword
SELECT can also be written select, Select, or sElEcT, for instance. Show how to
write a regular expression for a keyword in a case insensitive language. Illustrate
the idea by writing the expression for "select" in SQL.

Answer
select -> [Ss][Ee][Ll][Ee][Cc][Tt]

OR

Select(S|s)(E|e)(L|l)(E|e)(C|c)(T|t)

III. Write regular definitions for the following languages:

Mrs. Sini Anna Alex, Assistant Professor, Dept of CSE(AI&ML), RIT


1. All strings of lowercase letters that contain the five vowels in order.

2. All strings of lowercase letters in which the letters are in ascending lexicographic
order.

3. Comments, consisting of a string surrounded by /* and */, without an intervening */,


unless it is inside double-quotes (")

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

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

Answer
1、

want -> other* a (other|a)* e (other|e)* i (other|i)* o (other|o)* u (other|u)*


other -> [bcdfghjklmnpqrstvwxyz]

2、

a* b* ... z*

3、

\/\*([^*"]*|".*"|\*+[^/])*\*\/

b*(a+b?)*
5、

b* | b*a+ | b*a+ba*

IV. Write character classes for the following sets of characters:

1. The first ten letters (up to "j") in either upper or lower case.

2. The lowercase consonants.

3. The "digits" in a hexadecimal number (choose either upper or lower case for the
"digits" above 9).

4. The characters that can appear at the end of alegitimate English sentence (e.g. ,
exclamation point) .

Answer
1. [A-Ja-j]

Mrs. Sini Anna Alex, Assistant Professor, Dept of CSE(AI&ML), RIT


2. [bcdfghjklmnpqrstvwxzy]

3. [0-9a-f]

4. [.?!]

V. Note that these regular expressions give all of the following symbols (operator
characters) a special meaning:

\ " . ^ $ [ ] * + ? { } | /

Their special meaning must be turned off if they are needed to represent themselves in a
character string. We can do so by quoting the character within a string of length one or more;
e.g., the regular expression "**" matches the string ** . We can also get the literal meaning of
an operator character by preceding it by a backslash. Thus, the regular expression \*\* also
matches the string **. Write a regular expression that matches the string "\.

Answer
\"\\

VI. The operator ^ matches the left end of a line, and $ matches the right end of a line.
The operator ^ is also used to introduce complemented character classes, but the
context always makes it clear which meaning is intended. For example,
^[^aeiou]*$ matches any complete line that does not contain a lowercase vowel.

1. How do you tell which meaning of ^ is intended?

Answer:
if ^ is in a pair of brackets, and it is the first letter, it means complemented classes, or it means the
left end of a line.

VII. Construct transition diagram for the following


1. who, when, what, why, whom
2. arithmetic operators

who, when, what, why, whom

Mrs. Sini Anna Alex, Assistant Professor, Dept of CSE(AI&ML), RIT


o other *
start w h return (who,”who”)
0 1 2 3 4
a e m
y return
7 5 (whom,”whom”)
9 6
n return (why,”why”)
t
1
return (what,”what”) 8 return (when,”when”)
0

Arithmetic operators

+
return (arithop, ‘+’)
0 1
-
return (arithop, ‘-’)
* 2
% /

3 return (arithop, ‘*’)


5 4
return (arithop, ‘%’)
return (arithop, ‘/’)

Mrs. Sini Anna Alex, Assistant Professor, Dept of CSE(AI&ML), RIT

You might also like