Elements of Programming Style

Total Page:16

File Type:pdf, Size:1020Kb

Elements of Programming Style THE ELEMENTS OF PROGRAMMING STYLE SECOND EDITION Kernighan and Plauger THE ELEMENTS OF PROGRAMMING STYLE Second Edition Brian W. Kernighan Bell laboratories Murray Hill, New Jersey P. J. Plauger Yourdon, Inc. New York, New York McGRAW-HILL BOOK COMPANY New York St. Lou1; San Franc1;co Auckland Bogota Du;seldorf London Madnd Mexico Montreal New Delhi Panama Pan' Sao Paulo Singapore Sydney Tokyo Toronto Library of Congress Cataloging in Publication Data Kernighan, Brian W. The elements of programming style. Bibliography: p. Includes index. I. Electronic digital computers-Programming. I. Plauger, P.J., date joint author. II. Title. QA 76.6.K47 1978 001.6'42 78-3498 ISBN 0-07-034207-5 The Elements of Programming Style Copyright © 1978, 1974 by Bell Telephone Laboratories, Incorporated. 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, photocopy­ ing, recording, or otherwise, without the prior written permission of Bell Laboratories. Printed in the United States of America. 12 13 14 15 DODO 8 9 This book was set in Times Roman and Courier 12 by the authors, using a Graphic Sys­ tems phototypesetter driven by a PDP-11/70 running under the UNIX operating system. UNIX is a Trademark of Bell Laboratories. We are deeply indebted to the following authors and publishers for their kind permission to reproduce excerpts from the following copyrighted material: R V Andree, J P Andree, and D D Andree, Computer Programmmg Techniques, A nalys1s, and Mathematics. Copyright © 1973 by R V Andree By permission of Prentice-Hall, Inc F Bates and M L Douglas, Programmmg Language/One with Structured Programming (Thtrd Edmon) Copyright © 1975 by Prentice-Hall, Inc Reprinted by permission C R Bauer and A P Peluso, Basic Fortran IV with Waifor & Wa(/iv. Copyright © 1974 by Addison-Wesley Publishing Com­ pany, Inc By permission C R Bauer, A P Peluso, and D A Gomberg, Baste PL/I Programming. Copyright © 1968 by Addison-Wesley Publishing Company, Inc By permission M Bohl and A Walter, Introduction to PL/I Programming and PL/C. Copyright © 1973 by Science Research Associates, Inc Reprinted by permission of the publisher V J Calderbank, A Course on Programming m Fortran IV. Copyright © 1969 by Chapman and Hall, Ltd By permission Paul M Chirlian, lntroductt0n to Fortran IV Copyright © 1973 by Academic Press By permission Frank J Clark, lntroduc11on to PL/I Programming. Copyright© 1971 by Allyn and Bacon, Inc By permission Computerworld Copyright© 1972 by Computerworld, Newton, Mass 02160 By permission Datoma11on9 Copyright© 1972, 1973 by Technical Publishing Company, Greenwich, Connecticut 06830 Reprinted with per­ mission D F DeTar, Prmetples of Fortran Programming. Copyright © 1972 by W A Benjamin, Inc, Menlo Park, California By per­ mission of the publisher H Dinter, lntroductt0n to Computing. Copyright © 1973, Heinz Dinter By permission of The Macmillan Company, New York D Dmitry and T Mott, Jr, lntroduc11on to Fortran IV Programming Copyright © Holt, Rinehart and Winston, Inc, 1966 By permission V T Dock, Fortran IV Programming, Copyright © 1972 by Reston Publishing Company, Inc By permission W S Dorn, G G Bitter, and D L Hector, Computer Appltca11ons for Calculus Copyright © Prindle, Weber & Schmidt, Inc, 1972 By permission W S Dorn and D D McCracken, Numerical Methods with Fortran IV Case Studtes. Copyright © 1972 by John Wiley & Sons, Inc By permission L E Edwards, PL// for Busmess Applica11ons. Copyright© 1973 by Reston Publishing Company, Inc By permission M V Farina, Fortran IV Seif-Taught. Copyright© Prentice-Hall, Inc, 1966 By permission B S Gottfried, Programming with Fortran IV Copyright© 1972 by Quantum Publishers, Inc By permission Gabriel F Groner, PL// Programming 1n Technological Applteatt0ns. Copyright © 1971 by John Wiley and Sons, Inc Reprinted by permission of the publisher N Haag, Comprehensive Standard Fortran Programmmg. Copyright© Hayden Book Company, Inc, 1969 By permission K Hughes, PL/I Programming. Copyright © 1973 by John Wiley & Sons, Inc By permission K Hughes and J I Michtom, A Structured Approach to Programming Copyright © 1977 by Prentice-Hall, Inc Reprinted by permission R J Kochenburger and C J Turcio, Introduction to PL/I and PL/C Programming - Instructor's Guide Copyright © 1974 by John Wiley & Sons, Inc By permission C B Kreitzberg and B Shneiderman, The Elements of Fortran Style. Copyright © 1972 by Harcourt Brace Jovanovich, Inc By permission J L Kuester and J H Mize, Op11m1za11on Techniques with Fortran Copyright © 1973 by McGraw-Hill, Inc By permission S S Kuo, Computer Applica11ons of Numer1cal Methods. Copyright ©Addison-Wesley Publishing Company, 1972 By permis­ sion H L Ledgard, Programming Proverbs Copyright © 1975 by Hayden Book Company By permission R S Ledley, Fortran IV Programming. Copyright© McGraw-Hill, Inc, 1966 By permission G 0 Manifold, Ca/cu/atmg W1th Fortran Copyright © 1972 by Charles E Merrill Publishing Co , Inc By permission W A Manning and R S Gamero, A Fortran IV Problem Solver. Copyright © McGraw-Hill, Inc, 1970 By permission E Marxer and D Hartford, Elements of Computer Programming: Fortran. Copyright© 1973 Published by Delmar Publishers, a division of Litton Educational Publishing, Inc By permission D D McCracken, A Guide to Fortran IV Programming Copyright © 1965 by John Wiley and Sons, Inc Reprinted by permis­ sion of the publisher v vi THE ELEMENTS OF PROGRAMMING STYLE D D McCracken, A Guide to Fortran IV Programming, Second Edmon Copyright © 1972 by John Wiley and Sons, Inc Re­ printed by permission of the publisher C L McGowan and J R Kelly, Top-Down Structured Programming Techniques Copyright © 1975 by Litton Educational Pub­ lishing, Inc Reprinted by permission of Van Nostrand Reinhold Company, a division of Litton Educational Publishing, Inc L P Meissner, The Science ofCompullng. Copyright© 1974 by Wadsworth Publishing Company, Inc By permission H Mullish, Modern Programming: Fortran IV Copyright © 1968 by John Wiley & Sons, Inc By permission Paul W Murrill and Cecil L Smith, Fortran IV Programming for Engineers and Scientists, Second Edmon Ontext) Copyright © 1973 by Harper & Row, Publishers, Inc Used by permission of Harper & Row, Publishers Paul W Murrill and Cecil L Smith, PL/I Programming Ontext) Copyright© 1973 by Harper & Row, Publishers, Inc Used by permission of Harper & Row, Publishers R L Nolan, Fortran IV Compullng and App/1ca11ons Copyright © Addison-Wesley Publishing Company, 1971 By permission E I Organick and L P Meissner, For1ran IV (Second Edmon) Copyright © 1974 by Addison-Wesley Publishing Company, Inc By permission S V Pollack, A Guide to Fortran IV. Copyright © Columbia University Press, 1965 By permission Seymour V Pollack and Theodor D Sterling, A Guide to PL/I Copyright © 1969 by Holt, Rinehart and Winston Reprinted by permission of Holt, Rinehart and Winston Seymour V Pollack and Theodor D Sterling, A Guide 10 Pl// (Second Ed1t1onJ Copyright © 1976 by Holt, Rinehart and Win•• ton Reprinted by permission of Holt, Rinehart and Winston Seymour V Pollack and Theodor D Sterling, Essen11als of PL/I Copyright © 1974 by Holt, Rinehart and Winston Reprinted by permission of Holt, Rinehart and Winston A Ralston, Fortran IV Programming, A Concise Expos111on Copyright© McGraw-Hill, Inc, 1971 By permission J K Rice and J R Rice, lntroduc11on to Computer Science Copyright © 1969 by Holt, Rinehart and Winston, Inc Reprinted by permission of Holt, Rinehart and Winston, Inc G L Richardson and S J Birkin, Program Solving Using Pl/C Copyright © 1975 by John Wiley ~· Sons, Inc By permission J S Roper, Pl/I in Easy Stages Copyright© 1973 by Paul Elek (Scientific Books) Ltd By permis-.;m W P Rule, Fortran IV Programming Copyright © 1968 by W P Rule Prindle, Weber & Schmidt, Inc By permission School Mathematics Study Group, Algortthms, Computa11on and Mathema11cs, Fortran Supplement. Studen1 Tex1 (Revised Edt110n) Copyright ©Stanford University, 1966 By permission No endorsement by SMSG is implied G L Scott and J Scott, Pl/I. A Se!f-lnstruc11onal Manual Copyright © 1969 by Dickenson Publishing Company By permis­ sion R C Scott and N E Sondak, Pl// for Programmers Copyright ©Addison-Wesley Publishing Company, 1970 By permission Donald D Spencer, Programming with USA S1andard Fortran and Fortran IV Copyright© 1969 by Xerox Corporation Used by permission of Ginn and Company (Xerox Corporation) Donald D Spencer, Computers and Programming Guide For Engineers Copyright © 1973 by Howard W Sams & Co. Inc By permission R C Sprowls, lntroduc11on to Pl/I Programming Copyright © 1969 by Harper & Row, Publishers. Inc By permission R A Stern and N B Stern. Principles of Data Processing Copyright © 1973 by John Wiley & Sons. Inc By permission F Stuart, Fortran Programming Copyright © 1969 by Fredric Stuart Reprinted by permission of John Wiley and Sons, Inc A Vazsonyi, Problem Solving by D1g1tal Computers wl/h Pl/I Programming Copyright © Prentice-Hall, Inc. 1970 By permis­ sion T M Walker and W W Cotterman, An Introduction to Computer Science and A/gortthm1c Processes Copyright© 1971 by Allyn and Bacon. Inc Used by permission G M Weinberg, Pl/I Programming· A Manual of Style Copyright© McGraw-Hill, Inc. 1970 By permission CONTENTS Preface to the Second Edition ix Preface to the First Edition xi 1. Introduction 1 2. Expression 9 3. Control Structure 31 4. Program Structure 59 5. Input and Output 83 6. Common Blunders 101 7. Efficiency and Instrumentation 123 8. Documentation 141 Epilogue 155 Supplementary Reading 157 Summary of Rules 159 Index 163 vii PREFACE to the Second Edition The practice of computer programming has changed since The Elements of Pro­ gramming Style first appeared. Programming style has become a legitimate topic of discussion. After years of producing "write-only code," students, teachers, and computing professionals now recognize the importance of readable programs. There has also been a widespread acceptance of structured programming as a valuable cod­ ing discipline, and a growing recognition that program design is an important phase, too often neglected in the past.
Recommended publications
  • GNU M4, Version 1.4.7 a Powerful Macro Processor Edition 1.4.7, 23 September 2006
    GNU M4, version 1.4.7 A powerful macro processor Edition 1.4.7, 23 September 2006 by Ren´eSeindal This manual is for GNU M4 (version 1.4.7, 23 September 2006), a package containing an implementation of the m4 macro language. Copyright c 1989, 1990, 1991, 1992, 1993, 1994, 2004, 2005, 2006 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License.” i Table of Contents 1 Introduction and preliminaries ................ 3 1.1 Introduction to m4 ............................................. 3 1.2 Historical references ............................................ 3 1.3 Invoking m4 .................................................... 4 1.4 Problems and bugs ............................................. 8 1.5 Using this manual .............................................. 8 2 Lexical and syntactic conventions ............ 11 2.1 Macro names ................................................. 11 2.2 Quoting input to m4........................................... 11 2.3 Comments in m4 input ........................................ 11 2.4 Other kinds of input tokens ................................... 12 2.5 How m4 copies input to output ................................ 12 3 How to invoke macros........................
    [Show full text]
  • UNIX Reference Card
    UNlxt Reference Card distributed by Computing Information Service BELL LABORATORIES Murray Hill, N. J. 07974 compiled by Lorinda Cherry Second Edition March, 1979 TABLE OF CO~TEJIo"TS la. GENERAL UNIX COMMANDS adb general purpose debugger ...S. 21 ar archive & library maimainer. ..S as assembler. ..S at execute commands at designated time S awk pattern scanning & processing language S bas basic ...S basename strip filename affixes ...5 be arbitrary precision interactive language ... S calendar reminder service ... 5 cat concatenate & print...5 cb C program beautifier ...no arguments cc C compiler ...5 cd change working directory 5 chgrp change groupoid of files 6 . chmod change mode of files S chown change owner of files 6 cmp compare 2 files ...6 col filter reverse line feeds ...6 comm print" lines common to 2 files ...6 cp copy ...6 crypt encode/decode 6 date print or set date 6 de desk calculator 6 dd convert & copy a file ...6 deroff remove text formatting commands ...6 diff differential file comparator. ..6 dUO 3-way differential file comparison ...6 du summarize disk usage ...6 echo echo arguments ...7 ed text editor. ..7, 20 egrep full regular expression pattern search ...8 enroll enroll in secret mail...no arguments eqn typeset mathematics ...7. 29 expr evaluate arguments as expressions ...7 fT7 Fortran 77 compiler ... 7 factor factor a number ...7 false truth value ...no arguments fgrep search for a fixed pauern ...8 file determine file type ...7 find find files ...7 graph draw a graph ...7 grep search a file for a pattern ...8 join relational database operator.
    [Show full text]
  • GNU M4, Version 1.4.19 a Powerful Macro Processor Edition 1.4.19, 28 May 2021
    GNU M4, version 1.4.19 A powerful macro processor Edition 1.4.19, 28 May 2021 by Ren´eSeindal, Fran¸coisPinard, Gary V. Vaughan, and Eric Blake ([email protected]) This manual (28 May 2021) is for GNU M4 (version 1.4.19), a package containing an implementation of the m4 macro language. Copyright c 1989{1994, 2004{2014, 2016{2017, 2020{2021 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License." i Table of Contents 1 Introduction and preliminaries ::::::::::::::::: 3 1.1 Introduction to m4 :::::::::::::::::::::::::::::::::::::::::::::: 3 1.2 Historical references :::::::::::::::::::::::::::::::::::::::::::: 3 1.3 Problems and bugs ::::::::::::::::::::::::::::::::::::::::::::: 4 1.4 Using this manual :::::::::::::::::::::::::::::::::::::::::::::: 5 2 Invoking m4::::::::::::::::::::::::::::::::::::::: 7 2.1 Command line options for operation modes ::::::::::::::::::::: 7 2.2 Command line options for preprocessor features ::::::::::::::::: 8 2.3 Command line options for limits control ::::::::::::::::::::::: 10 2.4 Command line options for frozen state ::::::::::::::::::::::::: 11 2.5 Command line options for debugging :::::::::::::::::::::::::: 11 2.6 Specifying input files on the command line :::::::::::::::::::::
    [Show full text]
  • Programmer's Manual. the Documents Here Are Grouped
    Programmer’s Manual. The documents here are grouped roughly into the areas of basics, editing, language tools, document preparation, and system maintenance. Further general information may be found in the Bell System Tech- nical Journal special issue on UNIX, July-August, 1978. Many of the documents cited within this volume as Bell Laboratories internal memoranda or Computing Science Technical Reports (CSTR) are also contained here. These documents contain occasional localisms, typically references to other operating systems like GCOS and IBM. In all cases, such references may be safely ignored by UNIX users. General Works 1.7th Edition UNIX — Summary. A concise summary of the facilities available on UNIX. 2.The UNIX Time-Sharing System. D. M. Ritchie and K. Thompson. The original UNIX paper, reprinted from CACM. Getting Started 3.UNIX for Beginners — Second Edition. B. W. Kernighan. An introduction to the most basic use of the system. 4.A Tutorial Introduction to the UNIX Text Editor. B. W. Kernighan. An easy way to get started with the editor. 5.Advanced Editing on UNIX. B. W. Kernighan. The next step. 6.An Introduction to the UNIX Shell. S. R. Bourne. An introduction to the capabilities of the command interpreter, the shell. 7.Learn — Computer Aided Instruction on UNIX. M. E. Lesk and B. W. Kernighan. Describes a computer-aided instruction program that walks new users through the basics of files, the edi- tor, and document preparation software. Document Preparation 8.Typing Documents on the UNIX System. M. E. Lesk. Describes the basic use of the formatting tools. Also describes ‘‘−ms’’, a standardized package of format- ting requests that can be used to lay out most documents (including those in this volume).
    [Show full text]
  • Inf 212 Analysis of Prog. Langs Elements of Imperative Programming Style
    INF 212 ANALYSIS OF PROG. LANGS ELEMENTS OF IMPERATIVE PROGRAMMING STYLE Instructors: Kaj Dreef Copyright © Instructors. Objectives Level up on things that you may already know… ! Machine model of imperative programs ! Structured vs. unstructured control flow ! Assignment ! Variables and names ! Lexical scope and blocks ! Expressions and statements …so to understand existing languages better Imperative Programming 3 Oldest and most popular paradigm ! Fortran, Algol, C, Java … Mirrors computer architecture ! In a von Neumann machine, memory holds instructions and data Control-flow statements ! Conditional and unconditional (GO TO) branches, loops Key operation: assignment ! Side effect: updating state (i.e., memory) of the machine Simplified Machine Model 4 Registers Code Data Stack Program counter Environment Heap pointer Memory Management 5 Registers, Code segment, Program counter ! Ignore registers (for our purposes) and details of instruction set Data segment ! Stack contains data related to block entry/exit ! Heap contains data of varying lifetime ! Environment pointer points to current stack position ■ Block entry: add new activation record to stack ■ Block exit: remove most recent activation record Control Flow 6 Control flow in imperative languages is most often designed to be sequential ! Instructions executed in order they are written ! Some also support concurrent execution (Java) But… Goto in C # include <stdio.h> int main(){ float num,average,sum; int i,n; printf("Maximum no. of inputs: "); scanf("%d",&n); for(i=1;i<=n;++i){
    [Show full text]
  • Jalopy User's Guide V. 1.9.4
    Jalopy - User’s Guide v. 1.9.4 Jalopy - User’s Guide v. 1.9.4 Copyright © 2003-2010 TRIEMAX Software Contents Acknowledgments . vii Introduction . ix PART I Core . 1 CHAPTER 1 Installation . 3 1.1 System requirements . 3 1.2 Prerequisites . 3 1.3 Wizard Installation . 4 1.3.1 Welcome . 4 1.3.2 License Agreement . 5 1.3.3 Installation Features . 5 1.3.4 Online Help System (optional) . 8 1.3.5 Settings Import (optional) . 9 1.3.6 Configure plug-in Defaults . 10 1.3.7 Confirmation . 11 1.3.8 Installation . 12 1.3.9 Finish . 13 1.4 Silent Installation . 14 1.5 Manual Installation . 16 CHAPTER 2 Configuration . 17 2.1 Overview . 17 2.1.1 Preferences GUI . 18 2.1.2 Settings files . 29 2.2 Global . 29 2.2.1 General . 29 2.2.2 Misc . 32 2.2.3 Auto . 35 2.3 File Types . 36 2.3.1 File types . 36 2.3.2 File extensions . 37 2.4 Environment . 38 2.4.1 Custom variables . 38 2.4.2 System variables . 40 2.4.3 Local variables . 41 2.4.4 Usage . 42 2.4.5 Date/Time . 44 2.5 Exclusions . 44 2.5.1 Exclusion patterns . 45 2.6 Messages . 46 2.6.1 Categories . 47 2.6.2 Logging . 48 2.6.3 Misc . 49 2.7 Repository . 49 2.7.1 Searching the repository . 50 2.7.2 Displaying info about the repository . 50 2.7.3 Adding libraries to the repository . 50 2.7.4 Removing the repository .
    [Show full text]
  • C Style and Coding Standards
    -- -- -1- C Style and Coding Standards Glenn Skinner Suryakanta Shah Bill Shannon AT&T Information System Sun Microsystems ABSTRACT This document describes a set of coding standards and recommendations for programs written in the C language at AT&T and Sun Microsystems. The purpose of having these standards is to facilitate sharing of each other’s code, as well as to enable construction of tools (e.g., editors, formatters). Through the use of these tools, programmers will be helped in the development of their programs. This document is based on a similar document written by L.W. Cannon, R.A. Elliott, L.W. Kirchhoff, J.H. Miller, J.M. Milner, R.W. Mitze, E.P. Schan, N.O. Whittington at Bell Labs. -- -- -2- C Style and Coding Standards Glenn Skinner Suryakanta Shah Bill Shannon AT&T Information System Sun Microsystems 1. Introduction The scope of this document is the coding style used at AT&T and Sun in writing C programs. A common coding style makes it easier for several people to cooperate in the development of the same program. Using uniform coding style to develop systems will improve readability and facilitate maintenance. In addition, it will enable the construction of tools that incorporate knowledge of these standards to help programmers in the development of programs. For certain style issues, such as the number of spaces used for indentation and the format of variable declarations, no clear consensus exists. In these cases, we have documented the various styles that are most frequently used. We strongly recommend, however, that within a particular project, and certainly within a package or module, only one style be employed.
    [Show full text]
  • Time-Sharing System
    UNIXTM TIME-SHARING SYSTEM: UNIX PROGRAMMER'S MANUAL Seventh Edition, Volume 2B January, 1979 Bell Telephone Laboratories, Incorporated Murray Hill, New Jersey Yacc: Yet Another Compiler-Compiler Stephen C. Johnson Bell Laboratories Murray Hill, New Jersey 07974 ABSTRACT Computer program input generally has some structure; in fact, every computer program that does input can be thought of as de®ning an ``input language'' which it accepts. An input language may be as complex as a programming language, or as sim- ple as a sequence of numbers. Unfortunately, usual input facilities are limited, dif®cult to use, and often are lax about checking their inputs for validity. Yacc provides a general tool for describing the input to a computer program. The Yacc user speci®es the structures of his input, together with code to be invoked as each such structure is recognized. Yacc turns such a speci®cation into a subroutine that handles the input process; frequently, it is convenient and appropriate to have most of the ¯ow of control in the user's application handled by this subroutine. The input subroutine produced by Yacc calls a user-supplied routine to return the next basic input item. Thus, the user can specify his input in terms of individual input characters, or in terms of higher level constructs such as names and numbers. The user-supplied routine may also handle idiomatic features such as comment and con- tinuation conventions, which typically defy easy grammatical speci®cation. Yacc is written in portable C. The class of speci®cations accepted is a very gen- eral one: LALR(1) grammars with disambiguating rules.
    [Show full text]
  • A Description of One Programmer's Programming Style Revisited
    A Description of One Programmer’s Programming Style Revisited Adam N. Rosenberg 1990 August 1 2001 October 1 ABSTRACT We present the outlook of a programmer at AT&T Bell Labs who has written much code during his eight years there and thirteen years in other places. This document describes the author’s own programming style and what he considers important in generating reli- able, readable, and maintainable code. Since this document is the opinions and prejudices of an individual, it is written in the first person in a conversational tone, and with subjects covered in no particular order. It is intended to be a repository of good questions rather than a source of answers. The author feels that many programmers suffer from gross inattention to detail in writing code. He suggests that clarity and consistency will be rewarded sooner than most people think. A veteran of many languages and operating systems, the author today finds himself using the MS-DOS and UNIXr operating systems and the FORTRAN and C languages. The examples here are all either FORTRAN or C. A decade later the author feels that programming productivity in our “post modern” world has decreased sharply from 1990 to 2000. Many of the reasons for this decline were discussed in the original version of this paper. Our pleasure in prescient prognostication is mitigated by frustration with the “dumbing down” of computing in general. Based on this unhappy downturn of programming education and style, we have added materal (in italics) emphasizing areas of recent concern. The original text and examples (still in regular type) have been left virtually intact.
    [Show full text]
  • Oral History of Brian Kernighan
    Oral History of Brian Kernighan Interviewed by: John R. Mashey Recorded April 24, 2017 Princeton, NJ CHM Reference number: X8185.2017 © 2017 Computer History Museum Oral History of Brian Kernighan Mashey: Well, hello, Brian. It’s great to see you again. Been a long time. So we’re here at Princeton, with Brian Kernighan, and we want to go do a whole oral history with him. So why don’t we start at the beginning. As I recall, you’re Canadian. Kernighan: That is right. I was born in Toronto long ago, and spent my early years in the city of Toronto. Moved west to a small town, what was then a small town, when I was in the middle of high school, and then went to the University of Toronto for my undergraduate degree, and then came here to Princeton for graduate school. Mashey: And what was your undergraduate work in? Kernighan: It was in one of these catch-all courses called Engineering Physics. It was for people who were kind of interested in engineering and math and science and didn’t have a clue what they wanted to actually do. Mashey: <laughs> So how did you come to be down here? Kernighan: I think it was kind of an accident. It was relatively unusual for people from Canada to wind up in the United States for graduate school at that point, but I thought I would try something different and so I applied to six or seven different schools in the United States, got accepted at some of them, and then it was a question of balancing things like, “Well, they promised that they would get you out in a certain number of years and they promised that they would give you money,” but the question is whether, either that was true or not and I don’t know.
    [Show full text]
  • Lab Manual of Compiler Design
    LAB MANUAL OF COMPILER DESIGN Department of Electronics & Computer Engg. Dronacharya College Of Engineering Khentawas, Gurgaon – 123506 LIST OF EXPERIMENTS S. No. AIM OF EXPERIMENT 1. STUDY OF LEX AND YACC TOOLS. 2 TO CONVERT REGULAR EXPRESSION INTO NFA. 3 WAP TO FIND FIRST IN CFG. 4. WAP TO FIND STRING IS KEYWORD OR NOT. 5. WAP TO FIND STRING IS IDENTIFIER OR NOT. 6. WAP TO FIND STRING IS CONSTANT OR NOT. 7. WAP TO COUNT NO. OF WHITESPACES AND NEWLINE. 8. WAP TO GENERATE TOKENS FOR THE GIVEN GRAMMER. 9. AN ALGO TO CONVERT NFA TO DFA. 10. AN ALGO FOR MINIMIZING OF DFA. 11. WAP TO CHECK STRING IS IN GRAMMER OR NOT. 12. WAP TO CALCULATE LEADING FOR ALL NON TERMINALS . 13. WAP TO CALCULATE TRAILING FOR ALL NON TERMINALS . PROGRAM NO:-1 PRACTICE OF LEX/YACC OF COMPILER WRITING A compiler or interpreter for a programming language is often decomposed into two parts: 1. Read the source program and discover its structure. 2. Process this structure, e.g. to generate the target program. Lex and Yacc can generate program fragments that solve the first task. The task of discovering the source structure again is decomposed into subtasks: 1. Split the source file into tokens (Lex). 2. Find the hierarchical structure of the program (Yacc). Lex - A Lexical Analyzer Generator Lex is a program generator designed for lexical processing of character input streams. It accepts a high-level, problem oriented specification for character string matching, and produces a program in a general purpose language which recognizes regular expressions.
    [Show full text]
  • Comparative Studies of 10 Programming Languages Within 10 Diverse Criteria Revision 1.0
    Comparative Studies of 10 Programming Languages within 10 Diverse Criteria Revision 1.0 Rana Naim∗ Mohammad Fahim Nizam† Concordia University Montreal, Concordia University Montreal, Quebec, Canada Quebec, Canada [email protected] [email protected] Sheetal Hanamasagar‡ Jalal Noureddine§ Concordia University Montreal, Concordia University Montreal, Quebec, Canada Quebec, Canada [email protected] [email protected] Marinela Miladinova¶ Concordia University Montreal, Quebec, Canada [email protected] Abstract This is a survey on the programming languages: C++, JavaScript, AspectJ, C#, Haskell, Java, PHP, Scala, Scheme, and BPEL. Our survey work involves a comparative study of these ten programming languages with respect to the following criteria: secure programming practices, web application development, web service composition, OOP-based abstractions, reflection, aspect orientation, functional programming, declarative programming, batch scripting, and UI prototyping. We study these languages in the context of the above mentioned criteria and the level of support they provide for each one of them. Keywords: programming languages, programming paradigms, language features, language design and implementation 1 Introduction Choosing the best language that would satisfy all requirements for the given problem domain can be a difficult task. Some languages are better suited for specific applications than others. In order to select the proper one for the specific problem domain, one has to know what features it provides to support the requirements. Different languages support different paradigms, provide different abstractions, and have different levels of expressive power. Some are better suited to express algorithms and others are targeting the non-technical users. The question is then what is the best tool for a particular problem.
    [Show full text]