+ All Categories
Home > Documents > Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an...

Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an...

Date post: 26-Mar-2020
Category:
Upload: others
View: 20 times
Download: 0 times
Share this document with a friend
25
Automata and Formal Languages Lecture 04 Dr. Ahmed Hassan Computer Science Department 1
Transcript
Page 1: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Automata and Formal Languages

Lecture 04

Dr. Ahmed Hassan

Computer Sc ience Department

1

Page 2: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Books

2

Page 3: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

PowerPointhttp://www.bu.edu.eg/staff/ahmedaboalatah14-courses/14767

3

Page 4: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Regular Expressions & Regular Languages

4

Page 5: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

AgendaRegular Expressions

Example

The Operations Priority

Languages Associated with Regular Expressions

Examples

Properties of Regular Expressions

RE to NFA

Examples

5

Page 6: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Regular ExpressionsThe set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations and * is a unary operation:

Basis: ◦ Λ, ø, and a are regular expressions for all a ∈ A.

Induction: ◦ If R and S are regular expressions, then the following

expressions are also regular:

(R), R + S, R.S, and R*.

6

Page 7: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 00A = {a, b}

Λ ø a b

Λ + b

b*

a + (b.a)

(a + b).a

a.b*

a* + b*

7

Page 8: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

The Operations Priority

* highest (do it first),

.

+ lowest (do it last).

a + b.a* = (a + (b.(a*)))

8

Page 9: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Languages Associated with Regular ExpressionsL(ø) = ø,

L(Λ) = (Λ),

L(a) = (a) for each a ∈ A,

L(R + S) = L(R) ∪ L(S),

L(R • S) = L(R)L(S) (language product),

L(R*) = L(R)* (language closure).

9

Page 10: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 01Let's find the language of the regular expression a + bc*. We can evaluate the expression L(a + bc*) as follows:

L(a + bc*) = L(a) ∪ L(bc*)

= L(a) ∪ (L(b).L(c*))

= L(a) ∪ (L(b).L(c)*)

= {a} ∪ ({b} . {c}*)

= {a} ∪ ({b} {Λ, c, c2, ... , cn, ...} )

= {a} ∪ {b, bc, bc2 , ... ,bcn, ... }

= {a, b, bc, bc2 , ... , bcn, .... }

10

Page 11: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 02language L (a* · (a + b)) in set notation:

L (a* · (a + b)) = L (a*) L (a + b)

= (L (a))* (L (a) ∪ L (b))

= {Λ, a, aa, aaa, ...}{a, b}

= {a, aa, aaa, ..., b, ab, aab, ...}.

11

Page 12: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 03language r = (a + b)* (a + bb) in set notation:

L ((a + b)*.(a + bb) )= L ((a+b)*).L (a + bb)

= (L (a+b))*.(L (a) ∪ L (bb))= ({a, b})*.({a} ∪ L (b)L(b))

= {Λ,a,b,aa,ab,ba,bb ...}{a, bb}

= {a, bb, aa, abb, ba, bbb, ...}

12

Page 13: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 04Find language?

Λ + b

b*

a + (b.a)

(a + b).a

(aa)* (bb)* b

13

Page 14: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 05For Σ = {0, 1}, give a regular expression R such that

◦ L (R) = {w ∈ Σ* : w has at least one pair of consecutive zeros}.

R = (0 + 1)* 00 (0 + 1)*

14

Page 15: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

*Example 06Find a regular expression for the language

◦ L = {w ∈ {0, 1}* : w has no pair of consecutive zeros}.

(1 + 01)*(Λ + 0)

15

Page 16: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

*Example 06{Λ , 0, 1, 01, 10, 11, 010, 011, 101, 110, 111, 0101, 0110, 1010, 0111, 1110,…….}

= {Λ , 1, 01, 11, 011, 101, 111, 0101, 0111,….}

∪ { 0, 10, 010, 110, 0110, 1010, 1110, ….}

= {Λ , 1, 01, 11, 011, 101, 111, 0101, 0111,….}

∪ { 0, 10, 010, 110, 0110, 1010, 1110, ….}

= {Λ , 1, 01, 11, 011, 101, 111, 0101, 0111,….}

∪ {Λ, 1, 01, 11, 011, 101, 111, ….}{0}

={1, 01}* ∪ {1, 01}*.{0}

={1, 01}*{Λ, 0}

16

Page 17: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 07Find a regular expression for

L1 = {anbm : n ≥ 3, m is odd}

L2 = {anbm : (n + m) is odd}

L3 = {anbm, n ≥ 3, m ≤ 4}

17

Page 18: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Properties of Regular Expressions

18

Page 19: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Properties of Regular Expressions (cont.)

19

Page 20: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

20

RE to NFAFirst parse r into its constituent sub expressions.

Construct NFA’s for each of the basic symbols in r.◦ for

◦ for a in

◦ for ø

Page 21: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

21

RE to NFA (cont.)For the regular expression s+t,

For the regular expression s.t,

Page 22: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

22

RE to NFA (cont.)For the regular expression s*,

For the parenthesized regular expression (s), use N(s) itself as the NFA.

Every time we construct a new state, we give it a distinct name.

Page 23: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 08 Find an NFA that accepts L (r), where

r = (Λ + ab)*

23

Page 24: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

Example 09 Find an NFA that accepts each regular Expression

a∗a + ab

(aab)∗ab

ab∗aa

24

Page 25: Automata and Formal Languages and... · Regular Expressions The set of regular expressions over an alphabet “A” is defined inductively as follows, where + and • are binary operations

25

?


Recommended