programming-languagesfinite-automatastate-machine

Finite state automata as (programming) language acceptors


I know how a FSA accepts the string 'nice' (as shown in the Wikipedia page) but how can the language that a FSA accepts be a programming language?

Is it like this?; lets say that I have an alphabet A={1,2,+,-} and language L={1+1,1+2,1-1,1-2} then my FSA looks like this;

-->[1]--1-->[2]--+-->[3]--1-->[[5]]
             |        |
             -        2-->[[6]]
             |
             v
            [4]--1-->[[7]]
             |
             2-->[[8]]

When I reach the accepting states 5, 6, 7, 8 I know what the value should be and therefore I have defined a programming language???

And if I extend it to have nested FSAs then I can compute strings like '1plus2' and 'sqrt(9)'.

Is this thinking correct?


Solution

  • No, that's not quite right. To understand how FSAs are related to computation, you need to adopt a more general view of computation.

    Generally speaking, computation is about taking input and producing output. For now, let's focus on one kind of problem we can compute the answer to: decision problems, where the output is restricted to "yes" or "no". Let's further restrict the kinds of problems we're talking about to those decisions problems whose inputs are strings (like "nice"). These are precisely the kinds of questions that FSAs can be used to answer (but they can't answer all of them!).

    So FSAs can answer (some) questions of the following form: does string X possess property Y? Examples of this are "Is the string one of a known, finite set of strings?", "Is the string the binary representation of an odd number?", "Does the string have 'cat' as a substring?". These can all be answered by FSAs.

    Your problems - like 1+1 - is not a decision problem. You can make it a decision problem, though, as follows: "Is my string of the form 'x+y=z', where x, y and z are decimal representations of integers X, Y and Z and X + Y = Z?" This question, and many like it, cannot be answered using FSAs.

    Stronger kinds of state machines exist; they are not "finite". Examples include pushdown automata (PDAs), linear-bounded automata (LBAs) and Turing machines (TMs). There are some decision problems of the form "does string X possess property Y?" that not even Turing machines, the most powerful known kind of automata, cannot answer. One example is given by the halting problem: "Given 'x(y)' where x is a program and y is an input to the program, does the program represented by X halt when passed the input y?". There is no TM - that is, no algorithm - to answer this question in the general case.

    Can you write an FSA that answers the question "Is the string x a syntactically valid string in this language I'm defining?" Naturally, that depends on the rules of your language. Strings of the form "Number + Number + ... + Number" can be recognized by an FSA, but an FSA can't tell you what the sum is. However, you can't add parentheses to this, or else FSAs are no longer adequate. In other words, there is a difference between recognizing strings and computing results, and FSAs typically are thought of as doing the former.