SlideShare a Scribd company logo
Page 1 of 5
Cairo University
Faculty of Computers and Information
Final Exam
Department: CS
Course Name: Compilers Date: Tuesday 4-June-2013
Course Code: CS419 Duration: 2 hours
Instructor(s): Dr. Hussien Sharaf Total Marks: 60
Question 1 [12 marks]
For each of the following languages do the following:
i. Understand the languages without any assistance;
ii. Write sample words for the language where you show the smallest possible word.
iii. Construct a regular expression that represents the language.
Note: Draw and fill the following table in your answer sheet:
Sample Regular Expression
a. Σ ={a, b} Only words with exactly two consecutive a's [2 marks]
Solution:
Sample = {aa, aab, baa, baab, bbaabbb …..}
b*aab*
b. Σ ={a, b} Only words such that { an
bm
| n is even and m is odd} where n and m indicate number
of “a”s and “b”s respectively. [3 marks]
Solution:
Sample = {b,aab,aabbb,..}
(aa)* b(bb)* + (aa)* a (bb)* b
c. Σ ={a, b} Words where “a” appears ONLY in even positions or doesn’t appear at all. [3 marks]
Solution:
Sample = { Λ b ba bbb bbba baba …..}
b+(bb+ba)*b*
(b(a+b))* + b*
(ba)*(bb)*(ba)*
b* + (b(bb)* (a+b) )*
d. Σ ={a, b} Construct a regular expression for all strings that have exactly one double letter in
them. “One double letter” implies two equal touching letters; triples or more are excluded. [4 marks]
Solution:
Sample = { aa, baa, …..}
(b + Λ)(ab)*aa(ba)*(b + Λ) + (a + Λ)(ba)*bb(ab)*(a + Λ)
Question 2 [8 marks]
For each of the following languages do the following:
i. Understand the languages without any assistance;
ii. Write sample words for the language where you show the smallest possible word.
iv. Draw a deterministic finite automaton that represents the language and handles incorrect
inputs.
Page 2 of 5
a. Σ = {a, b} words where “a” appears ONLY in the second position or doesn’t appear at all. [3 marks]
Solution:
Sample = { Λ b ba bbb bab babbb …..}
b. Σ = {a, b} Words that begin and ending with the same letter. [5 marks]
Solution:
Sample = { Λ b ba bbb bab babbb …..}
Question 3 [10 marks]
An if-statement indicated by L is a language where multiple executable instructions “S” can be used only
by embedding them inside curly brackets pair where execution starts with the inner curly brackets pair;
i.e. {{{S1}S2}S3} means executing s1, s2 then s3. One statement can only be embedded inside one curly
bracket pair where the statement “S” should always stick to the closing curly bracket. Finally a curly
bracket pair must always contain a statement i.e. { {S} } is NOT valid.
Sample for if-statement in L:
if ((c4) OR (c5 AND c6))
{{{s1}s2}s3}
else
{{s5}s6}
a. Understand the language without any assistance and check if the following grammar represents
the conditional statements “C” indicated by L. If NO then explain why? If YES then show left
derivation for “((C4) OR (C5 AND C6))”; Do each step in a separate line and show rule
number. [3 marks]
R1: C→(C)
R2: C→C AND C
R3: C→C OR C
R4: C→c1|c2|c3|c4|c5|c6| …|c10
Note: Draw and fill the following table in your answer sheet:
a
b
b
-+1 2
a,b
+3
a
a
-+1
b
4
a
b
3
a
+2
b
b
a
a
5
b
+4
Page 3 of 5
Derivation Rule Number
Solution:
YES
Derivation Rule Number
C →(C) R1
→(C OR C) R3
→((C) OR C) R1
→((c4) OR C) R4
→((c4) OR (C)) R1
→((c4) OR (C AND C)) R2
→((c4) OR (c5 AND C)) R4
→((c4) OR (c5 AND c6)) R4
b. Write a CFG for the instructions “S” similar to the CFG of the “C”. Can you avoid using
Lambda? [4 marks]
Solution:
R1: S→{ST}
R2: S→Λ
R3: T→s1|s2|s3|s4|s5|s6| …|s10
Λ must be used to recursion of S
c. Can language L be described using regular expressions? Why? [3 marks]
Solution:
• No.
• Because L have nested structures brackets and parenthesis that must be balanced. RE cannot
describe balanced structures such as an
bn
Question 4 [30 marks]
Ζ delta is a language that allows for nested if-statements L, executable expressions “E” and conditional
statements “C”.
CFG:
R1: Z →E
R2: Z →L
R3: L →if C Z
R4: L →if C Z else Z
R5: C→(C)
R6: C→N and N
R7: E →id = N * N
R10: N→ 0
R11: N→ 1
Sample for a Z statement:
if (0 and 1) if (0 and 0) id = 1*1
a. Specify which pair of rule(s) contains the left factoring and rewrite all the CFG with numbers
(after removing left factoring) factoring? Hint: if you need to introduce a new variable then use
letter M. [3 marks]
Solution:
R3 and R4
CFG:
• R1: Z →E
• R2: Z →L
Page 4 of 5
• R3: L→ if C Z M
• R4:M→Λ
• R5:M→ else Z
• R6: C→ (C)
• R7: C→N and N
• R8: E →id = N * N
• R9: N→ 0
• R10: N→ 1
b. Construct a parsing table for Z. Note that the set of terminals is {if, else, (,),id=,*, and, 0,1} and
set of non-terminals is {Z, E, L, M, C, N} [3 marks]
Solution:
If else ( ) and id = * 0 1 $
Z R2 R1
E R8
L R3
M R5 R4 R4 R4
C R6 R7 R7
N R9 R10
c. Show the top-down parsing steps of the sample above using the parsing table constructed in the
previous section. [16 marks]
Solution:
Stack Input Parser action
Z if (0 and 1) if (0 and 0) id = 1*1
$
R2
L .. R3
if C Z M if .. Match
C Z M (0 and 1) .. R6
(C) Z M (0 and 1) .. Match
C) Z M 0 and 1) .. R7
N and N) Z M 0 and 1) .. R9
0 and N) Z M 0 and 1) .. Match
N) Z M 1) … R9
1) Z M 1) if (0 and 0) id = 1*1 $ Match
Z M if (0 and 0) id = 1*1 $ R2
L M if (0 and 0) id = 1*1 $ R3
if C Z M M if (0 and 0) id = 1*1 $ Match
C Z M M (0 and 0) id = 1*1 $ R6
(C) Z M M (0 and 0) id = 1*1 $ Match
C) Z M M 0 and 0) id = 1*1 $ R7
N and N) Z M M 0 and 0) id = 1*1 $ R9
0 and N) Z M M 0 and 0) id = 1*1 $ Match
N) Z M M 0) id = 1*1 $ R9
0) Z M M 0) id = 1*1 $ Match
Z M M id = 1*1 $ R1
E M M id = 1*1 $ R8
id = N * N M M id = 1*1 $ Match
N * N M M 1*1 $ R10
1 * N M M 1*1 $ Match
N M M 1 $ R10
1 M M 1 $ Match
M M $ R4
M $ R4
Page 5 of 5
Empty $ Accept
d. Show the 10 steps for bottom-up parsing of the sample above. [10 marks]
Solution:
Stack Input Action
$ if (0 and 1) if (0 and 0) id = 1*1
$
Shift
$if (0 and 1) … Shift
$if( 0 and 1) …. Shift
$if(0 and 1) …. Reduce R9
$if(N and 1) …. Shift
$if(N and 1) …. Shift
$if(N and 1 ) if (0 and 0) id = 1*1 $ Reduce R10
$if(N and N ) if (0 and 0) id = 1*1 $ Reduce R7
$if(C ) if (0 and 0) id = 1*1 $ Shift
$if(C) if (0 and 0) id = 1*1 $ Reduce R6
$if C if (0 and 0) id = 1*1 $ Shift
$if C if (0 and 0) id = 1*1 $ Shift
$if C if( 0 and 0) id = 1*1 $ Shift
$if C if(0 and 0) id = 1*1 $ Reduce R9
$if C if(N and 0) id = 1*1 $ Shift
$if C if(N and 0) id = 1*1 $ Shift
$if C if(N and 0 ) id = 1*1 $ Reduce R9
$if C if(N and N ) id = 1*1 $ Reduce R7
$if C if(C ) id = 1*1 $ Shift
$if C if(C) id = 1*1 $ Shift
$if C if(C) id = 1*1 $ Reduce R6
$if C if C id = 1*1 $ Shift
$if C if C id 1*1 $ Shift
$if C if C id = 1*1 $ Shift
$if C if C id = 1 *1 $ Reduce R10
$if C if C id = N *1 $ Shift
$if C if C id = N * 1 $ Shift
$if C if C id = N * 1 $ Reduce R10
$if C if C id = N * N $ Reduce R8
$if C if C E $ Reduce R1
$if C if C Z $ Reduce R4
$if C if C Z M $ Reduce R3
$if C L $ Reduce R2
$if C Z $ Reduce R4
$if C Z M $ Reduce R3
$ L $ Reduce R2
$Z $ Accept

