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

Compiler Design Assignment 2021 Department of Computer Science Page 1 Assignment

The document provides instructions for a compiler design assignment. It includes 3 questions - 1) Identify all tokens and lexemes in a C++ source code snippet, 2) Remove left-recursion and left-factoring from a grammar, and 3) Parse strings using recursive descent and LL(1) parsing based on the modified grammar. Students are asked to submit their answers in hard copy by a specified deadline.

Uploaded by

TEGEGN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Compiler Design Assignment 2021 Department of Computer Science Page 1 Assignment

The document provides instructions for a compiler design assignment. It includes 3 questions - 1) Identify all tokens and lexemes in a C++ source code snippet, 2) Remove left-recursion and left-factoring from a grammar, and 3) Parse strings using recursive descent and LL(1) parsing based on the modified grammar. Students are asked to submit their answers in hard copy by a specified deadline.

Uploaded by

TEGEGN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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