1 / 16

Module 22

Module 22. Regular languages are a subset of LFSA algorithm for converting any regular expression into an equivalent NFA Builds on existing algorithms described in previous lectures. Regular languages are a subset of LFSA. Reg. Lang. subset LFSA. Let L be an arbitrary regular language

kura
Download Presentation

Module 22

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module 22 • Regular languages are a subset of LFSA • algorithm for converting any regular expression into an equivalent NFA • Builds on existing algorithms described in previous lectures

  2. Regular languages are a subset of LFSA

  3. Reg. Lang. subset LFSA • Let L be an arbitrary regular language • Let R be the regular expression such that L(R) = L • R exists by definition of L is regular • Construct an NFA-l M such that L(M) = L • M is constructed from regular expression R • Argue L(M) = L • There exists an NFA-l M such that L(M) = L • L is in LFSA • By definition of L in LFSA and equivalence of LFSA and LNFA-l

  4. L L R M Regular Expressions NFA-l’s Visualization • Let L be an arbitrary regular language • Let R be the regular expression such that L(R) = L • R exists by definition of L is regular • Construct an NFA-l M such that L(M) = L • M is constructed from regular expression R • Argue L(M) = L • There exists an NFA-l M such that L(M) = L • L is in LFSA • By definition of L in LFSA and equivalence of LFSA and LNFA-l Regular Languages LFSA

  5. A Algorithm Specification * • Input • Regular expression R • Output • NFA M such that L(M) = NFA-l M Regular expression R

  6. Recursive Algorithm • We have an inductive definition for regular languages and regular expressions • Our algorithm for converting any regular expression into an equivalent NFA is recursive in nature • Base Case • Recursive or inductive Case

  7. Base Case • Regular expression R has zero operators • No concatenation, union, Kleene closure • For any alphabet S, only |S| + 2 regular languages can be depicted by any regular expression with zero operators • The empty language f • The language {l} • The |S| languages consisting of one string {a} for all a in S

  8. Table lookup * • Finite number of base cases means we can use table lookup to handle them f l a b

  9. Recursive Case • Regular expression R has at least one operator • This means R is built up from smaller regular expressions using the union, Kleene closure, or concatenation operators • More specifically, there are 3 cases: • R = R1+R2 • R = R1R2 • R = R1*

  10. Recursive Calls 1) R = R1 + R22) R = R1 R23) R = R1* • The algorithm recursively calls itself to generate NFA’s M1 and M2 which accept L(R1) and L(R2) • The algorithm applies the appropriate construction • union • concatenation • Kleene closure to NFA’s M1 and M2 to produce an NFA M such that L(M) = L(R)

  11. Pseudocode Algorithm * _____________ RegExptoNFA(_____________) { regular expression R1, R2; NFA M1, M2; Modify R by removing unnecessary enclosing parentheses /* Base Case */ If R = a, return (NFA for {a}) /* include l here */ If R = f, return (NFA for {}) /* Recursive Case */ Find “last operator O” of regular expression R Identify regular expressions R1 (and R2 if necessary) M1 = RegExptoNFA(R1) M2 = RegExptoNFA(R2) /* if necessary */ return (OP(M1, M2)) /* OP is chosen based on O */ }

  12. Example A: R = (b+a)a* Last operator is concatenation R1 = (b+a) R2 = a* Recursive call with R1 = (b+a) B: R = (b+a) Extra parentheses stripped away Last operator is union R1 = b R2 = a Recursive call with R1 = b

  13. Example Continued C: R = b Base case NFA for {b} returned B: return to this invocation of procedure Recursive call where R = R2 = a D: R = a Base case NFA for {a} returned B: return to this invocation of procedure return UNION(NFA for {b}, NFA for {a}) A: return to this invocation of procedure Recursive call where R = R2 = a*

  14. Example Finished E: R = a* Last operator is Kleene closure R1 = a Recursive call where R = R1 = a F: R = a Base case NFA for {a} returned E: return to this invocation of procedure return (KLEENE(NFA for {a})) A: return to this invocation of procedure return CONCAT(NFA for {b,a}, NFA for {a}*)

  15. (b|a) a* b a a a b a l l a l l l b l l a l a l b l Pictoral View concatenate (b|a)a* union Kleene Closure a

  16. concatenate union Kleene closure b a a Parse Tree We now present the “parse” tree for regular expression (b+a)a*

More Related