ebook img

Into the Realm of Oberon: An Introduction to Programming and the Oberon-2 Programming Language PDF

204 Pages·1997·9.573 MB·
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Into the Realm of Oberon: An Introduction to Programming and the Oberon-2 Programming Language

Into the Realm of Oberon Springer New York Berlin Heidelberg Barcelona Budapest Hong Kong London Milan Paris Santa Clara Singapore Tokyo Eric Nikitin Into the Realm of Oberon An Introduction to Programming and the Oberon-2 Programming Language Springer Eric Nikitin Bell & Howell Publication Systems Company Kinross Lakes Richfield, Ohio 44286 USA Library of Congress Cataloging-in-Publication Data Nikitin, Eric W. Into the realm of Oberon : an introduction to programming and the Oberon-2 programming language / Eric W. Nikitin. p. cm. ISBN-13: 978-1-4612-7491-9 e-ISBN-13: 978-1-4612-2300-9 001: 10.1007/978-1-4612-2300-9 1. Object-oriented programming (Computer science) 2. Operating systems (Computers) 3. Oberon. QA76.64.N55 1997 005.13'3-dc21 97-22886 Printed on acid-free paper. © 1998 Springer-Verlag New York, Inc. Softcover reprint of the hardcover 1st edition 1998 All rights reserved. This work may not be translated or copied in whole or in part without the written permission of the publisher (Springer-Verlag New York, Inc., 175 Fifth Avenue, New York, NY 10010, USA), except for brief excerpts in connection with reviews or scholarly analysis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed is forbidden. The use of general descriptive names, trade names, trademarks, etc., in this publication, even if the former are not especially identified, is not to be taken as a sign that such names, as understood by the Trade Marks and Merchan dise Marks Act, may accordingly be used freely by anyone. Production managed by Timothy Taylor; manufacturing supervised by Jacqui Ashri. Photocomposed copy prepared using the author's Microsoft Word files. 987654321 In memory of my father, Mitchell Nikitin For supplemental files relating to this book, go to the Springer New York Web site at: http://www.springer-ny.com/supplements/nikitin. Acknowledgments This book would not have been possible without my "standing on the shoulders of gi ants." I would like to thank those who provided both technical inspiration and moral support: Professor Niklaus Wirth, whose contributions to the field of computer programming are too numerous to mention, and without whom the programming language Oberon as we know it would not exist. Professor Hanspeter Mossenbock for his work on Oberon-2. All the contributors in the Oberon news group, comp.lang.oberon, for answers and clarifications I could find nowhere else. Martin Gilchrist at Springer-Verlag for seeing the value of publishing this book. Scott, Hanna, Frank, Erika, Dawnette, and Cathie for giving me confidence when I needed it most. My children, Alexander, Christopher, Katharine, and Spenser, who are my life. And special thanks to my wife, Tammy. Akron, Ohio Eric Nikitin Contents Acknowledgments ..................................................................................................... VB Introduction ............................................................................................................. . i.I Who Should Use This Book? ......................................................................... . i.2 What Is Programming? ................................................................................... 1 i.3 Why Oberon? .................................................................................................. 2 i.4 Where to Begin ............................................................................................... 3 Part I Procedures ............................................................................ 5 Chapter 1 Using Procedures..................................................................................... 7 1.1 A First Program........ .................................................... .......................... ...... ... 7 1.2 Pausing for a Moment..................................................................................... 10 1.3 Identifiers and Reserved Words ......... ........................................ ..................... 11 1.4 Comments .... ................... ........ ....................................................... ................. 12 1.5 "Bugs" ............................... ............... ........................... ...................... .............. 12 1.6 Exercises ...................... ............ ........................ ... ........... ................ ................. 13 Chapter 2 Values and Type......................................... ............................................. 15 2.1 Values............................................................................................................. 15 2.2 String and Character Values ........................................................................... 17 2.3 Hexadecimal Numbers.................................................................................... 18 2.4 Character and Integer Values as Hex Numbers .............................................. 21 2.5 Reals and Floating-point Notation .................................................................. 21 2.6 Boolean Values ..................... ............................................ ........ ........ .............. 22 2.7 Exercises ......................................................................................................... 22 Chapter 3 Writing Procedures .................................................................................. 24 3.1 Procedures with Parameters ............................................................................ 24 3.2 Parameters and the Parameter List.................................................................. 25 3.3 Basic Types ..................................................................................................... 26 3.4 Why Do We Need Types? .............................................................................. 27 3.5 MODULE Definitions..................................................................................... 27 3.6 Type Compatibility of Basic Types ................................................................ 29 3.7 Basic Arithmetic Operators............................................................................. 29 3.8 Standard Identifiers .............. ........................................................................... 31 3.9 Exercises ......................................................................................................... 32 Chapter 4 Variables and Changing Values............................................................... 34 4.1 Variables and the Assignment Operator ......................................................... 34 4.2 Variables ......................................................................................................... 36 x Contents 4.3 Assignment Statements ................................................................................... 37 4.4 String Variables and Assignments .................................................................. 38 4.5 Variables Versus Parameters........................................................................... 39 4.6 Value Parameters Versus Variable Parameters............................................... 41 4.7 Exercises ............................................................................................. ............ 44 Chapter 5 Using Modules......................................................................................... 46 In........................................................................................................ 5.1 Module 46 5.2 Modules and Program Structure ..................................................................... 48 5.3 The Import List and Qualified Identifiers ....................................................... 50 5.4 Forward Declarations...................................................................................... 51 5.5 Writing Modules ............................................................................................. 52 5.6 Exercises ......................................................................................................... 52 Chapter 6 Expressions and Function Procedures ..................................................... 54 6.1 Expressions ..................................................................................................... 54 6.2 Operators and Precedence ............................................................................... 55 6.3 Function Procedures........................................................................................ 58 6.4 Other Standard Procedures.............................................................................. 59 6.5 Constant Expressions ......................................................................... ............. 64 6.6 Scope............................................................................................................... 66 6.7 Program Planning............................................................................................ 67 6.8 Exercises ........................................................................................ ..... ............ 68 Chapter 7 The FOR Statement ................................................................................. 70 7.1 The FOR Loop.............................................. .................................................. 70 7.2 Details of the FOR Statement ......................................................................... 71 7.3 Nested FOR Loops.......................................................................................... 73 7.4 Exercises ......................................................................................................... 73 Chapter 8 The IF Statement ..................................................................................... 75 8.1 Making Decisions ........................................................................................... 75 8.2 Boolean Expressions and Relational Operators .............................................. 76 8.3 Boolean Variables and Constants.................................................................... 77 8.4 Logical Boolean Operators ............................................................................. 78 8.5 Partial Evaluation............................................................................................ 80 8.6 General Forms of the IF Statement ................................................................. 81 8.7 Error Checking................................................................................................ 82 8.8 Simplifying Boolean Expressions ................................................................... 83 8.9 Exercises ......................................................................................................... 85 Chapter 9 Other Looping Statements ....................................................................... 86 9.1 Looping Statements ........................................................................................ 86 9.2 The WHILE Loop........................................................................................... 86 9.3 The REPEAT Loop............................................. ............................................ 88 9.4 The LOOP Statement...................................................................................... 91 9.5 Looping Guidelines......................................................................................... 92 9.6 Debugging Statements .................................................................................... 93 9.7 Exercises ............................................................................................... .......... 94 Contents xi Chapter 10 The CASE Statement ........................................................................... 96 10.1 Choosing Alternatives ................................................................................. 96 10.2 The CASE Statement................................................................................... 97 10.3 Exercises ..................................................................................................... 98 Part II Types ..................................................................................... 101 Chapter 11 Working with Types............................................................................. 103 11.1 What Is a Type?.......................................................................................... 103 11.2 Defining New Types ................................................................................... 103 11.3 Type Compatibility and Named Typing...................................................... 105 11.4 Exercises ..................................................................................................... 106 Chapter 12 Array Types.......................................................................................... 107 12.1 Using Arrays ............................................................................................... 107 12.2 Why Use Arrays? ........................................................................................ 109 12.3 Details of Arrays ......................................................................................... 109 12.4 Array Assignment ....................................................................................... 111 12.5 Arrays as Parameters ................................................................................... 113 12.6 Data Abstraction.......................................................................................... 115 12.7 Exercises ..................................................................................................... 118 Chapter 13 Record Types ....................................................................................... 120 13.1 Declaring Record Types.............................................................................. 120 13.2 Details of Record Types.............................................................................. 122 13.3 Records and Arrays ..................................................................................... 124 13.4 Exporting Record Types.............................................................................. 126 13.5 Exercises ..................................................................................................... 127 Chapter 14 Extending Record Types...................................................................... 129 14.1 Type Extension of Records ......................................................................... 129 14.2 Details of Extended Record Types .............................................................. 132 14.3 Subtyping .................................................................................................... 134 14.4 Records as Parameters................................................................................. 135 14.5 Abstraction and Encapsulation.................................................................... 136 14.6 Exercises ..................................................................................................... 137 Chapter 15 Pointer Types ........... .............. .............................................................. 139 15.1 What Are Pointers? .................................................................................... 139 15.2 Details of Pointers ....................................................................................... 142 15.3 Memory Management and Pointers ............................................................ 145 15.4 Pointers and Type Extension....................................................................... 146 15.5 The wrrn Statement.................................................................................. 151 15.6 Exercises ..................................................................................................... 152 Chapter 16 Uses of Pointers............................................. ....................................... 154 16.1 Why Use Pointers? ...................................................................................... 154 16.2 Dynamic Structures and Lists...................................................................... 154 16.3 Pointers as Parameters and Return Values of Functions ............................. 158 16.4 Pointers and Open Arrays ........................................................................... 158

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.