Regular Expression
Regular expression is a simpler way to describe a regular language.
Regular Expression
Definition
Regular expression is an expression that can yield a language (later proved to be a regular language). We note as the language generated by the regular expression .
Regular expression is defined as,
Any sentence is a valid regular expression, .
The of a regular expression is still a regular expression,
The of a regular expression is still a regular expression,
If is a regular expression, is also a regular expression,
If and are regular expressions, then is also a regular expression, .
If and are regular expressions, then is also a regular expression,
Example
For example, the regular expression,
Yields the language,
The expression
Yields the language,
This regular expression yields the language,
Regular Expression can be Represented by e-NFA
We can convert regular expression to e-NFA based on patterns above.
We will firstly simplify the expression by using as little symbols as possible, so that we need to remember fewer patterns.
- We can eliminate with ( consecutive )
- We can eliminate with
Now we only have three patterns,
Sentence
Obviously, if a regular expression is a sentence , we can convert it to an e-NFA directly, with,
The and are the two proximity. Of course, we can remove them to get the same e-NFA, but during the conversion from regular expression to e-NFA, we always keep two nodes with empty transition at the proximity so that later it will be convenient for joining the patterns.
Star Closure
We note,
As a sub graph that accepts the language of the regular expression .
And the e-NFA for is,
Please note that all transition here are empty transition.
Concatenation
Union
Example
Let's convert,
To e-NFA.
We first remove the ,
Then we factor it into,
Where , , , .
When can convert to,
to,
to,
to,
Finally we concatenate them,
We can remove some obviously redundant nodes,
We can further reduce this into NFA, then DFA, minimized DFA.
e-NFA can Test Regular Expressions
DFA and NFA are special e-NFA.
If we get an e-NFA, we can convert it to a regular expression. The method is step-by-step pattern matching.
We note,
Stands for .
For convenience.
Please note that, during the process, we need to mark all in each step as accept states.
Patterns
Typical patterns contains,
Concatenation
Into,
Union
Into,
Star Closure
Into,
Example
Let's take a look back at the e-NFA we got in the previous section,
We can merge some obvious patterns,
Two parallel edges matches our previous union pattern, so,
We can remove an empty transition,
Then,
Finally,
Thus the given e-NFA can be converted into .
This seems a bit different from , but they generates the same language.