An Introduction To Formal Languages and Automata Book
An Introduction To Formal Languages and Automata Book
PETER LINZ
SUSAN H. RODGER
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page 2 — #3
World Headquarters
Jones & Bartlett Learning
25 Mall Road
Burlington, MA 01803
978-443-5000
[email protected]
www.jblearning.com
Jones & Bartlett Learning books and products are available through most bookstores and online booksellers. To contact
Jones & Bartlett Learning directly, call 800-832-0034, fax 978-443-8000, or visit our website, www.jblearning.com.
Substantial discounts on bulk quantities of Jones & Bartlett Learning publications are available to corporations,
professional associations, and other qualified organizations. For details and specific discount information, contact
the special sales department at Jones & Bartlett Learning via the above contact information or send an email to
[email protected].
Copyright
c 2023 by Jones & Bartlett Learning, LLC, an Ascend Learning Company
All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form,
electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without
written permission from the copyright owner.
The content, statements, views, and opinions herein are the sole expression of the respective authors and not that
of Jones & Bartlett Learning, LLC. Reference herein to any specific commercial product, process, or service by trade
name, trademark, manufacturer, or otherwise does not constitute or imply its endorsement or recommendation by
Jones & Bartlett Learning, LLC and such reference shall not be used for advertising or product endorsement purposes.
All trademarks displayed are the trademarks of the parties noted herein. An Introduction to Formal Languages and
Automata, Seventh Edition is an independent publication and has not been authorized, sponsored, or otherwise approved
by the owners of the trademarks or service marks referenced in this product.
There may be images in this book that feature models; these models do not necessarily endorse, represent, or participate
in the activities represented in the images. Any screenshots in this product are for educational and instructive purposes
only. Any individuals and scenarios featured in the case studies throughout this product may be real or fictitious but
are used for instructional purposes only.
Production Credits
Vice President, Product Management: Marisa R. Urbano Content Services Manager: Colleen Lamy
Vice President, Product Operations: Christine Emerton VP, Manufacturing and Inventory Control: Therese Connell
Product Manager: Ned Hinman Product Fulfillment Manager: Wendy Kilborn
Director, Content Management: Donna Gridley Composition: Straive
Content Strategist: Melissa Duffy Project Management: Straive
Content Coordinator: Mark Restuccia Cover Design: Briana Yates
Director, Project Management and Content Services: Rights & Permissions Manager: John Rusk
Karen Scott Rights Specialist: James Fortney
Manager, Project Management: Jessica deMartin Cover and Title Page: c VS148/Shutterstock.
Project Manager: Roberta Sherman Printing and Binding: Gasch Printing.
Senior Digital Project Specialist: Angela Dooley
Library of Congress Cataloging-in-Publication Data
Names: Linz, Peter, author. | Rodger, Susan H., author.
Title: An introduction to formal languages and automata / Peter Linz, Susan H.
Rodger.
Description: Seventh edition. | Burlington, Massachusetts : Jones &
Bartlett Learning, [2023] | Includes bibliographical references and
index.
Identifiers: LCCN 2021047487 | ISBN 9781284231601 (paperback)
Subjects: LCSH: Formal languages. | Machine theory.
Classification: LCC QA267.3 .L56 2023 | DDC 005.13/1–dc23/eng/20210927
LC record available at https://lccn.loc.gov/2021047487
6048
Printed in the United States of America
26 25 24 23 22 10 9 8 7 6 5 4 3 2 1
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page 3 — #4
© VS148/Shutterstock.
CONTENTS
PREFACE xi
PART I: THEORY 1
2 FINITE AUTOMATA 39
2.1 Deterministic Finite Accepters . . . . . . . . . . . . . . . . . 40
Deterministic Accepters and Transition Graphs . . . . . . . . 41
Languages and Dfa’s . . . . . . . . . . . . . . . . . . . . . . . 43
Regular Languages . . . . . . . . . . . . . . . . . . . . . . . . 48
2.2 Nondeterministic Finite Accepters . . . . . . . . . . . . . . . 53
Definition of a Nondeterministic Accepter . . . . . . . . . . . 54
Why Nondeterminism? . . . . . . . . . . . . . . . . . . . . . . 58
v
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page vi — #7
vi Contents
6 SIMPLIFICATION OF CONTEXT-FREE
GRAMMARS AND NORMAL FORMS 165
6.1 Methods for Transforming Grammars . . . . . . . . . . . . . 166
A Useful Substitution Rule . . . . . . . . . . . . . . . . . . . 167
Removing Useless Productions . . . . . . . . . . . . . . . . . 169
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page vii — #8
Contents vii
viii Contents
14 AN OVERVIEW OF COMPUTATIONAL
COMPLEXITY 371
14.1 Efficiency of Computation . . . . . . . . . . . . . . . . . . . . 372
14.2 Turing Machine Models and Complexity . . . . . . . . . . . . 374
14.3 Language Families and Complexity Classes . . . . . . . . . . 378
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page ix — #10
Contents ix
16 LL PARSING 423
16.1 Context-Free Grammar Conversion to Nondeterministic
Pushdown Automaton . . . . . . . . . . . . . . . . . . . . . . 424
Pushdown Automata for LL Parsing . . . . . . . . . . . . . . 424
Algorithm to Convert Context-Free Grammar to NPDA
for LL Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . 424
16.2 LL(1) Parse Table . . . . . . . . . . . . . . . . . . . . . . . . 429
LL(1) Parse Table . . . . . . . . . . . . . . . . . . . . . . . . 429
16.3 LL(1) Parsing Algorithm . . . . . . . . . . . . . . . . . . . . 431
LL(1) Parsing Algorithm . . . . . . . . . . . . . . . . . . . . 432
16.4 LL(k) Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
17 LR PARSING 441
17.1 Context-Free Grammar Conversion to NPDA . . . . . . . . . 443
Algorithm to Convert Context-Free Grammar to NPDA for
LR Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
17.2 Items and Closure . . . . . . . . . . . . . . . . . . . . . . . . 449
17.3 DFA Models the LR Parsing Stack . . . . . . . . . . . . . . . 453
Algorithm to Build DFA Modeling LR Parsing . . . . . . . . 454
17.4 LR(1) Parse Table . . . . . . . . . . . . . . . . . . . . . . . . 467
LR(1) Parsing Actions . . . . . . . . . . . . . . . . . . . . . . 468
LR(1) Parse Table Algorithm . . . . . . . . . . . . . . . . . . 468
17.5 LR(1) Parsing Algorithm . . . . . . . . . . . . . . . . . . . . 475
LR(1) Parsing Algorithm . . . . . . . . . . . . . . . . . . . . 476
17.6 LR(1) Parsing with λ-Productions . . . . . . . . . . . . . . . 481
17.7 LR(1) Parsing Conflicts . . . . . . . . . . . . . . . . . . . . . 492
x Contents
INDEX 575
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page xi — #12
© VS148/Shutterstock.
PREFACE
T
his book is designed for an introductory course on formal languages,
automata, computability, and related matters. These topics form a
major part of what is known as the theory of computation. A course
on this subject matter is now standard in the computer science curricu-
lum and is often taught fairly early in the program. Hence, the prospec-
tive audience for this book consists primarily of sophomores and juniors
majoring in computer science or computer engineering.
Prerequisites for the material in this book are a knowledge of some
higher-level programming language (commonly C, C++, PythonTM , or
JavaTM ) and familiarity with the fundamentals of data structures and algo-
rithms. A course in discrete mathematics that includes set theory, functions,
relations, logic, and elements of mathematical reasoning is essential. Such
a course is part of the standard introductory computer science curriculum.
The study of the theory of computation has several purposes, most
importantly (1) to familiarize students with the foundations and principles
of computer science, (2) to teach material that is useful in subsequent
courses, and (3) to strengthen students’ ability to carry out formal and
rigorous mathematical arguments. The presentation I have chosen for this
text favors the first two purposes, although I would argue that it also serves
the third. To present ideas clearly and to give students insight into the
material, the text stresses intuitive motivation and illustration of ideas
through examples. When there is a choice, I prefer arguments that are
easily grasped to those that are concise and elegant but difficult in concept.
I state definitions and theorems precisely and give the motivation for proofs
xi
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page xii — #13
xii Preface
but often leave out the routine and tedious details. I believe that this is
desirable for pedagogical reasons. Many proofs are unexciting applications
of induction or contradiction with differences that are specific to particular
problems. Presenting such arguments in full detail is not only unnecessary,
but it interferes with the flow of the story. Therefore, quite a few of the
proofs are brief, and someone who insists on completeness may consider
them lacking in detail. I do not see this as a drawback. Mathematical skills
are not the by-product of reading someone else’s arguments, but they come
from thinking about the essence of a problem, discovering ideas suitable to
make the point, then carrying them out in precise detail. The latter skill
certainly has to be learned, and I think that the proof sketches in this text
provide very appropriate starting points for such a practice.
Computer science students sometimes view a course in the theory of
computation as unnecessarily abstract and of no practical consequence. To
convince them otherwise, one needs to appeal to their specific interests
and strengths, such as tenacity and inventiveness in dealing with hard-to-
solve problems. Because of this, my approach emphasizes learning through
problem solving.
By a problem-solving approach, I mean that students learn the ma-
terial primarily through problem-type illustrative examples that show the
motivation behind the concepts, as well as their connection to the theorems
and definitions. At the same time, the examples may involve a nontrivial
aspect, for which students must discover a solution. In such an approach,
homework exercises contribute to a major part of the learning process. The
exercises at the end of each section are designed to illuminate and illustrate
the material and call on students’ problem-solving ability at various levels.
Some of the exercises are fairly simple, picking up where the discussion in
the text leaves off and asking students to carry on for another step or two.
Other exercises are very difficult, challenging even the best minds. A good
mix of such exercises can be a very effective teaching tool. Students need
not be asked to solve all problems, but should be assigned those that sup-
port the goals of the course and the viewpoint of the instructor. Computer
science curricula differ from institution to institution; while a few empha-
size the theoretical side, others are almost entirely oriented toward practical
application. I believe that this text can serve either of these extremes, pro-
vided that the exercises are selected carefully with the students’ background
and interests in mind. At the same time, the instructor needs to inform the
students about the level of abstraction that is expected of them. This is
particularly true of the proof-oriented exercises. When I say “prove that”
or “show that,” I have in mind that the student should think about how
a proof can be constructed and then produce a clear argument. How for-
mal such a proof should be needs to be determined by the instructor, and
students should be given guidelines on this early in the course.
The content of the text is appropriate for a one-semester course. Most
of the material can be covered, although some choice of emphasis will have
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page xiii — #14
Preface xiii
Peter Linz
Susan H. Rodger
“9781284231601˙TOCx˙Final” — 2022/1/7 — 23:15 — page xiv — #15