More Related Content

What's hot

Micro teaching junior high school
Micro teaching junior high schoolMicro teaching junior high school
Micro teaching junior high school
mengejar impian menuju kota kesuksesan
 
K map
K mapK map
Conversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad balochConversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad baloch
Sarmad Baloch
 
Chapter 1 review (algebra) (UPDATED for A.C.)
Chapter 1 review (algebra) (UPDATED for A.C.)Chapter 1 review (algebra) (UPDATED for A.C.)
Chapter 1 review (algebra) (UPDATED for A.C.)
Algebra / Mathematics
 
Str8ts: Solution to Weekly Extreme Str8ts #29
Str8ts: Solution to Weekly Extreme Str8ts #29Str8ts: Solution to Weekly Extreme Str8ts #29
Str8ts: Solution to Weekly Extreme Str8ts #29
SlowThinker
 
Core 3 Functions 3
Core 3 Functions 3Core 3 Functions 3
Core 3 Functions 3
davidmiles100
 
Exam1 (example with solutions)
Exam1 (example with solutions)Exam1 (example with solutions)
Exam1 (example with solutions)
Abdul Ghaffar Niazi
 
2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster
Chelsea Battell
 
Core 3 Functions 1
Core 3 Functions 1Core 3 Functions 1
Core 3 Functions 1
davidmiles100
 
