CC Midterm FA21
CC Midterm FA21
Course
Ms. Najam Us Sahar Programme Name: BS Computer Science
Instructor/s:
● 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!
Page 2
Name: Reg. No:
Question 1:
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
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)
Page 4
Name: Reg. No:
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
U’
E’
T’
Page 6
Name: Reg. No:
Page 7
Name: Reg. No:
iii. Give detail for how a non-recursive predictive parser will parse the sentence
Page 8