SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
Full mark is out of 20
Cairo University Midterm Exam
Faculty of Computers & Information Spring 2013
Dept. of Computer Science Time 1 hour
Compilers DesignCS419
Solve as much as you can. Full mark is out of twenty
Part A: Regular expressions:
1. ∑ ={a, b, c}; Formally describe all words for the language L that start with an 'a'
followed by any number of 'b'’s and then end with 'c'. Give examples for words in
this language. [1 mark]
Solution:
L = a b*c
Give examples for words in L
{ac, abc,abc,abbc, abbbc …..}
2. ∑ ={a, b}; All words with even count of letters. [2 mark]
Solution:
((a+b)(a+b))*
examples for words in L
{ Λ, aa,bb,ab,ba,bb,aaaa,…..}
3. ∑ ={a, b}; Construct a regular expression for:
a. All strings that end in a double letter. [2 mark]
b. All strings that do not end in a double letter. [2 mark]
Solution:
a. (a + b)*(aa + bb)
b. ((a + b)*(ab + ba)) + a + b + Λ
Note: Provide for strings containing zero or one letter too by + Λ
4. ∑ ={a, b};Construct a regular expression for all strings in which the total number
of 'a'’s is divisible by 3 no matter how they are distributed, such as “aabaabbaba”.
[2 mark]
Solution:
(b*ab*ab*ab*)*
5. ∑ ={a, b}, State whether the following pair of regular expressions are equivalent
or not and explain your answer.(a*b*) and (ab)* [2
mark]
Solution:
i. NOT equal
The language defined by the expression on the right contains the word abab, but
the language defined by the expression on the left does not.
Full mark is out of 20
b
b
b
a,b
ba
S
S
S3
+
ba
S
S
S2
+
S
ba,b
-+
S
Part B: Finite Automata:
∑ ={a, b}.
6. Build two FAs (with different number of states) that accept only the word "ab".
[1
mark]
Solution:
RE = ab
7. Build FA with one state that accepts anything. [1 mark]
Solution:
RE = (a+b)*
8. Build FA that accepts only words that have an even number of letters.
[2
mark]
Solution:
9. All words with even count of letters where even positions must contain an “a”,
and the first letter is letter number one. (a+b)a((a+b)a)*.
For example
Position 1 2 3 4 5
Example1 a a a a b
Example2 b a b a a
[2 mark]
Solution:
a,b
a,b
-
Full mark is out of 20
A
a
1 2 3 4
Part C: NFA:
10. Construct an NFA (with ε transitions) for (ab)*(aab)* [3 mark]
Solution:
Part D: NFA to DFA:
11. For the given NFA, construct the equivalent DFA [3 mark]
Solution:
Closure of 1 ={1,2,4}
Closure of 2 = {2}
Closure of 3 = {2, 3,4}
Closure of 4 = {4}
-
a,
b
aΛ Λ
Λ

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Lesson 10
Lesson 10Lesson 10
Lesson 10
 
Automata
AutomataAutomata
Automata
 
Lesson 04
Lesson 04Lesson 04
Lesson 04
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 
FInite Automata
FInite AutomataFInite Automata
FInite Automata
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Formal language & automata theory
Formal language & automata theoryFormal language & automata theory
Formal language & automata theory
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Lesson 12
Lesson 12Lesson 12
Lesson 12
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
2.8 normal forms gnf & problems
2.8 normal forms   gnf & problems2.8 normal forms   gnf & problems
2.8 normal forms gnf & problems
 
L3 cfg
L3 cfgL3 cfg
L3 cfg
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Theory of Automata Lesson 02
Theory of Automata Lesson 02Theory of Automata Lesson 02
Theory of Automata Lesson 02
 
Lefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptxLefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptx
 

Andere mochten auch

Os solved question paper
Os solved question paperOs solved question paper
Os solved question paperAnkit Bhatnagar
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionBharat17485
 
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 13mattbentley34
 
FINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEM
FINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEMFINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEM
FINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEMAmira Dolce Farhana
 
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 studentsmattbentley34
 