Rationalnumbers
RationalnumbersRationalnumbers
Rationalnumbers
Nishant Rohatgi
 
Vector
VectorVector
Vector
stuartlock
 
Vectors
VectorsVectors
Vectors
Rafi Allam
 
Graph Coloring
Graph ColoringGraph Coloring
Graph Coloring
Dr. Abdul Ahad Abro
 
Pointers
PointersPointers
Pointers
NabishaAK
 
1.3 notes
1.3 notes1.3 notes
Gsp 215 Effective Communication / snaptutorial.com
Gsp 215  Effective Communication / snaptutorial.comGsp 215  Effective Communication / snaptutorial.com
Gsp 215 Effective Communication / snaptutorial.com
HarrisGeorg21
 
Tutorials--Equations with Fractions
Tutorials--Equations with FractionsTutorials--Equations with Fractions
Tutorials--Equations with Fractions
Media4math
 
1301 d1 january_2013_mark_scheme
1301 d1 january_2013_mark_scheme1301 d1 january_2013_mark_scheme
1301 d1 january_2013_mark_scheme
claire meadows-smith
 
And or search
And or searchAnd or search
And or search
Megha Sharma
 

What's hot (19)

Micro teaching junior high school
Micro teaching junior high schoolMicro teaching junior high school
Micro teaching junior high school
 
K map
K mapK map
K map
 
Conversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad balochConversion of in fix pre fix,infix by sarmad baloch
Conversion of in fix pre fix,infix by sarmad baloch
 
