Rust: Pushdown Automata

Implementing a Simple State Machine in Rust

Ross
The Startup

--

Photo by Zbysiu Rodak on Unsplash

Rust is a really great language. It’s a real pain to get to know the borrow checker, but once you get past that hurdle you can start making some cool things. Today I’d like to discuss how we can make a variant of Finite State Machine known as the Pushdown Automata — in Rust!

Let’s discuss what a Finite State Machine is, first of all. Imagine an application, like a web app client possibly. This application has a variety of states that it can exist in at any point, and only one of those states may be the active state at any given time. If we can determine and define each possible state, we can create a Finite State Machine out of the set of states. A Finite State Machine is the collection of all possible states and their possible transitions. Let’s write an enum that will house our state data.

Empty State enum. We will give it variants soon.

So that tells us pretty much nothing. But don’t worry, we’ll add variants and implementation soon enough. Let’s now discuss the specific Pushdown Automata variant of the Finite State Machine. When a State Machine needs to remember it’s previous states, we can push them down into the State Machine mechanism. Then when we are…

--

--

Ross
The Startup

Programming maniac, #JavaScript zealot. I'm crazy about #FunctionalProgramming and I love Rust. ETH coffee fund: 0x0c37584674e7143e03328254232102973a9cd468