You are on page 1of 4

COMSATS University Islamabad, Wah

Campus
Theory Assignment 2

COMPUTER
Department of: SCIENCE

Due
Class/Program: BS(7-A,C,D) Date: 9 Nov 2022 11:59 AM
Subject: Compiler Construction Instructor: Muhammad Nadeem
Note: copying will lead to ZERO
This is hand written assignment.
You are required to write your Name and Registration Number on top of each
paper of your assignment.
Scan assignment using any scanner tool (like CAMSCANNER), create a pdf ,
and upload to server, prior to due time. PLEASE DO NOT submit Hard Fprm
No email will be accepted, except the students having registration issue.
Parse trees MUST BE NEAT AND CLEAN.
Not following the instructions will lead to marks deduction.

Q1. you are required to convert following regular expression to equivalent


CFG. [CLO-2 PLO-37]
 00 *11*
 (a+b)*abb
 (0+1)*0(0+1)*0(0+1)*
 (b + c)* a (b + c)*
 (a-z)+(cui)(w|a|h)

Q2. Explain what is the purpose of a CFG, what are the basic ingredients of
a CFG, explain each. [CLO-2 PLO-37]

Q3. Consider the following CFG. [CLO-2 PLO-37]


S→ aSa
S→ bSb
S→ c
create parse trees for following input and show that either they are accepted
or rejected.
abbcba, abbcbba, abaccbba, abbbcbbba, abbcbbba, abbbba, abcba, abab
Q4. Consider the following grammar. (S, NP,VP,DET,N,PP,IV,TV,PREP
are all single Non Terminal) [CLO-2 PLO-37]

You are required to create parse trees for following sentences.


 fruit flies like an apple
 the apple eats the giraffe
 the giraffe eats the fruit
 apple fruit like an fruit
 a fruit like flies fruit
 apple flies like a fruit
 apple flies flies like apple

Q5. Consider the following grammar. (S,NP,VP,PP,V,P are non terminal


symbols). [CLO-2 PLO-37]

Create parse trees for following sentences.


 they fish
 they can fish
 pakistan can in december
 they can fish in pakistan
 they can fish in pakistan in december
 they can fish in december in pakistan
 in pakistan fish can in pools
 they fish in rivers in pakistan
 they fish in december
 they fish in pakistan
 they fish in pakistan in december

Q6.Consider the following grammar. (S,NP,VP,Det,Noun,Verb are non


terminal) [CLO-2 PLO-37]

draw parse tree for following sentences.


 These students eats a cake
 the cake eat these students
 a student eats these cakes
 the cake eats a student

You might also like