Chapter 1 review (algebra) (UPDATED for A.C.)
Chapter 1 review (algebra) (UPDATED for A.C.)Chapter 1 review (algebra) (UPDATED for A.C.)
Chapter 1 review (algebra) (UPDATED for A.C.)
 
Str8ts: Solution to Weekly Extreme Str8ts #29
Str8ts: Solution to Weekly Extreme Str8ts #29Str8ts: Solution to Weekly Extreme Str8ts #29
Str8ts: Solution to Weekly Extreme Str8ts #29
 
Core 3 Functions 3
Core 3 Functions 3Core 3 Functions 3
Core 3 Functions 3
 
Exam1 (example with solutions)
Exam1 (example with solutions)Exam1 (example with solutions)
Exam1 (example with solutions)
 
2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster
 
Core 3 Functions 1
Core 3 Functions 1Core 3 Functions 1
Core 3 Functions 1
 
Rationalnumbers
RationalnumbersRationalnumbers
Rationalnumbers
 
Vector
VectorVector
Vector
 
Vectors
VectorsVectors
Vectors
 
Graph Coloring
Graph ColoringGraph Coloring
Graph Coloring
 
Pointers
PointersPointers
Pointers
 
1.3 notes
1.3 notes1.3 notes
1.3 notes
 
Gsp 215 Effective Communication / snaptutorial.com
Gsp 215  Effective Communication / snaptutorial.comGsp 215  Effective Communication / snaptutorial.com
Gsp 215 Effective Communication / snaptutorial.com
 
Tutorials--Equations with Fractions
Tutorials--Equations with FractionsTutorials--Equations with Fractions
Tutorials--Equations with Fractions
 
1301 d1 january_2013_mark_scheme
1301 d1 january_2013_mark_scheme1301 d1 january_2013_mark_scheme
1301 d1 january_2013_mark_scheme
 
And or search
And or searchAnd or search
And or search
 

Viewers also liked

Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
Arab Open University and Cairo University
 
Question, mark scheme, examiners report and model answer jan 13
Question, mark scheme, examiners report and model answer jan 13Question, mark scheme, examiners report and model answer jan 13
Question, mark scheme, examiners report and model answer jan 13
mattbentley34
 
Unit 2: Excellent revision aid..a must for all students
Unit 2: Excellent revision aid..a must for all studentsUnit 2: Excellent revision aid..a must for all students
Unit 2: Excellent revision aid..a must for all students
mattbentley34
 
To lec 03
To lec 03To lec 03
To lec 03
Hasam Panezai
 
Infos2014
Infos2014Infos2014
Jan 13 mark scheme, report & model answer
Jan 13   mark scheme, report & model answerJan 13   mark scheme, report & model answer
Jan 13 mark scheme, report & model answer
mattbentley34
 
File organisation
File organisationFile organisation
File organisation
Samuel Igbanogu
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
Arab Open University and Cairo University
 
Concept of computer files
Concept of computer filesConcept of computer files
Concept of computer files
Samuel Igbanogu
 
CS215 - Lec 9 indexing and reclaiming space in files
CS215 - Lec 9  indexing and reclaiming space in filesCS215 - Lec 9  indexing and reclaiming space in files
CS215 - Lec 9 indexing and reclaiming space in files
Arab Open University and Cairo University
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
Arab Open University and Cairo University
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
Sonali Chauhan
 
As government and politics the constitution
As government and politics the constitutionAs government and politics the constitution
As government and politics the constitution
flissxoxo
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
SANTOSH RATH
 
Aidan ferris
Aidan ferrisAidan ferris
Aidan ferris
mattbentley34
 
Os solved question paper
Os solved question paperOs solved question paper
Os solved question paper
Ankit Bhatnagar
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)
Sohaib Danish
 
AS Politics - Revision Guide: Unit 1
AS Politics - Revision Guide: Unit 1AS Politics - Revision Guide: Unit 1
AS Politics - Revision Guide: Unit 1
mattbentley34
 
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
vtunotesbysree
 