Operating system notes
Operating system notesOperating system notes
Operating system notesSANTOSH RATH
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)Sohaib Danish
 
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
 
Operating System Multiple Choice Questions
Operating System Multiple Choice QuestionsOperating System Multiple Choice Questions
Operating System Multiple Choice QuestionsShusil Baral
 
Collections of CS Multiple Choice Questions
Collections of CS Multiple Choice QuestionsCollections of CS Multiple Choice Questions
Collections of CS Multiple Choice QuestionsShusil Baral
 
Basic IT Multiple Choice Questions
Basic IT Multiple Choice QuestionsBasic IT Multiple Choice Questions
Basic IT Multiple Choice QuestionsShusil Baral
 
Computer Networking Multiple Choice Questions
Computer Networking Multiple Choice QuestionsComputer Networking Multiple Choice Questions
Computer Networking Multiple Choice QuestionsShusil Baral
 

Andere mochten auch (20)

To lec 03
To lec 03To lec 03
To lec 03
 
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
 
Infos2014
Infos2014Infos2014
Infos2014
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
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
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
 
Os solved question paper
Os solved question paperOs solved question paper
Os solved question paper
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
 
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
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
FINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEM
FINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEMFINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEM
FINAL PAPER FP501 OPEN SOURCE OPERATING SYSTEM
 
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
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)
 
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...
 
Operating System Multiple Choice Questions
Operating System Multiple Choice QuestionsOperating System Multiple Choice Questions
Operating System Multiple Choice Questions
 
Collections of CS Multiple Choice Questions
Collections of CS Multiple Choice QuestionsCollections of CS Multiple Choice Questions
Collections of CS Multiple Choice Questions
 
Basic IT Multiple Choice Questions
Basic IT Multiple Choice QuestionsBasic IT Multiple Choice Questions
Basic IT Multiple Choice Questions
 
Computer Networking Multiple Choice Questions
Computer Networking Multiple Choice QuestionsComputer Networking Multiple Choice Questions
Computer Networking Multiple Choice Questions
 

Ähnlich wie Compilers midterm spring 2013 model answer

12 -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]
12  -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]12  -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]
12 -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]Rabi Iftikhar
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)Rebaz Najeeb
 
Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........NaumanAli215439
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxRaviAr5
 
Lesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptLesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptashja1
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01 hamzamughal39
 
Alphabets , strings, languages and grammars
Alphabets , strings, languages  and grammarsAlphabets , strings, languages  and grammars
Alphabets , strings, languages and grammarshele987
 
Problem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurProblem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurVivekananda Samiti
 
Regular Expression Examples.pptx
Regular Expression Examples.pptxRegular Expression Examples.pptx
Regular Expression Examples.pptxGhulamRabani9
 
Handout Regular expression with examples and lecture
Handout Regular expression with examples  and lecture Handout Regular expression with examples  and lecture
Handout Regular expression with examples and lecture mariajan8
 
Expresiones Algebraicas
Expresiones AlgebraicasExpresiones Algebraicas
Expresiones AlgebraicasDargelisGomez1
 
V cse cs6503 model qb1 1
V  cse cs6503  model qb1 1V  cse cs6503  model qb1 1
V cse cs6503 model qb1 1Ezhumalai p
 

Ähnlich wie Compilers midterm spring 2013 model answer (20)

12 -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]
12  -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]12  -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]
12 -csc312_automat_theory_assign-1_(27-09-12)_(1)[1]
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
 
Lesson 09
Lesson 09Lesson 09
Lesson 09
 
Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........Theory of Automata ___ Basis ...........
Theory of Automata ___ Basis ...........
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
Lesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.pptLesson-01-29092022-081117pm.ppt
Lesson-01-29092022-081117pm.ppt
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01
 
Lesson 09.ppt
Lesson 09.pptLesson 09.ppt
Lesson 09.ppt
 
Alphabets , strings, languages and grammars
Alphabets , strings, languages  and grammarsAlphabets , strings, languages  and grammars
Alphabets , strings, languages and grammars
 
Problem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurProblem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Problem set2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
 
