You are on page 1of 3

Compiler Design Assignment 2021 Department of Computer Science Page 1 Assignment (15pts) Instructions:

 Be in previous group of five members and work on the given questions


 Make your answers neat and clear, unless will not be marked.
 The submission date will be on Monday August 3, 2021. Submit your work in hardcopy.
Questions:

1. Assume you have the following C++ source program to be analyzed by C++ compiler lexical analyzer.
Identify and list down all possible tokens and their lexemes.(4pts)

Token Matching Lexeme


Key word Int
Operator Add
( (
Key word Int
Identifier Op1
Operator +
Key word Int
Identifier Op2
) )
( (
Return Return
Identifier Op1
Operator +
Identifier Op2
) )
Separator ;
) )
Key word Int
Function Main
( (
) )
{ {
Key word Int
Identifier X
Operator =
Num 7
Separator ,
Identifier Y
Operator =
Num 9
Cout Cout
<< <<
“the sum of “ “the sum of”
<< <<
Identifier X
<< <<
“and” “and”
<< <<
Identifier Y
Operator “=”
<< <<
Operator Add
( (
Identifier X
Separator ,
Identifier Y
) )
; ;
Return Return
Num 0
; ;
} }

Use the following table to write your answers. Token Matching Lexeme

2. Consider the following grammar and remove left-recursion and left-factoring from the grammar if any.(4pts)

A → Ba | C

B → AA

C→B|b

3. Consider the grammar from which you have eliminated both problems and the following questions.

a. Parse the string bbbb using recursive-decent parsing to check that the string belongs to the language defined
by the grammar.(2pts)
b. Parse the string bbbb using non-recursive predictive parsing.(2pts) Don’t forget to construct the LL(1)
parsing table of the parser by yourself .(3pts) #include int Add(int op1, int op2) ( return op1+op2; ) int main()
{ int x=7,y=9; cout<<<x<<<y<<

You might also like