Viewers also liked (19)

Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Question, mark scheme, examiners report and model answer jan 13
Question, mark scheme, examiners report and model answer jan 13Question, mark scheme, examiners report and model answer jan 13
Question, mark scheme, examiners report and model answer jan 13
 
Unit 2: Excellent revision aid..a must for all students
Unit 2: Excellent revision aid..a must for all studentsUnit 2: Excellent revision aid..a must for all students
Unit 2: Excellent revision aid..a must for all students
 
To lec 03
To lec 03To lec 03
To lec 03
 
Infos2014
Infos2014Infos2014
Infos2014
 
Jan 13 mark scheme, report & model answer
Jan 13   mark scheme, report & model answerJan 13   mark scheme, report & model answer
Jan 13 mark scheme, report & model answer
 
File organisation
File organisationFile organisation
File organisation
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Concept of computer files
Concept of computer filesConcept of computer files
Concept of computer files
 
CS215 - Lec 9 indexing and reclaiming space in files
CS215 - Lec 9  indexing and reclaiming space in filesCS215 - Lec 9  indexing and reclaiming space in files
CS215 - Lec 9 indexing and reclaiming space in files
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
 
As government and politics the constitution
As government and politics the constitutionAs government and politics the constitution
As government and politics the constitution
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
 
Aidan ferris
Aidan ferrisAidan ferris
Aidan ferris
 
Os solved question paper
Os solved question paperOs solved question paper
Os solved question paper
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)
 
AS Politics - Revision Guide: Unit 1
AS Politics - Revision Guide: Unit 1AS Politics - Revision Guide: Unit 1
AS Politics - Revision Guide: Unit 1
 
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
 

Similar to Model answer of compilers june spring 2013

KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)
mihir jain
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
Rebaz Najeeb
 
algo1
algo1algo1
Unicamp 2015 - aberta
Unicamp 2015 - abertaUnicamp 2015 - aberta
Unicamp 2015 - aberta
KalculosOnline
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
sanchi29
 
Instruction Set Architecture: MIPS
Instruction Set Architecture: MIPSInstruction Set Architecture: MIPS
Instruction Set Architecture: MIPS
Prasenjit Dey
 
Compiling fµn language
Compiling fµn languageCompiling fµn language
Compiling fµn language
Didier Plaindoux
 
Exercises-set-theory-answer-key
Exercises-set-theory-answer-keyExercises-set-theory-answer-key
Exercises-set-theory-answer-key
IreneJoy4
 
SSC STUDY MATERIAL
SSC STUDY MATERIALSSC STUDY MATERIAL
SSC STUDY MATERIAL
Avula Yadav
 
Simplifying algebraic expressions
Simplifying algebraic expressionsSimplifying algebraic expressions
Simplifying algebraic expressions
Malini Sharma
 
Ayush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptxAyush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptx
AmanChoudhary329978
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
HussainPashaShaik1
 
Outrageous Ideas for Graph Databases
Outrageous Ideas for Graph DatabasesOutrageous Ideas for Graph Databases
Outrageous Ideas for Graph Databases
Max De Marzi
 
Lecture 3 (algebraic expressions)
Lecture 3 (algebraic expressions)Lecture 3 (algebraic expressions)
Lecture 3 (algebraic expressions)
HarithaRanasinghe
 
Form 5 Additional Maths Note
Form 5 Additional Maths NoteForm 5 Additional Maths Note
Form 5 Additional Maths Note
Chek Wei Tan
 
PEA 305.pdf
PEA 305.pdfPEA 305.pdf
PEA 305.pdf
SofiaSingla3
 
Add math may june 2016 p1
Add math may june 2016 p1Add math may june 2016 p1
Add math may june 2016 p1
Don Cunningham
 
DBMS CS3
DBMS CS3DBMS CS3
Starr pvt. ltd. rachit's group ppt (1)
Starr pvt. ltd. rachit's group ppt (1)Starr pvt. ltd. rachit's group ppt (1)
Starr pvt. ltd. rachit's group ppt (1)
Rachit Mehta
 

