0% found this document useful (0 votes)
60 views

Phase Structure Grammar: Grammars, (2) Finite-State Machines, and Turing Machine

There are three main types of structures used in models of computation: grammars, finite-state machines, and Turing machines. Grammars are used to generate the words of a language and determine if a word is in the language. Finite-state machines have a set of states, input alphabet, transition function, and starting state. Turing machines have a control unit that changes states and can read and write on an infinite tape to perform computations.

Uploaded by

Bryan Revelo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Phase Structure Grammar: Grammars, (2) Finite-State Machines, and Turing Machine

There are three main types of structures used in models of computation: grammars, finite-state machines, and Turing machines. Grammars are used to generate the words of a language and determine if a word is in the language. Finite-state machines have a set of states, input alphabet, transition function, and starting state. Turing machines have a control unit that changes states and can read and write on an infinite tape to perform computations.

Uploaded by

Bryan Revelo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

three types of structures used in

models of computation, namely,


grammars,
finite-state machines, and Turing
machines
three types of structures used in
models of computation, namely,
grammars,
finite-state machines, and Turing
machines
There are three types of structures used in models of computation namely: (1) Grammars, (2)
finite-state machines, and Turing machine. Grammars are used to generate the words of a language
and to determine whether a word is in a language. Formal languages, which are generated by
grammars, provide models both for natural languages, such as English, and for programming
languages.

Phase Structure Grammar


Definition 1: A vocabulary (or alphabet) V is a finite, nonempty set of elements called symbols. A
word (or sentence) over V is a string of finite length of elements of V .The empty string or null
string, denoted by λ, is the string containing no symbols. The set of all words over V is denoted by
V∗.A language over V is a subset of V
Definition 2: A phrase-structure grammar G = (V, T, S, P) consists of a vocabulary V, a subset T of V
consisting of terminal symbols, a start symbol S from V, and a finite set of productions P. The set V −
T is denoted by N. Elements of N are called nonterminal symbols. Every production in P must
contain at least one nonterminal on its left side.
Definition 3: Let G = (V, T, S, P) be a phrase-structure grammar. Let w0= lz0r (that is, the
concatenation of l, z0, and r) andw1= lz1r be strings over V .Ifz0→ z1is a production of G, we say
that w1is directly derivable from w0and we write w0⇒ w1.Ifw0, w1,..., wn are strings over V such
that w0⇒ w1, w1⇒ w2,..., wn−1⇒ wn, then we say that wn is derivable from w0, and we write
w0∗⇒ wn. The sequence of steps used to obtain wn from w0is called a derivation.
Definition 4: Let G = (V, T, S, P) be a phrase-structure grammar. The language generated by G (or the
language of G), denoted by L (G), and is the set of all strings of terminals that are derivable from the
starting state S. In other words, L (G) = {w ∈ T∗| S∗⇒ w}.
Various types of finite-state machines are used in modeling. All finite-state machines have a
set of states, including a starting state, an input alphabet, and a transition function that assigns a
next state ever pair of a state and an input.
Example of Grammars
1.) Let G be the grammar with vocabulary V={S, A, a, b}, set of terminals T= {a, b}, starting
symbol S, and production P= {S->aA, S->b, A->aa}. What is L (G), the language of this grammar?
Solution: From the start state S we can derive aA using the production S->aA. We can also use the
productions P={S->b to derive b. From aA the production A-> aa can be used to derive aaa. No
additional words can be derived. Hence, L (G) = {b, aaa}.

Types of Phase Structure Grammar


Derivation Trees
A derivation in the language generated by a context-free grammar can be represented graphically
using an ordered rooted tree, called a derivation, or parse tree. The root of this tree represents the
starting symbol. The internal vertices of the tree represent the nonterminal symbols that arise in
the derivation. The leaves of the tree represent the terminal symbols that arise. If the production A
→ w arises in the derivation, where w is a word, the vertex that represents A has as children
vertices that represent each symbol in w, in order from left to right.

dy of natural languages, but also in


the study of programming
languages.
We will describe the sentences of a
formal language using a grammar.
The use of grammars
helps when we consider the two
classes of problems that arise most
frequently in applications
to programming languages: (1) How
can we determine whether a
combination of words is a
valid sentence in a formal language?
(
dy of natural languages, but also in
the study of programming
languages.
We will describe the sentences of a
formal language using a grammar.
The use of grammars
helps when we consider the two
classes of problems that arise most
frequently in applications
to programming languages: (1) How
can we determine whether a
combination of words is a
valid sentence in a formal language?
(
dy of natural languages, but also in
the study of programming
languages.
We will describe the sentences of a
formal language using a grammar.
The use of grammars
helps when we consider the two
classes of problems that arise most
frequently in applications
to programming languages: (1) How
can we determine whether a
combination of words is a
valid sentence in a formal language?
(
dy of natural languages, but also in
the study of programming
languages.
We will describe the sentences of a
formal language using a grammar.
The use of grammars
helps when we consider the two
classes of problems that arise most
frequently in applications
to programming languages: (1) How
can we determine whether a
combination of words is a
valid sentence in a formal language?
(
dy of natural languages, but also in
the study of programming
languages.
We will describe the sentences of a
formal language using a grammar.
The use of grammars
helps when we consider the two
classes of problems that arise most
frequently in applications
to programming languages: (1) How
can we determine whether a
combination of words is a
valid sentence in a formal language?
(

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.

What is the Backus–Naur form of


the grammar for the subset of
English describ e d i n t h e
introduction to this section?
What is the Backus–Naur form of
the grammar for the subset of
English describ e d i n t h e
introduction to this section?
Example in Backus-Naur Form
What is the Backus–Naur form of the grammar for the subset of English described in the
introduction to this section?
Solution: The Backus-Naur form of this grammar is:
[Sentence]::=[noun phrase] [verb phrase]
[noun phrase]::==[article][adjective][noun]|[article][noun]

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.

You might also like