next up previous contents
Next: Converting a regular expression Up: REGULAR LANGUAGES Previous: Regular Expressions   Contents

Non-Deterministic Finite-State Automata

In order to try and understand how lex builds a scanner, we will construct a formal model of the scanning process. This model should take characters one-by-one from the input, and identify them with particular patterns which match up with a regular expression.

The standard model used is the finite-state automaton. We can convert any definition involving regular expressions into an implementable finite automaton in two steps:

Regular expression $\longleftrightarrow$ NFA $\longleftrightarrow$ DFA

A non-deterministic finite-state automaton (NFA) consists of:

We can represent a NFA diagrammatically using a (labelled, directed) graph, where states are represented by nodes (circles) and transitions are represented by edges (arrows).

The purpose of an NFA is to model the process of reading in characters until we have formed one of the words that we are looking for.

How an NFA operates:

Basically, in order to match a pattern, we are trying to find a sequence of transitions that will take us from the start state to one of the finish states, consuming all of the input.

The key concept here is that: every NFA corresponds to a regular expression

Moreover, it is fairly easy to convert a regular expression to a corresponding NFA. To see how NFAs correspond to regular expressions, let us describe a conversion algorithm.



Subsections
next up previous contents
Next: Converting a regular expression Up: REGULAR LANGUAGES Previous: Regular Expressions   Contents
James Power 2002-11-29