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

CC Midterm FA21

The document is the midterm examination for the course Compiler Construction. It contains instructions for the exam, which allows 90 minutes to complete 2 problems worth a total of 25 marks. Students must show their work as partial credit will be given based on both the correctness of answers and clarity of explanations. The exam contains recursive descent parsing and LL(1) parsing questions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

CC Midterm FA21

The document is the midterm examination for the course Compiler Construction. It contains instructions for the exam, which allows 90 minutes to complete 2 problems worth a total of 25 marks. Students must show their work as partial credit will be given based on both the correctness of answers and clarity of explanations. The exam contains recursive descent parsing and LL(1) parsing questions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

COMSATS University Islamabad, Lahore Campus

Midterm Examination – FALL 2021


Course Title: Compiler Construction Course Code: CSC 441 Credit Hours: 3(2,1)

Course
Ms. Najam Us Sahar Programme Name: BS Computer Science
Instructor/s:

Semester: 7th Batch: FA18 Section: A/B Date: 16/11/2021


Time Allowed: 90 Minutes Maximum Marks: 25
Student’s Name: Reg. No.

● Do not open the booklet until you are directed to do so. Read all instructions first.
● Make sure to write your name and registration number on all the pages. Any page without name
and registration number will not be graded.
● The exam contains 2 problems, some with multiple parts. You have 1.5 hour to earn 25 marks.
● The booklet contains 8 pages, including this cover page. Write your solutions in the space
provided. If you run out of space, continue on the backside of the page.
● Calculators are allowed. Cell phones must be put away.
● Read questions carefully and don’t waste time writing/explaining something which is not asked.
● Do not spend too much time on one problem. Generally, a problem’s marks are an indication on
how much time you should spend on it.
● Show all your work, as partial credits will be given. You will be graded not only on the
correctness of your answer, but also on the clarity with which you express it. Please be neat.
● Good luck!

Total Marks Obtained Marks Examiner Signature


25
Name: Reg. No:
- [This page is intentionally left blank] -

Page 2
Name: Reg. No:

Question 1:

a) Give short answers to following questions [9]


i. Suppose One of the Operand is String and other is Integer then it throws error as it only
checks whether there are two operands have same datatype or not. (1)

This operation is done by ___________ phase of compiler

ii. Write a regular expression to accept strings according to the following rules. (3)

Remote file identifiers of the form user@hostname:filename, is constructed as per following rules.
The parts of the identifier are made up of words, which are sequences of one or more letters and
digits. The user part contains a single word e.g. attu. A hostname consists of one or more words
separated by periods, like www.google.com. A filename consists of one or more words separated by
slash ( / ) characters with an optional leading and/or trailing slash (standard Unix conventions). The
user@ part is optional and may be omitted. The entire user@hostname: part may be omitted

Sample string 🡪 [email protected]:compiler/paper/

Page 3
Name: Reg. No:

iii. How many numbers of tokens in following statement? Categorize and name them. Also
identify any error if present (1+2+2)

int foo(int i, int j))


{
for(k=0; i j; )
fi (i < j-2 )
sum = 3sum+int
return sum;
}

Page 4
Name: Reg. No:

b) Write recursive descent parser for following CFG [4]

Prog → { Stmts } Eof


Stmts → Stmt Stmts
Stmts →λ
Stmt → id = Expr ;
Stmt → if ( Expr ) Stmt
Expr → id Etail
Etail → + Expr
Etail → - Expr
Etail →λ

Page 5
Name: Reg. No:

c) Consider the following grammar with left-recursion and common prefixes removed and answer
the following questions [12]

1. P   U
2. U   S U'
3. U'     
4. U'  U
5. S   A ;
6. A   Id = E
7. E   T E'
8. E'   + T E'
9. E'   
10. T   F T'
11. T'   * F T'
12. T'   
13. F   (E) | Id

i. Find First and follow sets (4)


First Set Follow Set

U’

E’

T’

Page 6
Name: Reg. No:

ii. Create LL (1) parsing table.


Note: Write only number of Production Rule as table entries (4)
id = ; + * ( ) $
P
U
U’
S
A
E
E’
T
T’
F

Page 7
Name: Reg. No:
iii. Give detail for how a non-recursive predictive parser will parse the sentence

“ z = b * ( c + d ) ; ” using the table you constructed above. (4)  

Stack input output


z=b*(c+d);

Page 8

You might also like