Similar to Model answer of compilers june spring 2013 (20)

KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
 
algo1
algo1algo1
algo1
 
Unicamp 2015 - aberta
Unicamp 2015 - abertaUnicamp 2015 - aberta
Unicamp 2015 - aberta
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Instruction Set Architecture: MIPS
Instruction Set Architecture: MIPSInstruction Set Architecture: MIPS
Instruction Set Architecture: MIPS
 
Compiling fµn language
Compiling fµn languageCompiling fµn language
Compiling fµn language
 
Exercises-set-theory-answer-key
Exercises-set-theory-answer-keyExercises-set-theory-answer-key
Exercises-set-theory-answer-key
 
SSC STUDY MATERIAL
SSC STUDY MATERIALSSC STUDY MATERIAL
SSC STUDY MATERIAL
 
Simplifying algebraic expressions
Simplifying algebraic expressionsSimplifying algebraic expressions
Simplifying algebraic expressions
 
Ayush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptxAyush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptx
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
 
Outrageous Ideas for Graph Databases
Outrageous Ideas for Graph DatabasesOutrageous Ideas for Graph Databases
Outrageous Ideas for Graph Databases
 
Lecture 3 (algebraic expressions)
Lecture 3 (algebraic expressions)Lecture 3 (algebraic expressions)
Lecture 3 (algebraic expressions)
 
Form 5 Additional Maths Note
Form 5 Additional Maths NoteForm 5 Additional Maths Note
Form 5 Additional Maths Note
 
PEA 305.pdf
PEA 305.pdfPEA 305.pdf
PEA 305.pdf
 
Add math may june 2016 p1
Add math may june 2016 p1Add math may june 2016 p1
Add math may june 2016 p1
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
 
Starr pvt. ltd. rachit's group ppt (1)
Starr pvt. ltd. rachit's group ppt (1)Starr pvt. ltd. rachit's group ppt (1)
Starr pvt. ltd. rachit's group ppt (1)
 

More from Arab Open University and Cairo University

Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
Arab Open University and Cairo University
 
Lec4
Lec4Lec4
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
Arab Open University and Cairo University
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
Arab Open University and Cairo University
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
Arab Open University and Cairo University
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
Arab Open University and Cairo University
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
Arab Open University and Cairo University
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
Arab Open University and Cairo University
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
Arab Open University and Cairo University
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
Arab Open University and Cairo University
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
Arab Open University and Cairo University
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
Arab Open University and Cairo University
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
Arab Open University and Cairo University
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
Arab Open University and Cairo University
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
Arab Open University and Cairo University
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
Arab Open University and Cairo University
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
Arab Open University and Cairo University
 
CS215 - Lec 7 managing records collection
CS215 - Lec 7  managing records collectionCS215 - Lec 7  managing records collection
CS215 - Lec 7 managing records collection
Arab Open University and Cairo University
 

More from Arab Open University and Cairo University (20)

Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Lec4
Lec4Lec4
Lec4
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
 
CS215 - Lec 7 managing records collection
CS215 - Lec 7  managing records collectionCS215 - Lec 7  managing records collection
CS215 - Lec 7 managing records collection
 

Recently uploaded

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 

Recently uploaded (20)

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 

