Mark As Completed Discussion

Acceptors

State machines that change states depending on some input and then produce a binary output are called acceptors. That name is derived from the fact that they're often used to either accept or reject some input, such as a sequence of characters or a sequence of tokens. They're often used to implement frontends of compilers.

Let's start with a simple example. This acceptor checks whether a binary number has an even number of 0s or not. The circle within a circle state indicates a state in which we can end with an even number of zeros. If the input ends in any other state, that means the number is odd (or in the general case, the state machine outputs false). We can have multiple of these end states, but in our even-odd example, there's going to be only one.

Acceptors

The arrow entering even from nowhere is the starting point of the state machine. It can have only one starting point from which it can go into various states depending on the input. A set of possible inputs of a state machine is its alphabet. In the case of our even-odd example, the alphabet would be [0,1]. If any other character is received, it would go into an error state. Sometimes that error state is explicitly drawn, but if it's not on the diagram it just means "any input other than these causes error".

Let's say we want to detect whether a username belongs to our company employee or not, and assume our mandated format is name.sur, where name is persons full first name, while sur is the first three letters of a surname. We could do something like this:

Acceptors

This state machine will take any number of letters (indicated by a cyclical transition), then a point, and then exactly three letters for the surname. In our case, this is case insensitive. Think about how you could make a case-sensitive version of this.

Two major algorithms allow us to turn any regular expression into a finite state machine, called Thompson's construction and Glushkov's algorithm. We won't get into them in this article, but if you want to study this subject more deeply, they're a must.

Acceptors with a single-letter input alphabet are called sequencers.

There's also a class of state machines similar to acceptors, but which can produce n-ary output instead of binary. This means that instead of just differentiating between true or false, even or odd, etc. it can classify given input into n different classes. These state machines are, accordingly, called classifiers.