Processing math: 100%
Close
Close Window

CS4114 Formal Languages Spring 2021

Chapter 4 Regular Languages

Show Source |    | About   «  3.9. More DFA Minimization Exercises   ::   Contents   ::   4.2. Regular Expressions Exercises  »

4.1. Regular Expressions

The Regular Expression (also known as RegEx or RE) is another way to define a language. They are used a lot, especially by programmers for defining simple search patterns. This adds another way to define languages along with the ones that we already know: Grammars, DFAs and NFAs. Or, we could just describe the language using an English description. Why do we need another one?

The problem with an English description (or any other language that people speak) is that it is too imprecise, and not something that we can easily implement. Using a DFA or NFA requires typically requires some sort of graphical editor, and this takes a bit of time to enter. We will see that regular expressions are easy to just type, and they tend to be relatively short descriptions for common languages that we want to represent. Of course, even a relatively small precise specification for a language can be hard to come up with (or to understand). But at least with a regular expression, it is usually quick and easy to type once you have it.

4.1.1. Definition and Examples of Regular Expressions

1 / 27 Settings
<<<>

This slideshow presents the definition and some examples for Regular Expressions.

Proficient Saving... Error Saving
Server Error
Resubmit

Definition for Regular Expressions (RE): Given Σ,
  1. λ, and aΣ are RE

  2. If r and s are regular expressions, then

    • r+s is a RE

    • rs is a RE

    • (r) is a RE

    • r is a RE

  3. r is a RE if and only if it can be derived from (1) with a finite number of applications of (2).

4.1.2. Converting a Regular Expression to a NFA

1 / 13 Settings
<<<>

Part 1. Recall that we define the term regular language to mean the languages that are recognized by a DFA. And we know these are the same as the languages recognized by an NFA, because we know that every NFA can be converted to a DFA (and vice versa).

Now, we will show the relationship between regular languages (and thus, DFAs and NFAs) and Regular Expressions.

Proficient Saving... Error Saving
Server Error
Resubmit

Summary: We can convert any NFA to an equivalent NFA with a single final state. This will be a useful first step.

1 / 12 Settings
<<<>

Part 2. In Part 1, we showed how to convert the base case REs ($\lambda$ and any symbol from $\Sigma$) to NFAs. And we showed that any NFA can be converted to an equivalent NFA with a single final state.

Now we will see how to convert more complex REs to an NFA.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit


1 / 12 Settings
<<<>

Part 3. Next, we will define a construction for the NFA that can accept the RE $r \cdot s$, given that we have NFAs that are equivalent to $r$ and $s$.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit


1 / 12 Settings
<<<>

Part 4. The last operator that we need to implement is the Kleene star ($*$) operator. The operator will concatenate the language with itself zero or more times.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit

Summary: We can convert any RE to an NFA. So, all REs are associated with a regular language.

4.1.3. Regular Expression VS Regular Language Example

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

4.1.4. Regular Expression to Minimized DFA Example

1 / 30 Settings
<<<>>>

In this example, we will convert the regular expression ab*+c to a minimized DFA.

Proficient Saving... Error Saving
Server Error
Resubmit

4.1.5. Converting Regular Languages to Regular Expressions

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

4.1.6. Converting Regular Languages to Regular Expressions Example

1 / 9 Settings
<<<>>>

Suppose we want to convert the following FA to a Regular Expression.

Proficient Saving... Error Saving
Server Error
Resubmit

   «  3.9. More DFA Minimization Exercises   ::   Contents   ::   4.2. Regular Expressions Exercises  »

nsf
Close Window