Compilers midterm spring 2013 model answer

577 views
496 views

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
577
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Compilers midterm spring 2013 model answer

  1. 1. Full mark is out of 20Cairo University Midterm ExamFaculty of Computers & Information Spring 2013Dept. of Computer Science Time 1 hourCompilers DesignCS419Solve as much as you can. Full mark is out of twentyPart A: Regular expressions:1. ∑ ={a, b, c}; Formally describe all words for the language L that start with an afollowed by any number of b’s and then end with c. Give examples for words inthis language. [1 mark]Solution:L = a b*cGive 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 numberof 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 equivalentor not and explain your answer.(a*b*) and (ab)* [2mark]Solution:i. NOT equalThe language defined by the expression on the right contains the word abab, butthe language defined by the expression on the left does not.
  2. 2. Full mark is out of 20bbba,bbaSSS3+baSSS2+Sba,b-+SPart B: Finite Automata:∑ ={a, b}.6. Build two FAs (with different number of states) that accept only the word "ab".[1mark]Solution:RE = ab7. 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.[2mark]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 examplePosition 1 2 3 4 5Example1 a a a a bExample2 b a b a a[2 mark]Solution:a,ba,b-
  3. 3. Full mark is out of 20Aa1 2 3 4Part 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,baΛ ΛΛ

×