Phase Structure Grammar: Grammars, (2) Finite-State Machines, and Turing Machine
Phase Structure Grammar: Grammars, (2) Finite-State Machines, and Turing Machine
Backus-Naur Form
There is another notation that is sometimes used to specify a type 2 grammar, called the
Backus–Naur form (BNF), after John Backus, who invented it, and Peter Naur, who refined it for use
in the specification of the programming language ALGOL. (Surprisingly, a notation quite similar to
the Backus–Naur form was used approximately 2500 years ago to describe the grammar of
Sanskrit.) The Backus–Naur form is used to specify the syntactic rules of many computer languages,
including Java. The productions in a type 2 grammar have a single nonterminal symbol as their left-
hand side. Instead of listing all the productions separately, we can combine all those with the same
nonterminal symbol on the left-hand side into one statement. Instead of using the symbol → in a
production, we use the symbol: =. We enclose all nonterminal symbols in brackets, [ ], and we list all
the right-hand sides of productions in the same statement, separating them by bars.
Finite-State Machine
Finite-state machines are used extensively in applications in computer science and data
networking. For example, finite-state machines are the basis for programs for spell checking,
grammar checking, indexing or searching large bodies of text, recognizing speech, transforming text
using markup languages such as XML and HTML, and network protocols that specify how
computers communicate.
Definition 1: A finite-state machine M = (S, I, O, f, g, s0) consists of a finite set S of states, a finite
input alphabet I, a finite output alphabet O, a transition function f that assigns to each state and
input pair a new state, an output function g that assigns to each state and input pair an output, and
an initial state s0.
Example of Finite-State Machine
An important element in many electronic devices is a unit-delay machine, which produces
as output the input string delayed by a specified amount of time. How can a finite-state machine be
constructed that delays an input string by one unit of time, that is, produces as output the bit string
0x1x2...xk−1given the input bit string x1x2...xk?
Solution: A delay machine can be constructed that has two possible inputs, namely, 0 and 1. The
machine must have a start state s0. Because the machine has to remember whether the previous,
Turing Machines
Turing machine consists of a control unit, which at any step is in one of finitely many
different states, together with a tape divided into cells, which is infinite in both directions. Turing
machines have read and write capabilities on the tape as the control unit moves back and forth
along this tape, changing states depending on the tape symbol read. Turing machines are more
powerful than finite-state machines because they include memory capabilities that finite-state
machines lack.
Definition 1: A Turing machine T = (S, I, f, s0) consists of a finite set S of states, an alphabet I
containing the blank symbol B, a partial function f from S × I to S × I ×{R, L}, and a starting state s0.
Definition 2: Let V be a subset of an alphabet I. A Turing machine T = (S, I, f, s0) recognizes a string x
in V ∗if and only if T, starting in the initial position when x is written on the tape, halts in a final
state. T is said to recognize a subset A of V ∗if x is recognized by T if and only if x belongs to A.
Example in Turing Machine
Find a Turing machine that
recognizes the set of bit strings that
have a 1 as their second bit, that
is, the regular set (0 ∪ 1)1(0 ∪ 1)
∗
.
Find a Turing machine that recognizes the set of bit strings that have a 1 as their second bit,
that is, the regular set (0 ∪ 1)1(0 ∪ 1)∗.
Solution: We want a Turing machine that, starting at the leftmost nonblank tape cell, moves right,
and determines whether the second symbol is a 1. If the second symbol is 1, the machine should
move into a final state. If the second symbol is not a 1, the machine should not halt or it should halt
in a non final state.
To construct such a machine, we include the five-tuples (s0, 0, s1, 0, R) and (s0, 1, s1, 1, R) to
read in the first symbol and put the Turing machine in state s1. Next, we include the five-tuples (s1,
0, s2, 0, R) and (s1, 1, s3, 1, R) to read in the second symbol and either move to state s2 if this
symbol is a 0, or to state s3if this symbol is a 1. We do not want to recognize strings that have a 0 as
their second bit, so s2should not be a final state. We want s3to be a final state. So, we can include
the five-tuple (s2, 0, s2, 0, R). Because we do not want to recognize the empty string or a string with
one bit, we also include the five-tuples (s0, B, s2, 0, R) and (s1, B, s2, 0, R).
The Turing machine T consisting of the seven five-tuples listed here will terminate in the
final state s3if and only if the bit string has at least two bits and the second bit of the input string is
a 1. If the bit string contains fewer than two bits or if the second bit is not a 1, the machine will
terminate in the non final state s2.▲Given a regular set, a Turing machine that always moves to the
right can be built to recognize this set (as in Example 2). To build the Turing machine, first find a
finite-state automaton that recognizes the set and then construct a Turing machine using the
transition function of the finite-state machine, always moving to the right.