Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conversions Regular Expression to FA FA to Regular Expression.

Similar presentations


Presentation on theme: "Conversions Regular Expression to FA FA to Regular Expression."— Presentation transcript:

1 Conversions Regular Expression to FA FA to Regular Expression

2 Language Representing Regular Expressions We define a mapping from a regular expression  to a language L(  ) as follows: Step 0: L(  ) = L(e) = L(  ) = for each    Inductive step: L((    )) = L((  )) = L(  *) = {} {e}{e} {}{} L(  )  L(  ) L(  )L(  ) L(  )*

3 Regular Languages Definition. A language is regular if there exists a regular expression that describes all its strings

4 Examples Example 1. Find L((ab*)a) L(ab*a) = Example 2. Find L((a(a  b)*)). L(a(a  b)*) = L(a)L(b)*L(a) = {w : w is of the form ab n a with n = 0, 1, 2,…} L(a)(L(a)  L(b))* = {aw : w is a word in  }

5 Example Find the regular expression for the language L in the alphabet {a,b} such that the words in L contains the substring aaa Find the regular expression for the language L in the alphabet {a,b} such that the words in L contains the substring aaa or bbb

6 Main Theorem About Finite Automata (Kleene) (1) Given a finite automata A, there is a regular expression expr such that L(A) = L(expr) (2) Given a regular expression expr, there is a finite automata A such that L(A) = L(expr)

7 Algorithm A (from text) Input: a regular expression expr Output: a finite automaton accepting L(expr) 1.Convert any step-0 element (any of the characters in ,  or e) occurring in expr to a finite automaton accepting this element 2.Apply the theorem about closure under set operations to every Union Concatenation Kleene star

8 Recall: Construction on NFA- s M(R1) M(R2) M M(R1 U R2) M M(R1 R2) M M(R*) M(R2) M(R)

9 Exercise Obtain a finite automaton accepting a regular expression: One or two in class How about: (a  a * b) a (ba * ) (a *  b * ) a * b + a Make up several! Use the union, concatenation, and * operations

10 Algorithm B (from text) Input: a finite automaton A Output: a regular expression expr such that L(expr) = L(A) Assumptions about the automaton A: A has a single favorable state If it doesn’t, can this be taken care of ? There are no transitions directed to the initial state If there is one, can this be taken care of ? There are no transitions starting at the favorable state Definition. An expression diagram is a labeled directed graph like a FSA, but with transitions labeled by regular expressions. as opposed to single elements of .

11 Algorithm B – States to RE Unions For every pair of nodes such that there is more than one transition from one to the other one: expr 1 expr 2 … expr n expr 1  expr 2  …  expr n

12 Algorithm B – States to RE Kleene * For every pair of nodes such that there is an intermediate node connecting them: expr 1 expr 3 expr 2 expr 1 (expr 2 )* expr 3

13 Simple Example b a a b q0 q1q2

14 Delete node q1 b a a b q0 q1 q2 ab

15 Delete node q2 b a q0 q2 ab (ab * ab) *

16 Detailed Example b a b a a b b q0 q1q2q3

17 Delete node q1 b a b a a b b q0 q1q2q3bb ab

18 Delete node q2 b a a b  bb q0 q2q3 ab ab*ab

19 Finally a b  bb q0 q3 ab*ab (ab*ab)*a ((b  bb) (ab*ab)*a)*


Download ppt "Conversions Regular Expression to FA FA to Regular Expression."

Similar presentations


Ads by Google