Set_A_Questions
Set_A_Questions
A2 Write a program to design Lexical Analyzer in C/C++ Language (to recognize any five
keywords, identifiers, numbers, operators and punctuations).
Outcome: It gives the students a feel of how a lexical analyzer for a typical regular language is
written.
A4 Write a program in LEX to recognize different tokens: Keywords, Identifiers, Constants, Operators and
Punctuation symbols.
Outcome: It gives the students, a knowledge of using LEX tool to recognize all kinds of tokens
of C language.
A5 Write a LEX program that copies a file, replacing each nonempty sequence of white spaces by a single
blank.
Outcome: It makes the students to know how a LEX tool can be used in general to process the
text.
A6 Write a LEX program that converts a file to “Pig Latin”. Specifically, assume the file is containing a
sequence of words (groups of letters) separated by white space. Every time you encounter a word:
(a) If the first letter is a consonant, move it to the end of the word and then add ay.
(b) If the first letter is a vowel, just add ay to the end of the word. All non-letters are copied intact to the
output.
Outcome: It makes the students to know how a LEX tool may be used to process the content of
files.
1
A7 Write a LEX program to recognize the following tokens over the alphabets {0,1,..,9}
a) The set of all string ending in 00.
b) The set of all strings with three consecutive 222’s.
c) The set of all string such that every block of five consecutive symbols contains at least two 5’s.
d) The set of all strings beginning with a 1 which, interpreted as the binary representation of an
integer, is congruent to zero modulo 5.
e) The set of all strings such that the 10th symbol from the right end is 1.
f) The set of all four digits numbers whose sum is 9
g) The set of all four digital numbers, whose individual digits are in ascending order from left to
right.
Outcome: It will provide students with how to write regular expressions for different patterns.
A8 “The auxiliary procedure part of a LEX program can be complied separately and loaded with lexical
analyzer”. Test and show that, the given statement is valid.
Outcome: This assignment provides the insight of how a LEX compiler works and how to
manage the lengthy code written in LEX language.
A10 Suppose an image is encoded as an n×m matrix M of ''light intensities.'' Mij is a number from 0 to 15,
with 0=black and 15=white. M may be stored row by row, with rows terminated by newline (n)
characters. Call this string vM. For example, if M is
0 0 2 6
0 1 4 7
1 8 8 6
then vM is 0026 n 0147 n 1886. We can also encode M by its differences along rows, dM. For Example,
for M above dM is 0+2+4 n +1+3+3 n+70-2. If we replace positive numbers by + and negative numbers
by - in dM we get the sequence of changes, d'M. In this case, d'M=0++ n +++ n +0-. Suppose a ‘feature’
is defined to be a nonempty sequence of increasing value of intensity, followed by zero to three
unchanging value of intensity followed by at least one decreasing value of intensity, all on one row.
a. Write a LEX program to find maximal features in d'M and surround them by parentheses. A
maximal feature is not a proper substring of any other feature.
b. Display the longest maximal feature of each row.
Outcome: Students can learn how to apply the knowledge about various components of a
compiler in other domains as well. Here it is shown how a lexical analysis process can be used
to solve an image processing problem.