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.
EXAMPLE 1
Rosen-2311T MHIA017-Rosen-v5.cls
May 13, 2011 10:27 856 13 / Modeling
Computation adjective sleepy
adjective happy noun tortoise
noun hare transitive verb passes
intransitive verb runs adverb
quickly adverb slowly 1. Use the set
of productions to show th
various ways. The grammar of English
tells us whether a combination of
words is a valid sentence. For instance,
the frog writes neatly is a valid
sentence, because it is formed from a
noun phrase, the frog, made up of the
article the and the noun frog, fo
stream into a stream of tokens for use
by a parser. EXAMPLE 9 It follows from
Example 5 that cfw_0n1n | n = 0, 1, 2,. is a
context-free language, because the
productions in this grammar are S
0S1 and S . However, it is not a
regular language. This will b
pigeonhole principle guarantees that
there are at least 800,001/200,000 = 5
Parisians with the same number of
hairs on their heads. 35. 18 37. Because
there are six computers, the number of
other computers a computer is
connected to is an integer between
right and n moves up. Each such path
can be represented by a bit string of
length m + n with m 0s and n 1s, where
a 0 represents a move to the right and a
1 a move up. b) The number of bit
strings of length m + n containing
exactly n 1s equals m+n n = m+n
restrictions on its productions. A type
1 grammar can have productions of the
form w1 w2, where w1 = lAr and w2
= lwr, where A is a nonterminal
symbol, l and r are strings of zero or
more terminal or nonterminal
symbols, and w is a nonempty string of
term
1; terminals T = cfw_0, 1; and
productions S 0S, S 1A, S 1, A
1A, A 1, and S . The details that
this grammar generates the correct set
are left as an exercise for the reader.
Sometimes a set that is easy to
describe can be generated only by a
complicate
computing. In 1955 he served as a
consultant to the building of the first
Danish computer. In 1959 Naur made
the switch from astronomy to
computing as a full-time activity. His
first job as a full-time computer
scientist was participating in the
developme
surrounded by the strings l and r. A
language generated by a type 1
grammar is called a context-sensitive
language. Type 3 grammars are also
called regular grammars. A language
generated by a regular grammar is
called regular. Section 13.4 deals with
the
1955 he joined the faculty at M.I.T.,
beginning his M.I.T. career teaching
engineers French and German.
Chomsky is currently the Ferrari P.
Ward Professor of foreign languages
and linguistics at M.I.T. He is known for
his many fundamental contributions to
13. a verb is hops; 14. an adverb is
quickly, or 15. an adverb is wildly.
From these rules we can form valid
sentences using a series of
replacements until no more rules can
be used. For instance, we can follow the
sequence of replacements: sentence
noun
in linguistics, the study 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
fre
starting symbol, and the productions
are S AB A Ca B Ba B Cb B b
C cb C b. Solution: One way to
approach this problem is to begin with
S and attempt to derive cbab using a
series of productions. Because there is
only one production with S on its lefthand
ago to describe the grammar of
Sanskrit.) The BackusNaur 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 listi
right-hand side, first choose the
distinguished element out of the entire
n-set (this can be done in n ways), and
then choose the remaining k 1
elements of the subset from the
remaining n1 elements of the set (this
can be done in n1 k1 ways). b) k n k
= k
programmer in 1950. He participated
in the design and development of two
of IBMs early computers. From 1954 to
1958 he led the IBM group that
developed FORTRAN. Backus became a
staff member at the IBM Watson
Research Center in 1958. He was part
of the com
the introduction of the section, the set
of terminals is cfw_a, the, rabbit,
mathematician, hops, eats, quickly,
wildly, and the set of nonterminals is
cfw_sentence, noun phrase, verb phrase,
adjective, article, noun, verb, adverb.
There is a special memb
with 1 d) the set of bit strings that
consist of a 0 followed by an even
number of 1s 14. Find a phrasestructure grammar for each of these
languages. a) the set consisting of the
bit strings 10, 01, and 101 b) the set of
bit strings that start with 00 and
spending his summers in New
Hampshire where he attended summer
school and amused himself with
summer activities, including sailing. He
obliged his father by enrolling at the
University of Virginia to study
chemistry. But he quickly decided
chemistry was n
for a grammar that produces signed
integers is signed integer := sign
integer sign := + | integer := digit |
digit integer digit := 0 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 The BackusNaur form,
with a variety of extensions, is used
extensively to specify the
n!/(n1!n2! nk!), as straightforward
simplification shows. 49. a) Because x1
x2 xr, it follows that x1 + 0 < x2 +
1 < < xr + r 1. The inequalities are
strict because xj + j 1 < xj+1 + j as long
as xj xj+1. Because 1 xj n + r 1,
this sequence is made up of
| boxes, one for each element of T . 45.
Let dj be j x N (j x), where N (j x) is the
integer closest to j x for 1 j n. Each dj
is an irrational number between 1/2
and 1/2. We will assume that n is even;
the case where n is odd is messier.
Consider the n i
TABLE 1 Types of Grammars. Type
Restrictions on Productions w1 w2 0
No restrictions 1 w1 = lAr and w2 = lwr,
where A N, l, r,w (N T ) and w =
; or w1 = S and w2 = as long as S is
not on the right-hand side of another
production 2 w1 = A, where A is a
nont
addOperator addOperator := + |
term := factor |factor factor
mulOperator mulOperator := | /
factor := identifier |expression
identifier := a | b | z 39. For each of
these strings, determine whether it is
generated by the grammar given for
postfix notatio
grammar. The other way that contextsensitive grammars are defined is by
specifying that all productions are
noncontracting. A grammar with this
property is called noncontracting or
monotonic. The class of noncontracting
grammars is not the same as the cla
0) to (n, r j ), which by Exercise 33
equals n+rj rj . Because r j=0 n+rj
rj = r k=0 n+k k , it follows that r k=1
n+k k = n+r1 r . 39. a) n+1 2 b) n+2 3
c) 2n2 n1 d) n1 (n1)/2) e)
Largest odd entry in nth row of Pascals
triangle f) 3n3 n1 Section 6.5 1.
replaces S with the empty string. The
solution is the grammar G = (V , T , S,
P ), where V = cfw_0, 1, S, T = cfw_0, 1, S is
the starting symbol, and the
productions are S 0S1 S . The
verification that this grammar
generates the correct set is left as an
Construct phrase-structure grammars
to generate each of these sets. a) cfw_012n
| n 0 b) cfw_0n12n | n 0 c) cfw_0n1m0n |
m 0 and n 0 19. Let V = cfw_S, A, B, a,
b and T = cfw_a, b. Determine whether G
= (V , T , S, P ) is a type 0 grammar but
not a type 1
and a last name, which can be any
string of letters. 33. Give production
rules in BackusNaur form that
generate all identifiers in the C
programming language. In C an
identifier starts with a letter or an
underscore (_) that is followed by one
or more low
derive 0 using S 0, or 11S using S
11S. From 11S we can derive either 110
or 1111S. From 1111S we can derive
11110 and 111111S. At any stage of a
derivation we can either add two 1s at
the end of the string or terminate the
derivation by adding a 0 at th
subscripts, and if any computers with
higher subscripts need a printer
instead of one or more of these, then
they can use the printers that are not
being used, because they are connected
to all the printers. Now we must show
that 1619 cables is not enough
BackusNaur to describe the set of
allowable identifiers: identifier :=
letter |identifier letter |identifier digit
letter := a | b | y | z the ellipsis
indicates that all 26 letters are
included digit := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
| 8 | 9 For example,