0% found this document useful (0 votes)
23 views33 pages

4-Reg Exp

The document discusses regular expressions and their equivalence to finite automata and generalized nondeterministic finite automata (GNFAs). It defines regular expressions and provides examples of their use and properties. It also describes how to convert between regular expressions, finite automata and GNFAs.

Uploaded by

mythemyaseen6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views33 pages

4-Reg Exp

The document discusses regular expressions and their equivalence to finite automata and generalized nondeterministic finite automata (GNFAs). It defines regular expressions and provides examples of their use and properties. It also describes how to convert between regular expressions, finite automata and GNFAs.

Uploaded by

mythemyaseen6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

1 Regular Languages

1.3 Regular Expressions


Regular Expressions

• The value of the arithmetic expression is the number 32. The value of a regular expression is a
language.
• In this case, the value is the language consisting of all strings starting with a 0 or a 1 followed by
any number of 0s.
• The symbols 0 and 1 are shorthand for the sets {0} and {1}. So (0 ∪ 1) means ({0} ∪ {1}). The
value of this part is the language {0,1}.
• The part 0* means {0}* and its value is the language consisting of all strings containing any
number of 0s.
Regular Expressions
• Applications of regular expressions include:
• Powerful method for describing patterns in text.
• Utilities such as awk and grep in UNIX, modern programming languages such
as Perl, and text editors all provide mechanisms for the description of
patterns by using regular expressions.
Examples

all possible strings of 0s and 1s. If Σ = {0,1}, we can write Σ as shorthand for the
regular expression (0 ∪ 1).

all strings that start with a 0 or end with a 1


Precedence
• In regular expressions, the star operation is done first, followed by
concatenation, and finally union, unless parentheses change the usual
order.
Formal Definition
+ notation
• For convenience, we let R+ be shorthand for RR*. In other words,
whereas R* has all strings that are 0 or more concatenations of strings
from R, the language R+ has all strings that are 1 or more
concatenations of strings from R.
• So R+ ∪ ε = R*.
• In addition, we let Rk be shorthand for the concatenation of k R’s with
each other.
More Examples
More Examples
More Examples
Further Properties
Further Properties
An example from programming languages
• How can you define a numerical constant?
• Examples: 72, 13.4, 0.1, -0.3, +.02, -7.
• Not a numerical constant: -., +.-, -9+
• Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, -, .}
• D = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Equivalence with Finite Automata
Equivalence with Finite Automata
Equivalence with Finite Automata
Equivalence with Finite Automata
Equivalence with Finite Automata
Equivalence with Finite Automata
Generalized Nondeterministic Finite
Automata
• Generalized nondeterministic finite automata (GNFA) are simply
nondeterministic finite automata wherein the transition arrows may
have any regular expressions as labels, instead of only members of the
alphabet or ε.
• The GNFA moves along a transition arrow connecting two states by
reading a block of symbols from the input, which themselves
constitute a string described by the regular expression on that arrow.
GNFA Example
GNFAs
• For convenience, we require that GNFAs always have a special form
that meets the following conditions.
• The start state has transition arrows going to every other state but no arrows
coming in from any other state.
• There is only a single accept state, and it has arrows coming in from every
other state but no arrows going to any other state. Furthermore, the accept
state is not the same as the start state.
• Except for the start and accept states, one arrow goes from every state to
every other state and also from each state to itself.
GNFAs
We can easily convert a DFA into a GNFA in the special form.
• We simply add a new start state with an ε arrow to the old start state and a
new accept state with ε arrows from the old accept states.
• If any arrows have multiple labels (or if there are multiple arrows going
between the same two states in the same direction), we replace each with a
single arrow whose label is the union of the previous labels.
• Finally, we add arrows labeled ∅ between states that had no arrows. This last
step won’t change the language recognized because a transition labeled with
∅ can never be used.
• From here on we assume that all GNFAs are in the special form.
Conversion from GNFA to Regular
Expression
• The stages in converting a DFA with three states to an equivalent
regular expression are shown in the following figure.
Constructing an equivalent GNFA with one fewer
state
An Example
Conversion
Another
example
conversion

You might also like