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

PPTX
Theory of computation Lec1
PDF
Réalisation d’un interpréteur en langue Arabe - Khawarizmi
PPT
Unit 2 dhtml
PPTX
Context free grammars
ODP
Regex Presentation
PDF
Regex - Regular Expression Basics
PPTX
Backus Naur and Chomsky Normal Forms
PPT
Theory of computation Lec1
Réalisation d’un interpréteur en langue Arabe - Khawarizmi
Unit 2 dhtml
Context free grammars
Regex Presentation
Regex - Regular Expression Basics
Backus Naur and Chomsky Normal Forms

What's hot (20)

PPTX
Java Constructors
PPTX
Full Stack Web Developer (MERN STACK Developer.pptx
PPT
Lecture 7
PPTX
Windows form application - C# Training
PPT
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
PPTX
Five Major Types of Intrusion Detection System (IDS)
PPTX
IPv6 Addressing
PDF
Swift Programming Language
PPTX
push down automata
PDF
Java servlets
PPT
Lecture 6
PPTX
Context Free Grammar
PPTX
Regular Expression (Regex) Fundamentals
PPT
Lecture 8
PPTX
Master page and Theme ASP.NET with VB.NET
PPT
PPTX
gRPC on .NET Core - NDC Sydney 2019
PPTX
Theory of computation Lec2
PDF
Lecture: Context-Free Grammars
PPT
subnet mask.ppt
Java Constructors
Full Stack Web Developer (MERN STACK Developer.pptx
Lecture 7
Windows form application - C# Training
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
Five Major Types of Intrusion Detection System (IDS)
IPv6 Addressing
Swift Programming Language
push down automata
Java servlets
Lecture 6
Context Free Grammar
Regular Expression (Regex) Fundamentals
Lecture 8
Master page and Theme ASP.NET with VB.NET
gRPC on .NET Core - NDC Sydney 2019
Theory of computation Lec2
Lecture: Context-Free Grammars
subnet mask.ppt
Ad

Viewers also liked (14)

PDF
Model answer of compilers june spring 2013
PDF
Compilers midterm spring 2013 model answer
PPT
To lec 03
PDF
Model answer of exam TC_spring 2013
PDF
File Organization & processing Mid term summer 2014 - modelanswer
DOCX
Question, mark scheme, examiners report and model answer jan 13
PDF
Final Exam OS fall 2012-2013 with answers
PDF
Os Question Bank
PDF
Unit 2: Excellent revision aid..a must for all students
DOCX
Operating system notes
DOCX
Os solved question paper
PDF
Operating system concepts (notes)
PDF
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
Model answer of compilers june spring 2013
Compilers midterm spring 2013 model answer
To lec 03
Model answer of exam TC_spring 2013
File Organization & processing Mid term summer 2014 - modelanswer
Question, mark scheme, examiners report and model answer jan 13
Final Exam OS fall 2012-2013 with answers
Os Question Bank
Unit 2: Excellent revision aid..a must for all students
Operating system notes
Os solved question paper
Operating system concepts (notes)
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
Ad

Similar to Compilers Final spring 2013 model answer (20)

PPTX
Top down and botttom up Parsing
PPTX
This is a presentation on the parsing.pptx
PPTX
Top down and botttom up 2 LATEST.
PDF
Theory of automata and formal language lab manual
PDF
Bc0052 theory of computer science-mqp
DOC
Principles of Compiler Design
DOC
PCD ?s(MCA)
DOC
Pcd(Mca)
DOC
Pcd(Mca)
DOC
Compiler Design Material 2
PPT
Compiler Design in Engineering for Designing
PDF
Compiler worksheet
KEY
Verification with LoLA: 2 The LoLA Input Language
PPT
0227 regularlanguages
PPTX
Compiler Design_Syntax Analyzer_Top Down Parsers.pptx
PPTX
Chapter 4.pptx compiler design lecture note
PPT
Integrated Fundamental and Technical Analysis of Select Public Sector Oil Com...
DOCX
V cse cs6503 model qb1 1
Top down and botttom up Parsing
This is a presentation on the parsing.pptx
Top down and botttom up 2 LATEST.
Theory of automata and formal language lab manual
Bc0052 theory of computer science-mqp
Principles of Compiler Design
PCD ?s(MCA)
Pcd(Mca)
Pcd(Mca)
Compiler Design Material 2
Compiler Design in Engineering for Designing
Compiler worksheet
Verification with LoLA: 2 The LoLA Input Language
0227 regularlanguages
Compiler Design_Syntax Analyzer_Top Down Parsers.pptx
Chapter 4.pptx compiler design lecture note
Integrated Fundamental and Technical Analysis of Select Public Sector Oil Com...
V cse cs6503 model qb1 1

More from Arab Open University and Cairo University (20)

PPTX
Theory of computation Lec6
PPTX
Theory of computation Lec3 dfa
PPTX
Theory of computation Lec7 pda
PPTX
PPTX
Cs419 lec8 top-down parsing
PPTX
Cs419 lec11 bottom-up parsing
PPTX
Cs419 lec12 semantic analyzer
PPTX
Cs419 lec9 constructing parsing table ll1
PPTX
Cs419 lec10 left recursion and left factoring
PPTX
Cs419 lec6 lexical analysis using nfa
PPTX
Cs419 lec5 lexical analysis using dfa
PPTX
Cs419 lec4 lexical analysis using re
PPTX
Cs419 lec3 lexical analysis using re
PPTX
Cs419 Compiler lec1&2 introduction
PDF
CS215 - Lec 8 searching records
PDF
CS215 - Lec 7 managing records collection
PDF
CS215 - Lec 6 record index
PDF
CS215 - Lec 5 record organization
Theory of computation Lec6
Theory of computation Lec3 dfa
Theory of computation Lec7 pda
Cs419 lec8 top-down parsing
Cs419 lec11 bottom-up parsing
Cs419 lec12 semantic analyzer
Cs419 lec9 constructing parsing table ll1
Cs419 lec10 left recursion and left factoring
Cs419 lec6 lexical analysis using nfa
Cs419 lec5 lexical analysis using dfa
Cs419 lec4 lexical analysis using re
Cs419 lec3 lexical analysis using re
Cs419 Compiler lec1&2 introduction
CS215 - Lec 8 searching records
CS215 - Lec 7 managing records collection
CS215 - Lec 6 record index
CS215 - Lec 5 record organization

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Presentation on HIE in infants and its manifestations
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Lesson notes of climatology university.
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
master seminar digital applications in india
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Structure & Organelles in detailed.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Presentation on HIE in infants and its manifestations
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Lesson notes of climatology university.
human mycosis Human fungal infections are called human mycosis..pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
2.FourierTransform-ShortQuestionswithAnswers.pdf
A systematic review of self-coping strategies used by university students to ...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
master seminar digital applications in india
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharma ospi slides which help in ospi learning
O7-L3 Supply Chain Operations - ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Structure & Organelles in detailed.

Compilers Final spring 2013 model answer

  • 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