Title: Regular languages are a subset of LFSA
1Lecture 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
2Regular languages are a subset of LFSA
3Reg. 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
4Visualization
- 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
5Algorithm Specification
- Input
- Regular expression R
- Output
- NFA M such that L(M) L(R)
NFA-l M
Regular expression R
6Recursive 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
7Base 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
8Table lookup
- Finite number of base cases means we can use
table lookup to handle them
f
l
a
b
9Recursive 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
10Recursive 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)
11Pseudocode 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
/ -
12Example
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
13Example 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
14Example 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)
15Pictoral View
concatenate
(ba)a
union
Kleene Closure
a
16Parse Tree
We now present the parse tree for regular
expression (ba)a