Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CIS-401: Compiler Construction

Assignments 2 due: May 15, 2024


Each question carries equal 02 points. Total 10 points
Only handwritten and uploaded on canvas files will be accepted
Question no. 1 related to Exercises for Section 2.6, lexical analyzer ,
A) Extend the lexical analyzer in Section 2.6.5 to remove comments, defined as follows:

 A comment begins with // and includes all characters until the end of that line.
 A comment begins with / and includes all characters through the next occurrence of the
character sequence /.

B) Extend the lexical analyzer in Section 2.6.5 to recognize the relational operators <, <=, ==, !
=, >=, >.

C) Extend the lexical analyzer in Section 2.6.5 to recognize floating point numbers such as

2., 3.14, and . 5.

Questions 2 and 3 related to Exercises of Section 3.1

Question no. 2
Divide the following C++ program:

float limitedSquare(x){float x;
/* returns x-squared, nut never more than 100 */
return (x <= -10.0 || x >= 10.0) ? 100 : x*x;
}
into appropriate lexemes, using the discussion of Section 3.1.2 as a guide. Which lexemes should
get associated lexical values? What should those values be?

Question no. 3
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)*)*
Question no. 4
Draw the FA for a language which consists of the tokens: <, <=, =, >=, >, <>, (,), +, -, *, /,:=, ;,
identifier, keywords, constants and literals (which are enclosed in apostrophes). Comments,
which begin with /* and end with a */, and blanks are ignored by the scanner (that is blanks are
treated as blank separator only).

Question no. 5
Design a context-free grammar which generates the mathematical expressions for ‘+’ and ‘-’
operators. Also apply this grammar on algebraic expression “a – b + c” and construct the parse
tree for this string

You might also like