## Introduction

In a **previous article**, I explained how to convert a regular expression to postfix notation by using the Shunting-Yard algorithm. This is the first step you must do before converting a given regular expression to an NFA. The purpose for using postfix notation is to rearrange the symbols and operations in such a way that the expression can be read from left to right, maintain the order of operations for regular expressions, and not have to handle parsing parentheses.

In the last article, we used the regular expression `**a(a+b)*b**`

, which returns all strings that begin with the letter **a** and end in the letter **b** After we run this expression through the Shunting-Yard algorithm, the postfix result is `**aab+*?b?**`

(remember the **?** symbol represents concatenation). I will now illustrate how to apply **Thompson’s Construction Algorithm** to convert this expression into its respective NFA.

## What is Thompson’s Construction Algorithm?

Thompson’s Construction Algorithm is **a method for converting regular expressions to their respective NFA diagrams**. There are loads of documentation all over the internet that go more in-depth about the inner workings of why this algorithm works and its history, but you can read that on your own time. I want this article to give you a straightforward, understandable approach to this algorithm. All you need to know about Thompson’s Construction Algorithm is that there are **5 simple rules**.

## Rule #1: An Empty Expression

**An empty expression**, for example `‘’`

or `**ε**`

, will be converted to:

## Rule #2: A symbol

**A symbol**, such as `**a**`

or `**b**`

, we will converted to:

## Rule #3: Union expression

**A union expression** `**a+b**`

will be converted to:

## Rule #4: Concatenation expression

**A concatenation expression** `**ab**`

or`**a?b**`

will be converted to:

## Rule #5: A closure/kleene star expression

**A closure **`**a***`

will be converted to:

#software-development #computer-science #formal-languages #mathematics