Regular Expression Examples.pptx
Regular Expression Examples.pptxRegular Expression Examples.pptx
Regular Expression Examples.pptx
 
Handout Regular expression with examples and lecture
Handout Regular expression with examples  and lecture Handout Regular expression with examples  and lecture
Handout Regular expression with examples and lecture
 
Linear Algebra Assignment Help
Linear Algebra Assignment HelpLinear Algebra Assignment Help
Linear Algebra Assignment Help
 
Expresiones Algebraicas
Expresiones AlgebraicasExpresiones Algebraicas
Expresiones Algebraicas
 
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
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
L_2_apl.pptx
L_2_apl.pptxL_2_apl.pptx
L_2_apl.pptx
 
V cse cs6503 model qb1 1
V  cse cs6503  model qb1 1V  cse cs6503  model qb1 1
V cse cs6503 model qb1 1
 

Mehr von Arab Open University and Cairo University

Mehr von 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 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
 
CS215 - Lec 6 record index
CS215 - Lec 6  record indexCS215 - Lec 6  record index
CS215 - Lec 6 record index
 
CS215 - Lec 5 record organization
CS215 - Lec 5  record organizationCS215 - Lec 5  record organization
CS215 - Lec 5 record organization
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 

Kürzlich hochgeladen (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

Compilers midterm spring 2013 model answer

  • 1. Full mark is out of 20 Cairo University Midterm Exam Faculty of Computers & Information Spring 2013 Dept. of Computer Science Time 1 hour Compilers DesignCS419 Solve as much as you can. Full mark is out of twenty Part A: Regular expressions: 1. ∑ ={a, b, c}; Formally describe all words for the language L that start with an 'a' followed by any number of 'b'’s and then end with 'c'. Give examples for words in this language. [1 mark] Solution: L = a b*c Give examples for words in L {ac, abc,abc,abbc, abbbc …..} 2. ∑ ={a, b}; All words with even count of letters. [2 mark] Solution: ((a+b)(a+b))* examples for words in L { Λ, aa,bb,ab,ba,bb,aaaa,…..} 3. ∑ ={a, b}; Construct a regular expression for: a. All strings that end in a double letter. [2 mark] b. All strings that do not end in a double letter. [2 mark] Solution: a. (a + b)*(aa + bb) b. ((a + b)*(ab + ba)) + a + b + Λ Note: Provide for strings containing zero or one letter too by + Λ 4. ∑ ={a, b};Construct a regular expression for all strings in which the total number of 'a'’s is divisible by 3 no matter how they are distributed, such as “aabaabbaba”. [2 mark] Solution: (b*ab*ab*ab*)* 5. ∑ ={a, b}, State whether the following pair of regular expressions are equivalent or not and explain your answer.(a*b*) and (ab)* [2 mark] Solution: i. NOT equal The language defined by the expression on the right contains the word abab, but the language defined by the expression on the left does not.
  • 2. Full mark is out of 20 b b b a,b ba S S S3 + ba S S S2 + S ba,b -+ S Part B: Finite Automata: ∑ ={a, b}. 6. Build two FAs (with different number of states) that accept only the word "ab". [1 mark] Solution: RE = ab 7. Build FA with one state that accepts anything. [1 mark] Solution: RE = (a+b)* 8. Build FA that accepts only words that have an even number of letters. [2 mark] Solution: 9. All words with even count of letters where even positions must contain an “a”, and the first letter is letter number one. (a+b)a((a+b)a)*. For example Position 1 2 3 4 5 Example1 a a a a b Example2 b a b a a [2 mark] Solution: a,b a,b -
  • 3. Full mark is out of 20 A a 1 2 3 4 Part C: NFA: 10. Construct an NFA (with ε transitions) for (ab)*(aab)* [3 mark] Solution: Part D: NFA to DFA: 11. For the given NFA, construct the equivalent DFA [3 mark] Solution: Closure of 1 ={1,2,4} Closure of 2 = {2} Closure of 3 = {2, 3,4} Closure of 4 = {4} - a, b aΛ Λ Λ