Assignment Solution Chapter 3 Q 1) Write a regular definitions for the following languages: a) all strings beginning and ending with b, let Σ = {a, b}. L- > b | b(a|b)*b b) all strings containing exactly three 1s, let Σ = {0, 1}. L –> 0* 1 0* 1 0*1 0* c) All strings of a’s and b’s that do not contain the substring abb, let Σ = {a, b}. L –> b* (a (|b))* d) String of a`s and b`s that contains odd number of b’s , let Σ = {a, b}. L –> a* b (a* b a* b)* a* e) All strings of a's and b's with an even number of a's and an odd number of b's , let Σ = {a, b}. L –> (aa)* b (bb)* (aa)* f) All strings of digits that contain no leading zeroes num –> 1 | 2 | … | 9 digit –> 0 | num digits –> 0 | num digit* g) All strings of digits that represent even numbers even –> 0 | 2 | 4 | 6 | 8 digits –> even | [1-9] [0-9]* even h) All strings of digits such that all the 5’s occur before all the 8’s dignot8 –> 0 | 1 |2 | 3 | 4 | 5| 6 | 7 | 9 dignot5 –> 0 | 1 |2 | 3 | 4 | 6 | 7 | 8| 9 digits –> dignot8* dignot5* The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering ECOM5060:Compiler Design Eng. Ibraheem Lubbad
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Assignment Solution
Chapter 3
Q 1) Write a regular definitions for the following languages:
a) all strings beginning and ending with b, let Σ = {a, b}.
L- > b | b(a|b)*b
b) all strings containing exactly three 1s, let Σ = {0, 1}.
L –> 0* 1 0* 1 0*1 0*
c) All strings of a’s and b’s that do not contain the substring abb, let Σ = {a, b}.
L –> b* (a (|b))*
d) String of a`s and b`s that contains odd number of b’s , let Σ = {a, b}.
L –> a* b (a* b a* b)* a*
e) All strings of a's and b's with an even number of a's and an odd number of b's , let Σ = {a, b}.
L –> (aa)* b (bb)* (aa)*
f) All strings of digits that contain no leading zeroes
num –> 1 | 2 | … | 9
digit –> 0 | num
digits –> 0 | num digit*
g) All strings of digits that represent even numbers
even –> 0 | 2 | 4 | 6 | 8
digits –> even | [1-9] [0-9]* even
h) All strings of digits such that all the 5’s occur before all the 8’s
dignot8 –> 0 | 1 |2 | 3 | 4 | 5| 6 | 7 | 9
dignot5 –> 0 | 1 |2 | 3 | 4 | 6 | 7 | 8| 9
digits –> dignot8* dignot5*
The Islamic University of Gaza
Faculty of Engineering
Dept. of Computer Engineering
ECOM5060:Compiler Design
Eng. Ibraheem Lubbad
Q 2) Construct an NFA that recognizes the regular expressions a* (a|b) aa , and find the DFA: