Formal-Languages-And-Their-Relation-To-Automata-John-E-Hopcroft-Jeffrey-D-Ullman.Pdf

Total Page:16

File Type:pdf, Size:1020Kb

Formal-Languages-And-Their-Relation-To-Automata-John-E-Hopcroft-Jeffrey-D-Ullman.Pdf FORMAL LANGUAGES AND THEIR RELATION TO AUTOMATA FORMAL LANGUAGES AND THEIR RELATION TO AUTOMATA JOHN E. HOPCROFT Cornell University, Ithaca, New York JEFFREY D. ULLMAN Bell Telephone Laboratories, Murray Hill, New Jersey A VV ADDISON-WESLEY PUBLISHING COMPANY Reading, Massachusetts Menlo Park, California • London • Don Mills, Ontario This book is in the ADDISON-WESLEY SERIES IN COMPUTER SCIENCE AND INFORMATION PROCESSING Consulting Editors MICHAEL A. HARRISON RICHARD S. VARGA Copyright © 1969 by Addison-Wesley Publishing Company, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Published simultaneously in Canada. Library of Congress Catalog Card No. 69-14297. PREFACE The study of formal languages constitutes an important subarea of computer science. This area sprang to life around 1956 when Noam Chomsky gave a mathematical model of a grammar in connection with his study of natural languages. Shortly afterwards, the concept of a grammar was found to be of great importance to the programmer when the syntax of the programming language ALGOL was defined by a context-free grammar. This development led naturally to syntax-directed compiling and the concept of a compiler compiler. Since then a considerable flurry of activity has taken place, the results of which have related formal languages and automata theory to such an extent that it is impossible to treat the areas separately. By now, no serious study of computer science would be complete without a knowledge of the techniques and results from language and automata theory. This book presents the theory of formal languages as a coherent theory and makes explicit its relationship to automata. The book begins with an explanation of the notion of a finite description of a language. The funda- mental descriptive device--the grammar--is explained, as well as its three major subclasses--regular, context-free, and context-sensitive grammars. The context-free grammars are treated in detail, and such topics as normal forms, derivation trees, and ambiguity are covered. Four types of automata equivalent to the four types of grammars are described. These automata are the finite automaton, the pushdown automaton, the linear bounded autom- aton, and the Turing machine. The Turing machine is covered in detail, and unsolvability of the halting problem shown. The book concludes with certain advanced topics in language theory--closure properties, computational complexity, deterministic pushdown automata, LR(k) grammars, stack automata, and decidability. The emphasis is on ideas and ease of understanding rather than undue formalism. In some cases the details of long and tedious proofs are omitted. However, in all cases sufficient intuitive explanation is given so that the reader may easily provide the rigorous proof if desired. The book is intended primarily as a textbook for a first or second year graduate course in formal languages. It is self-contained and presupposes only the normal level of maturity expected of a beginning graduate student. Although not essential, it has been found that a course in finite state machines or Turing machines is useful preparation. The book is not intended as a research monogram on formal languages, although it covers many of the known results, and much of the material presented previously existed only in journals of mathematics and computer science. The chapters are provided with a guide to references on the material covered and related topics. The problems are an integral part of the text and their difficulty ranges from almost trivial to extremely difficult. The material for this book is based upon class notes for courses in language theory taught by the authors at Princeton, Columbia, and Cornel1. The authors would like to thank the many people who offered their sugges- tions and criticism. In particular, we would like to thank A. V. Aho, S. Amoroso, A. Korenjak, and M. Harrison. Thanks are also due to Bell Telephone Laboratories, and Princeton and Cornell Universities for provid- ing the facilities for the preparation of the work. J. E. H. J. D. U. CONTENTS Chapter 1 Languages and Their Representations 1.1 Alphabets and Languages ........... 1 1.2 Procedures and Algorithms .......... 2 1.3 Representations of Languages .......... 5 Problems ................ 7 Chapter 2 Grammars 2.1 Motivation ............... 8 2.2 The Formal Notion of a Grammar ........ 10 2.3 The Types of Grammars ........... 13 2.4 The Empty Sentence ............ 15 2.5 Recursiveness of Context-Sensitive Grammars ..... 16 2.6 Derivation Trees for Context-Free Grammars ..... 18 Problems ................ 24 References ............... 25 Chapter 3 Finite Automata and Regular Grammars 3.1 The Finite Automaton ............ 26 3.2 Equivalence Relations and Finite Automata ..... 28 3.3 Nondeterministic Finite Automata ........ 30 3.4 Finite Automata and Type 3 Languages ....... 33 3.5 Properties of Type 3 Languages ......... 35 3.6 Solvable Problems Concerning Finite Automata .... 39 3.7 Two-way Finite Automata ........... 41 Problems ................ 44 References ............... 45 Chapter 4 Context-Free Grammars 4.1 Simplification of Context-Free Grammars ...... 46 4.2 Chomsky Normal Form ........... 51 4.3 Greibach Normal Form ........... 53 4.4 Solvability of Finiteness and the "uvwxy Theorem" . 57 4.5 The Self-Embedding Property .......... 61 vii 4.6 ~-Rules in Context-Free Grammars ........ 62 4.7 Special Types of Context-Free Languages and Grammars. 63 Problems ................ 65 References ............... 67 Chapter 5 Pushdown Automata 5.1 Informal Description ............ 68 5.2 Definitions ....... ........ 70 5.3 Nondeterministic Pushdown Automata and Context-Free Languages ............... 74 Problems ................ 79 References ............... 79 Chapter 6 Turing Machines 6.1 Introduction ............... 80 6.2 Definitions and Notation ........... 80 6.3 Techniques for Turing Machine Construction ..... 84 6.4 The Turing Machine as a Procedure ....... 91 6.5 Modifications of Turing Machines ........ 92 6.6 Restricted Turing Machines Equivalent tO the Basic Model . 98 Problems ............... 101 References ............... 101 Chapter 7 Turing Machines: The Halting Problem, Type 0 Languages 7.1 Informal Discussion ............ 102 7.2 A Universal Turing Machine ......... 102 7.3 The Unsolvability of the Halting Problem ...... 108 7.4 The Class of Recursive Sets .......... 109 7.5 Turing Machines and Type 0 Grammars ...... 111 Problems ................ 113 References ............... 114 Chapter 8 Linear Bounded Automata and Context-Sensitive Languages 8.1 Introduction ............... 115 8.2 Relation of Linear Bounded Automata to Context-Sensitive Languages ............... 116 8.3 The Context-Sensitive Languages as a Subclass of the Recursive Sets ................. 117 Problems ................ 118 References ............... 119 Chapter 9 Operations on Languages 9.1 Introduction ............... 120 9.2 Closure Under Elementary Operations ....... 120 9.3 Closure Under Mappings ........... 124 Problems ................ 133 References ............... 134 Chapter 10 Time- and Tape-Bounded Turing Machines 10.1 Introduction ............ , . 135 10.2 Definitions ............... 135 10.3 "Speed Up" and "Tape Reduction" Theorems ..... 137 10.4 Single-Tape Turing Machines and Crossing Sequences . 143 10.5 Lower Bounds on Tape Complexity ........ 147 10.6 Tape and Time Hierarchies .......... 149 Problems ................ 154 References ................ 155 Chapter 11 Time and Space Bounds for Recognizing Context-Free Languages 11.1 Introduction ............... 156 11.2 Time Requirements for Recognition of Context-Free Languages 156 11.3 Space Requirements for Recognition of Context-Free Languages 160 Problems ................ 164 References ............... 165 Chapter 12 Deterministic Pushdown Automata 12.1 Introduction ............... 166 12.2 Complements of Deterministic Languages ...... 167 12.3 Properties of Deterministic Languages ....... 171 12.4 Context-Free Languages That Are Not Deterministic . 180 12.5 LR(k) Grammars . ............ 180 Problems ................ 187 References ............... 188 Chapter 13 Stack Automata 13.1 Definitions ............... 189 13.2 Restricted Types of Stack Automata ........ 192 13.3 The Power of Two-Way Stack Automata ...... 192 13.4 The Power of One-Way Stack Automata ...... 201 13.5 Recursiveness of Stack Automata ........ 207 13.6 Closure Properties ............. 209 Problems ................ 209 References ............... 209 Chapter 14 Decidability 14.1 Decidable and Undecidable Questions ....... 211 14.2 Post's Correspondence Problem ......... 212 14.3 A Question Concerning Context-Sensitive Languages . 219 14.4 Unsolvable Questions for Context-Free Languages .... 219 14.5 Ambiguity in Context-Free Languages ....... 222 14.6 Unsolvable Questions Concerning Deterministic Context-Free Languages ............... 229 14.7 Summary of Decision Problems for Regular, LR(k), Context- Free, Context-Sensitive, and Type 0 Grammars .... 231 Problems ................ 231 References ............... 232 Bibliography .......... .... 233 Index ................. 239 CHAPTER 1 LANGUAGES AND THEIR REPRESENTATIONS 1.1 ALPHABETS AND LANGUAGES What is the theory of languages ? To answer this question we first ask"
Recommended publications
  • Uniform Vs. Nonuniform Membership for Mildly Context-Sensitive Languages: a Brief Survey
    algorithms Article Uniform vs. Nonuniform Membership for Mildly Context-Sensitive Languages: A Brief Survey Henrik Björklund *, Martin Berglund and Petter Ericson Department of Computing Science, Umeå University, SE-901 87 Umeå, Sweden; [email protected] (M.B.); [email protected] (P.E.) * Correspondence: [email protected]; Tel.: +46-90-786-9789 Academic Editors: Henning Fernau and Florin Manea Received: 8 March 2016; Accepted: 27 April 2016; Published: 11 May 2016 Abstract: Parsing for mildly context-sensitive language formalisms is an important area within natural language processing. While the complexity of the parsing problem for some such formalisms is known to be polynomial, this is not the case for all of them. This article presents a series of results regarding the complexity of parsing for linear context-free rewriting systems and deterministic tree-walking transducers. We discuss the difference between uniform and nonuniform complexity measures and how parameterized complexity theory can be used to investigate how different aspects of the formalisms influence how hard the parsing problem is. The main results we survey are all hardness results and indicate that parsing is hard even for relatively small values of parameters such as rank and fan-out in a rewriting system. Keywords: mildly context-sensitive languages; parsing; formal languages; parameterized complexity 1. Introduction Context-free and context-sensitive grammars were introduced in the 1950s by Noam Chomsky, as possible formalisms for describing the structure of natural languages; see, e.g., [1]. Context-free grammars (CFG for short), in particular, have been very successful, both when it comes to natural language modelling and, perhaps to an even larger degree, the description of the syntax of programming languages.
    [Show full text]
  • Formal Languages and Automata
    Formal Languages and Automata Stephan Schulz & Jan Hladik [email protected] [email protected] L ⌃⇤ ✓ with contributions from David Suendermann 1 Table of Contents Formal Grammars and Context-Free Introduction Languages Basics of formal languages Formal Grammars The Chomsky Hierarchy Regular Languages and Finite Automata Right-linear Grammars Regular Expressions Context-free Grammars Finite Automata Push-Down Automata Non-Determinism Properties of Context-free Regular expressions and Finite Languages Automata Turing Machines and Languages of Type Minimisation 1 and 0 Equivalence Turing Machines The Pumping Lemma Unrestricted Grammars Properties of regular languages Linear Bounded Automata Scanners and Flex Properties of Type-0-languages 2 Outline Introduction Basics of formal languages Regular Languages and Finite Automata Scanners and Flex Formal Grammars and Context-Free Languages Turing Machines and Languages of Type 1 and 0 3 Introduction I Stephan Schulz I Dipl.-Inform., U. Kaiserslautern, 1995 I Dr. rer. nat., TU Munchen,¨ 2000 I Visiting professor, U. Miami, 2002 I Visiting professor, U. West Indies, 2005 I Lecturer (Hildesheim, Offenburg, . ) since 2009 I Industry experience: Building Air Traffic Control systems I System engineer, 2005 I Project manager, 2007 I Product Manager, 2013 I Professor, DHBW Stuttgart, 2014 Research: Logic & Automated Reasoning 4 Introduction I Jan Hladik I Dipl.-Inform.: RWTH Aachen, 2001 I Dr. rer. nat.: TU Dresden, 2007 I Industry experience: SAP Research I Work in publicly funded research projects I Collaboration with SAP product groups I Supervision of Bachelor, Master, and PhD students I Professor: DHBW Stuttgart, 2014 Research: Semantic Web, Semantic Technologies, Automated Reasoning 5 Literature I Scripts I The most up-to-date version of this document as well as auxiliary material will be made available online at http://wwwlehre.dhbw-stuttgart.de/ ˜sschulz/fla2015.html and http://wwwlehre.dhbw-stuttgart.de/ ˜hladik/FLA I Books I John E.
    [Show full text]
  • Intro to Automata Theory, Languages and Computation John E Hopcroft, Jeffrey D Ullman
    INllHHXXTION AL'lttMATA TIH-'OKY, Kan k ImnncK Kmn D bl I viy KTUNOTES.IN Downloaded from Ktunotes.in INTRODUCTION TO AUTOMATA THEORY, LANGUAGES, COMPUTATION JOHN E. HOPCROFT Cornell University JEFFREY D. ULLMAN Princeton University KTUNOTES.IN AD DI SON-WESLEY PUBLISHING COMPANY Reading, Massachusetts Menlo Park, California London • Amsterdam • Don Mills, Ontario • Sydney Downloaded from Ktunotes.in This book is in the ADDISON -WESLEY SERIES IN COMPUTER SCIENCE Michael A. Harrison, Consulting Editor Library of Congress Cataloging in Publication Data Hopcroft, John E. , 1939- Introduction to automata theory, languages, and computation. Bibliography: p. Includes index. 1. Machine theory. 2. Formal languages. 3- Computational complexity. I. Ullman, Jeffrey D. , 19^2- joint author. II. Title. QA267.H56 629.8'312 78-67950 KTUNOTES.INISBN 0-201-02988-X Copyright (O 1979 by Addison-Wesley Publishing Company, Inc. Philippines copyright 1979 by Addison-Wesley Publishing Company, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photoc6pying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Published simultaneously in Canada. Library of Congress Catalog Card No. 78-67950. ISBN: 0-201-02988-X LMNOPQ-DO-89876 Downloaded from Ktunotes.in PREFACE Ten years ago the authors undertook to produce a book covering the known material on formal languages, automata theory, and computational complexity. In retrospect, only a few significant results were overlooked in the 237 pages. In writing a new book on the subject, we find the field has expanded in so many new directions that a uniform com- prehensive coverage is impossible.
    [Show full text]
  • Formal Languages and Automata
    Formal Languages and Automata Stephan Schulz & Jan Hladik [email protected] [email protected] L ⌃⇤ ✓ with contributions from David Suendermann 1 Table of Contents Introduction Scanners and Flex Lecture 3 Organisation Formal Grammars and Context-Free Lecture 4 Formal languages overview Languages Lecture 5 Formal language basics Formal Grammars Lecture 6 Regular Languages and Finite The Chomsky Hierarchy Lecture 7 Automata Right-linear Grammars Lecture 8 Regular Expressions Context-free Grammars Lecture 9 Finite Automata Push-Down Automata Lecture 10 Properties of Context-free Lecture 11 Non-Determinism Languages Lecture 12 Regular Parsers and Bison Lecture 13 Turing Machines and Languages of Lecture 14 expressions and Type 1 and 0 Lecture 15 Turing Machines Finite Automata Lecture 16 Unrestricted Grammars Lecture 17 Minimisation Linear Bounded Automata Lecture 18 Properties of Type-0-languages Equivalence Lecture-specific material Bonus Exercises The Pumping Lemma Lecture 1 Properties of Regular Languages Lecture 2 Selected Solutions 2 Outline Formal Grammars and Context-Free Introduction Languages Organisation Parsers and Bison Formal languages overview Formal language basics Turing Machines and Languages of Type 1 and 0 Regular Languages and Finite Automata Lecture-specific material Scanners and Flex Bonus Exercises Selected Solutions 3 Outline Formal Grammars and Context-Free Introduction Languages Organisation Parsers and Bison Formal languages overview Formal language basics Turing Machines and Languages of Type 1 and 0 Regular Languages and Finite Automata Lecture-specific material Scanners and Flex Bonus Exercises Selected Solutions 4 Introduction I Stephan Schulz I Dipl.-Inform., U. Kaiserslautern, 1995 I Dr. rer. nat., TU Munchen,¨ 2000 I Visiting professor, U.
    [Show full text]