Bryan Revelo Bscpe-2N Discrete Mathematics: Phase Structure Grammar
Bryan Revelo Bscpe-2N Discrete Mathematics: Phase Structure Grammar
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
Bryan Revelo BSCpE-2N Discrete Mathematics
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.
Bryan Revelo BSCpE-2N Discrete Mathematics
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
Bryan Revelo BSCpE-2N Discrete Mathematics