Automata-based programming

Another reason for using the notion of automata-based programming is that the programmer's style of thinking about the program in this technique is very similar to the style of thinking used to solve mathematical tasks using Turing machines, Markov algorithms, etc.

The most important property of the program is that the automaton step code section is clearly localized.

With an explicit function step for the automation step, the program better demonstrates this property: The program now clearly demonstrates the basic properties of automata-based code: A finite automaton can be defined by a state-transition table whose rows stand for the current states, columns stand for the inputs, and cells stand for the next states and actions to perform.

The program in C++ using object-oriented style could look like this: To minimize changes not directly related to the subject of the article, the input/output getchar and putchar functions from the standard library of C are being used.

Its main advantages over code using state-transition tables are that virtual function calls are often more efficient than table lookups, that state-transition criteria are more explicit than in tabular format, and that it is easier to add actions accompanying state transitions.

The combination of possible states can generate a wide variety of events, thus defining a more complex production cycle.

There are commonly parallel branches running together and alternatives selected according to different events, schematically represented below: Automata-based programming is widely used in lexical and syntactic analyses.

For instance, UML-based software architecture development uses state diagrams to specify the behaviour of the program.

Thinking in terms of automata (steps and states) can also be used to describe semantics of some programming languages.

Alexander Ollongren in his book[2] explains the so-called Vienna method of programming languages semantics description which is fully based on formal automata.

Automata-based techniques were used widely in the domains where there are algorithms based on automata theory, such as formal language analyses.

[3] One of the earliest mentions of automata-based programming as a general technique is found in the paper by Peter Naur, 1963.

Such methods must not call each other nor themselves, neither directly nor indirectly, otherwise the object can not be considered to be implemented in an automata-based manner.

The state diagram of a finite-state machine that prints the first word of each line of an input stream. The machine follows exactly one transition on each step, depending on the current state and the encountered character. The action accompanying a transition is either a no-operation or the printing of the encountered character, denoted with print .