Extra Exercises and Solution for some extra

advertisement
Extra Exercises and Solution for some extra
exercises
Solution to Some Extra Exercises
Describe the languages denoted by the following regular expressions:
i) 0(0|1)*0
Answer
(0|1)* denotes the set of all strings (including the empty string, ) of 0's and 1's.
Therefore, 0(0|1)*0 denotes the set of all strings of 0's and 1's that begin with 0 and end
with another 0.
Note that the beginning 0 and the ending 0 must be distinct, so all strings in this set
(language) have length at least two.
ii) 0*10*10*10*
Answer
Each string in the set (language) denoted by this expression contains exactly three 1's.
Because of the 0*'s at the beginning and end, this allows strings that begin with any
number (including zero) of 0's and end with any number (including zero) of 0's.
Because of the 0*s between the 1's, this allows strings with any number (including
zero) of 0's between the 1's.
Briefly, the language denoted by this regular expression is the set of all strings of 0's
and 1's with exactly three 1's.
Write regular definitions for the following languages.
a) All strings of letters that contain the five vowels in order.
Answer
We allow upper and lower case letters, and we assume that each vowel occurs only
once. We want the following pattern:
zero or more (upper or lower case) consonants
A or a
zero or more (upper or lower case) consonants

zero or more (upper or lower case) consonants
U or u
zero or more (upper or lower case) consonants
We first define consonant as any upper or lower case consonant. We then define
consonants as a string of zero or more instances of consonant. The pattern we want,
here called string, is then easily defined.
consonant ® B | | D | F | | H | J | | N | P | | T | V |W | X | Y | Z |
b | | d | f | | h | j | | n | p | | t | v | w | x | y | z
consonants ® consonants*
string ® consonants (A|a) consonants (E|e) consonants (I|i) consonants (O|o)
consonants (U|u) consonants
b) All strings of letters in which the letters are in ascending order.
Answer
We allow for upper and lower case letters. We take "ascending" to mean "increasing"
so allow at most one occurrence of a letter (upper or lower case). Examples of the
strings allowed are
AbCDevWxyz

aeiou
AbmnYZ
Each such string is generated by considering the letters in alphabetical order and
selecting one of the following three options for each letter:
Don't include it.
Include its upper case version.
Include its lower case version.
Where is the upper case version of the letter , (||) allows the three options.
((||) is equivalent to (|)?.) It remains only to arrange the triple-choices in
alphabetical order. We again call the pattern string.
string ® (A|a|) (B|b|) (Y|y|)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
System Software
MCA Sem IV
Exercise I
Chapter : Scanning and Lexical Analysis
Q-1 Do As Directed
A. identify the lexemes that make up the tokens in the following C program. Give reasonable attribute values for
int max (I , j) int I , j;
/* return maximum of integers I and j */
{
if( I > j ) {
return I;
}
else {
return j;
}
}
B. In a string of length n, how many of the following are there?
a) prefixes
b) substrings
c) subsequences.
C. Describe the languages denoted by the following expressions
i) 0(0|1)*01
ii) 0*10*10*10*
D. Write regular definitions for the following languages
i) All String of digits with no repeated digit
ii) All strings of 0’s and 1’s with an even number of 0’s and an odd number of 1’s
iii) All string of letters that contain the fie vowels in order
iv) Comments consisting of string surrounded by /* and */ without an intervening */ unless it appears inside the q
E. Construct the nondeterministic finite automat for the following regular expressions using Thompson’s NFA co
Show the sequence of moves made by each in processing the input string ababbab
i) (a*|b*)
ii) (a|b)*abb(a|b)*
F. convert the above mentioned NFA of Q-1 e into DFA using the respective Algorithm for NFA to DFA conversion a
moves made by each in processing the input string ababbab.
Download