Regular languages are a subset of LFSA - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Regular languages are a subset of LFSA

Description:

algorithm for converting any regular expression into an equivalent NFA ... Modify R by removing unnecessary enclosing parentheses /* Base Case ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 17
Provided by: erict9
Learn more at: http://www.cse.msu.edu
Category:

less

Transcript and Presenter's Notes

Title: Regular languages are a subset of LFSA


1
Lecture 23
  • 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
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
Algorithm Specification
  • Input
  • Regular expression R
  • Output
  • NFA M such that L(M) L(R)

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 R1R2
  • R R1R2
  • R R1

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

11
Pseudocode Algorithm
  • NFA RegExptoNFA(regular expression R)
  • 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 (ba)a Last operator is
concatenation R1 (ba) R2 a Recursive
call with R1 (ba) B R (ba) 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 (NFA for a) A
return to this invocation of procedure return
CONCAT(NFA for b,a, NFA for a)
15
Pictoral View
concatenate
(ba)a
union
Kleene Closure
a
16
Parse Tree
We now present the parse tree for regular
expression (ba)a
Write a Comment
User Comments (0)
About PowerShow.com