Model answer of compilers june spring 2013

  • 1. Page 1 of 5 Cairo University Faculty of Computers and Information Final Exam Department: CS Course Name: Compilers Date: Tuesday 4-June-2013 Course Code: CS419 Duration: 2 hours Instructor(s): Dr. Hussien Sharaf Total Marks: 60 Question 1 [12 marks] For each of the following languages do the following: i. Understand the languages without any assistance; ii. Write sample words for the language where you show the smallest possible word. iii. Construct a regular expression that represents the language. Note: Draw and fill the following table in your answer sheet: Sample Regular Expression a. Σ ={a, b} Only words with exactly two consecutive a's [2 marks] Solution: Sample = {aa, aab, baa, baab, bbaabbb …..} b*aab* b. Σ ={a, b} Only words such that { an bm | n is even and m is odd} where n and m indicate number of “a”s and “b”s respectively. [3 marks] Solution: Sample = {b,aab,aabbb,..} (aa)* b(bb)* + (aa)* a (bb)* b c. Σ ={a, b} Words where “a” appears ONLY in even positions or doesn’t appear at all. [3 marks] Solution: Sample = { Λ b ba bbb bbba baba …..} b+(bb+ba)*b* (b(a+b))* + b* (ba)*(bb)*(ba)* b* + (b(bb)* (a+b) )* d. Σ ={a, b} Construct a regular expression for all strings that have exactly one double letter in them. “One double letter” implies two equal touching letters; triples or more are excluded. [4 marks] Solution: Sample = { aa, baa, …..} (b + Λ)(ab)*aa(ba)*(b + Λ) + (a + Λ)(ba)*bb(ab)*(a + Λ) Question 2 [8 marks] For each of the following languages do the following: i. Understand the languages without any assistance; ii. Write sample words for the language where you show the smallest possible word. iv. Draw a deterministic finite automaton that represents the language and handles incorrect inputs.
  • 2. Page 2 of 5 a. Σ = {a, b} words where “a” appears ONLY in the second position or doesn’t appear at all. [3 marks] Solution: Sample = { Λ b ba bbb bab babbb …..} b. Σ = {a, b} Words that begin and ending with the same letter. [5 marks] Solution: Sample = { Λ b ba bbb bab babbb …..} Question 3 [10 marks] An if-statement indicated by L is a language where multiple executable instructions “S” can be used only by embedding them inside curly brackets pair where execution starts with the inner curly brackets pair; i.e. {{{S1}S2}S3} means executing s1, s2 then s3. One statement can only be embedded inside one curly bracket pair where the statement “S” should always stick to the closing curly bracket. Finally a curly bracket pair must always contain a statement i.e. { {S} } is NOT valid. Sample for if-statement in L: if ((c4) OR (c5 AND c6)) {{{s1}s2}s3} else {{s5}s6} a. Understand the language without any assistance and check if the following grammar represents the conditional statements “C” indicated by L. If NO then explain why? If YES then show left derivation for “((C4) OR (C5 AND C6))”; Do each step in a separate line and show rule number. [3 marks] R1: C→(C) R2: C→C AND C R3: C→C OR C R4: C→c1|c2|c3|c4|c5|c6| …|c10 Note: Draw and fill the following table in your answer sheet: a b b -+1 2 a,b +3 a a -+1 b 4 a b 3 a +2 b b a a 5 b +4
  • 3. Page 3 of 5 Derivation Rule Number Solution: YES Derivation Rule Number C →(C) R1 →(C OR C) R3 →((C) OR C) R1 →((c4) OR C) R4 →((c4) OR (C)) R1 →((c4) OR (C AND C)) R2 →((c4) OR (c5 AND C)) R4 →((c4) OR (c5 AND c6)) R4 b. Write a CFG for the instructions “S” similar to the CFG of the “C”. Can you avoid using Lambda? [4 marks] Solution: R1: S→{ST} R2: S→Λ R3: T→s1|s2|s3|s4|s5|s6| …|s10 Λ must be used to recursion of S c. Can language L be described using regular expressions? Why? [3 marks] Solution: • No. • Because L have nested structures brackets and parenthesis that must be balanced. RE cannot describe balanced structures such as an bn Question 4 [30 marks] Ζ delta is a language that allows for nested if-statements L, executable expressions “E” and conditional statements “C”. CFG: R1: Z →E R2: Z →L R3: L →if C Z R4: L →if C Z else Z R5: C→(C) R6: C→N and N R7: E →id = N * N R10: N→ 0 R11: N→ 1 Sample for a Z statement: if (0 and 1) if (0 and 0) id = 1*1 a. Specify which pair of rule(s) contains the left factoring and rewrite all the CFG with numbers (after removing left factoring) factoring? Hint: if you need to introduce a new variable then use letter M. [3 marks] Solution: R3 and R4 CFG: • R1: Z →E • R2: Z →L
  • 4. Page 4 of 5 • R3: L→ if C Z M • R4:M→Λ • R5:M→ else Z • R6: C→ (C) • R7: C→N and N • R8: E →id = N * N • R9: N→ 0 • R10: N→ 1 b. Construct a parsing table for Z. Note that the set of terminals is {if, else, (,),id=,*, and, 0,1} and set of non-terminals is {Z, E, L, M, C, N} [3 marks] Solution: If else ( ) and id = * 0 1 $ Z R2 R1 E R8 L R3 M R5 R4 R4 R4 C R6 R7 R7 N R9 R10 c. Show the top-down parsing steps of the sample above using the parsing table constructed in the previous section. [16 marks] Solution: Stack Input Parser action Z if (0 and 1) if (0 and 0) id = 1*1 $ R2 L .. R3 if C Z M if .. Match C Z M (0 and 1) .. R6 (C) Z M (0 and 1) .. Match C) Z M 0 and 1) .. R7 N and N) Z M 0 and 1) .. R9 0 and N) Z M 0 and 1) .. Match N) Z M 1) … R9 1) Z M 1) if (0 and 0) id = 1*1 $ Match Z M if (0 and 0) id = 1*1 $ R2 L M if (0 and 0) id = 1*1 $ R3 if C Z M M if (0 and 0) id = 1*1 $ Match C Z M M (0 and 0) id = 1*1 $ R6 (C) Z M M (0 and 0) id = 1*1 $ Match C) Z M M 0 and 0) id = 1*1 $ R7 N and N) Z M M 0 and 0) id = 1*1 $ R9 0 and N) Z M M 0 and 0) id = 1*1 $ Match N) Z M M 0) id = 1*1 $ R9 0) Z M M 0) id = 1*1 $ Match Z M M id = 1*1 $ R1 E M M id = 1*1 $ R8 id = N * N M M id = 1*1 $ Match N * N M M 1*1 $ R10 1 * N M M 1*1 $ Match N M M 1 $ R10 1 M M 1 $ Match M M $ R4 M $ R4
  • 5. Page 5 of 5 Empty $ Accept d. Show the 10 steps for bottom-up parsing of the sample above. [10 marks] Solution: Stack Input Action $ if (0 and 1) if (0 and 0) id = 1*1 $ Shift $if (0 and 1) … Shift $if( 0 and 1) …. Shift $if(0 and 1) …. Reduce R9 $if(N and 1) …. Shift $if(N and 1) …. Shift $if(N and 1 ) if (0 and 0) id = 1*1 $ Reduce R10 $if(N and N ) if (0 and 0) id = 1*1 $ Reduce R7 $if(C ) if (0 and 0) id = 1*1 $ Shift $if(C) if (0 and 0) id = 1*1 $ Reduce R6 $if C if (0 and 0) id = 1*1 $ Shift $if C if (0 and 0) id = 1*1 $ Shift $if C if( 0 and 0) id = 1*1 $ Shift $if C if(0 and 0) id = 1*1 $ Reduce R9 $if C if(N and 0) id = 1*1 $ Shift $if C if(N and 0) id = 1*1 $ Shift $if C if(N and 0 ) id = 1*1 $ Reduce R9 $if C if(N and N ) id = 1*1 $ Reduce R7 $if C if(C ) id = 1*1 $ Shift $if C if(C) id = 1*1 $ Shift $if C if(C) id = 1*1 $ Reduce R6 $if C if C id = 1*1 $ Shift $if C if C id 1*1 $ Shift $if C if C id = 1*1 $ Shift $if C if C id = 1 *1 $ Reduce R10 $if C if C id = N *1 $ Shift $if C if C id = N * 1 $ Shift $if C if C id = N * 1 $ Reduce R10 $if C if C id = N * N $ Reduce R8 $if C if C E $ Reduce R1 $if C if C Z $ Reduce R4 $if C if C Z M $ Reduce R3 $if C L $ Reduce R2 $if C Z $ Reduce R4 $if C Z M $ Reduce R3 $ L $ Reduce R2 $Z $ Accept