# CS606 Assignment 3 Solution and Discussion

• CS606 – Compiler Construction
Assignment # 03
Fall 2019
Total marks = 20

22nd January, 2020

RULES FOR MARKING
It should be clear that your assignment would not get any credit if:
 The assignment is submitted after the due date.
 The submitted assignment does not open or file is corrupt.
 Strict action will be taken if submitted solution is copied from any other student or from the internet.

You should consult the recommended books to clarify your concepts as handouts are not enough.

You are supposed to submit your assignment in .doc or docx format.
Any other formats like scan images, PDF, zip, rar, ppt and bmp etc will not be accepted.

OBJECTIVE
Objective of this assignment is to increase the learning capabilities of the students about
• Context-Free Grammars
• LL(1) Table constructions

NOTE

No assignment will be accepted after the due date via email in any case (whether it is the case of load shedding or internet malfunctioning etc.). Hence refrain from uploading assignment in the last hour of deadline. It is recommended to upload solution file at least two days before its closing date.

If you find any mistake or confusion in assignment (Question statement), please consult with your instructor before the deadline. After the deadline no queries will be entertained in this regard.

For any query, feel free to email at:
[email protected]

Questions No 01 12+8=20 Marks

Consider the grammar given below:

S → XaXb
S → Yb
X → €
Y → €

Where € (epsilon) is empty string.

a) Find First and Follow sets for above grammar. [12]
b) Construct LL (1) parsing table. [8]

Good Luck!

• The FIRST of a sentential form is the set of terminal symbols that lead any sentential from derived from the very first sentential form. In this particular case X and Y only derive the empty string and as a result the empty string is the FIRST set of both non-terminal symbols X and Y. The FIRST of S, however, includes “a” as in the first production once can derive a sentential form that starts with an “a” given that X can be replaced by the empty string. X similar reasoning allows you to include “b” in the FIRST(S).
summary: FIRST(X) = {e}, FIRST(Y) = {e}, FIRST(S) = {a, b}

The FOLLOW set of a non-terminal symbol is the set of terminals that can appear after that non-terminal symbol in any sentential form derived from the grammar’s start symbol. By definition the follow of the start symbol will automatically include the \$ sign which represents the end of the input string. In this particular case by looking at the productions of S one can determine right away that the follow of X includes the terminal “a” and “b” and that the FOLLOW of Y includes the terminal “b”. Given that the non-terminal S does not appear in any productions, not even in its own productions, the FOLLOW of S is only \$.
summary: FOLLOW(S) = {\$}, FOLLOW(X) = {a, b}, FOLLOW(Y) = {b}.

b) YES, because the intersection of the FIRST for every non-terminal symbol in empty. This leads to the parsing table for this LL method as indicated below. As there is no conflict in entry then grammar is clearly LL (1).
[23/01, 21:33] Waqas Ahmad: a b \$
S S→XaXb S → Yb
A X→ε X→ε
B Y→ε

• @ramsha-kanwal

• ab to so hi jana chaye fr

• @Nabeel-Chaudhary w8 kru k so jau?

• mery pas file hai pr mujhy idhr uplod ni krni aa rahi

• @Nabeel-Chaudhary plz send me solution file at [email protected]

• @Nabeel-Chaudhary bhai agr ap k pas file ha to send kr do plz

• @ramsha-kanwal Give me your email or something i will send you a file

• allah hi puchy ga

• bta dy file hai k ni plz

• @ramsha-kanwal File hai hi nahi in k pas

• @zareen This does not make any sense. I also downloaded this type of sketch from internet. Its so confusing. The thing is our assignment is gone.

• plz file send kr dy

5

2

2

1

1

2

2

1
| |