Understanding Programming Languages

Total Page:16

File Type:pdf, Size:1020Kb

Understanding Programming Languages Understanding Programming Languages M. Ben-Ari Weizmann Institute of Science Originally published by John Wiley & Sons, Chichester, 1996. Copyright °c 2006 by M. Ben-Ari. You may download, display and print one copy for your personal use in non-commercial academic research and teaching. Instructors in non-commerical academic institutions may make one copy for each student in his/her class. All other rights reserved. In particular, posting this document on web sites is prohibited without the express permission of the author. Contents Preface xi I Introduction to Programming Languages 1 1 What Are Programming Languages? 2 1.1 The wrong question . 2 1.2 Imperative languages . 4 1.3 Data-oriented languages . 7 1.4 Object-oriented languages . 11 1.5 Non-imperative languages . 12 1.6 Standardization . 13 1.7 Computer architecture . 13 1.8 * Computability . 16 1.9 Exercises . 17 2 Elements of Programming Languages 18 2.1 Syntax . 18 2.2 * Semantics . 20 2.3 Data . 21 2.4 The assignment statement . 22 2.5 Type checking . 23 2.6 Control statements . 24 2.7 Subprograms . 24 2.8 Modules . 25 2.9 Exercises . 26 v Contents vi 3 Programming Environments 27 3.1 Editor . 28 3.2 Compiler . 28 3.3 Librarian . 30 3.4 Linker . 31 3.5 Loader . 32 3.6 Debugger . 32 3.7 Profiler . 33 3.8 Testing tools . 33 3.9 Configuration tools . 34 3.10 Interpreters . 34 3.11 The Java model . 35 3.12 Exercises . 37 II Essential Concepts 38 4 Elementary Data Types 39 4.1 Integer types . 39 4.2 Enumeration types . 43 4.3 Character type . 46 4.4 Boolean type . 47 4.5 * Subtypes . 48 4.6 * Derived types . 50 4.7 Expressions . 52 4.8 Assignment statements . 55 4.9 Exercises . 57 5 Composite Data Types 59 5.1 Records . 59 5.2 Arrays . 62 5.3 Reference semantics in Java . 64 5.4 Arrays and type checking . 66 5.5 * Array subtypes in Ada . 69 5.6 String type . 70 5.7 Multi-dimensional arrays . 72 Contents vii 5.8 Array implementation . 73 5.9 * Representation specification . 76 5.10 Exercises . 80 6 Control Structures 82 6.1 switch-/case-statements . 82 6.2 if-statements . 86 6.3 Loop statements . 91 6.4 for-statements . 94 6.5 Sentinels . 99 6.6 * Invariants . 100 6.7 goto-statements . 102 6.8 Exercises . 103 7 Subprograms 105 7.1 Subprograms: procedures and functions . 105 7.2 Parameters . 107 7.3 Passing parameters to a subprogram . 109 7.4 Block structure . 117 7.5 Recursion . 122 7.6 Stack architecture . 124 7.7 More on stack architecture . 130 7.8 * Implementation on the 8086 . 132 7.9 Exercises . 134 III Advanced Concepts 136 8 Pointers 137 8.1 Pointer types . 137 8.2 Data structures . 143 8.3 Dynamic data structures in Java . 149 8.4 Equality and assignment in Java . 149 8.5 Memory allocation . 151 8.6 Algorithms for heap allocation . 153 8.7 Exercises . 156 Contents viii 9 Real Numbers 157 9.1 Representations of real numbers . 157 9.2 Language support for real numbers . 160 9.3 The three deadly sins . 163 9.4 * Real types in Ada . 165 9.5 Exercises . 166 10 Polymorphism 168 10.1 Type conversion . 168 10.2 Overloading . 169 10.3 Generics . 171 10.4 Polymorphic data structures in Java . 174 10.5 Variant records . 175 10.6 Dynamic dispatching . 178 10.7 Exercises . 179 11 Exceptions 180 11.1 Exception handling requirements . 180 11.2 Exceptions in PL/I . 181 11.3 Exceptions in Ada . 182 11.4 Exceptions in C++ . 184 11.5 Error handling in Eiffel . 186 11.6 Exercises . ..
Recommended publications
  • Working with System Frameworks in Python and Objective-C
    Working with System Frameworks in Python and Objective-C by James Barclay Feedback :) j.mp/psumac2015-62 2 Dude, Where’s My Source Code? CODE https://github.com/futureimperfect/psu-pyobjc-demo https://github.com/futureimperfect/PSUDemo SLIDES https://github.com/futureimperfect/slides 3 Dude, Where’s My Source Code? CODE https://github.com/futureimperfect/psu-pyobjc-demo https://github.com/futureimperfect/PSUDemo SLIDES https://github.com/futureimperfect/slides 3 Dude, Where’s My Source Code? CODE https://github.com/futureimperfect/psu-pyobjc-demo https://github.com/futureimperfect/PSUDemo SLIDES https://github.com/futureimperfect/slides 3 Agenda 1. What are system frameworks, and why should you care? 2. Brief overview of the frameworks, classes, and APIs that will be demonstrated. 3. Demo 1: PyObjC 4. Demo 2: Objective-C 5. Wrap up and questions. 4 What’s a System Framework? …and why should you care? (OS X) system frameworks provide interfaces you need to write software for the Mac. Many of these are useful for Mac admins creating: • scripts • GUI applications • command-line tools Learning about system frameworks will teach you more about OS X, which will probably make you a better admin. 5 Frameworks, Classes, and APIs oh my! Cocoa CoreFoundation • Foundation • CFPreferences - NSFileManager CoreGraphics - NSTask • Quartz - NSURLSession - NSUserDefaults • AppKit - NSApplication 6 CoreFoundation CoreFoundation is a C framework that knows about Objective-C objects. Some parts of CoreFoundation are written in Objective-C. • Other parts are written in C. CoreFoundation uses the CF class prefix, and it provides CFString, CFDictionary, CFPreferences, and the like. Some Objective-C objects are really CF types behind the scenes.
    [Show full text]
  • Review Thanks!
    CS 242 Thanks! Review Teaching Assistants • Mike Cammarano • TJ Giuli • Hendra Tjahayadi John Mitchell Graders • Andrew Adams Tait Larson Final Exam • Kenny Lau Aman Naimat • Vishal Patel Justin Pettit Wednesday Dec 8 8:30 – 11:30 AM • and more … Gates B01, B03 Course Goals There are many programming languages Understand how programming languages work Early languages Appreciate trade-offs in language design • Fortran, Cobol, APL, ... Be familiar with basic concepts so you can Algol family understand discussions about • Algol 60, Algol 68, Pascal, …, PL/1, … Clu, Ada, Modula, • Language features you haven’t used Cedar/Mesa, ... • Analysis and environment tools Functional languages • Implementation costs and program efficiency • Lisp, FP, SASL, ML, Miranda, Haskell, Scheme, Setl, ... • Language support for program development Object-oriented languages • Smalltalk, Self, Cecil, … • Modula-3, Eiffel, Sather, … • C++, Objective C, …. Java General Themes in this Course Concurrent languages Language provides an abstract view of machine • Actors, Occam, ... • We don’t see registers, length of instruction, etc. • Pai-Lisp, … The right language can make a problem easy; Proprietary and special purpose languages wrong language can make a problem hard • Could have said a lot more about this • TCL, Applescript, Telescript, ... Language design is full of difficult trade-offs • Postscript, Latex, RTF, … • Expressiveness vs efficiency, ... • Domain-specific language • Important to decide what the language is for Specification languages • Every feature
    [Show full text]
  • SETL for Internet Data Processing
    SETL for Internet Data Processing by David Bacon A dissertation submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy Computer Science New York University January, 2000 Jacob T. Schwartz (Dissertation Advisor) c David Bacon, 1999 Permission to reproduce this work in whole or in part for non-commercial purposes is hereby granted, provided that this notice and the reference http://www.cs.nyu.edu/bacon/phd-thesis/ remain prominently attached to the copied text. Excerpts less than one PostScript page long may be quoted without the requirement to include this notice, but must attach a bibliographic citation that mentions the author’s name, the title and year of this disser- tation, and New York University. For my children ii Acknowledgments First of all, I would like to thank my advisor, Jack Schwartz, for his support and encour- agement. I am also grateful to Ed Schonberg and Robert Dewar for many interesting and helpful discussions, particularly during my early days at NYU. Terry Boult (of Lehigh University) and Richard Wallace have contributed materially to my later work on SETL through grants from the NSF and from ARPA. Finally, I am indebted to my parents, who gave me the strength and will to bring this labor of love to what I hope will be a propitious beginning. iii Preface Colin Broughton, a colleague in Edmonton, Canada, first made me aware of SETL in 1980, when he saw the heavy use I was making of associative tables in SPITBOL for data processing in a protein X-ray crystallography laboratory.
    [Show full text]
  • Modern Programming Languages CS508 Virtual University of Pakistan
    Modern Programming Languages (CS508) VU Modern Programming Languages CS508 Virtual University of Pakistan Leaders in Education Technology 1 © Copyright Virtual University of Pakistan Modern Programming Languages (CS508) VU TABLE of CONTENTS Course Objectives...........................................................................................................................4 Introduction and Historical Background (Lecture 1-8)..............................................................5 Language Evaluation Criterion.....................................................................................................6 Language Evaluation Criterion...................................................................................................15 An Introduction to SNOBOL (Lecture 9-12).............................................................................32 Ada Programming Language: An Introduction (Lecture 13-17).............................................45 LISP Programming Language: An Introduction (Lecture 18-21)...........................................63 PROLOG - Programming in Logic (Lecture 22-26) .................................................................77 Java Programming Language (Lecture 27-30)..........................................................................92 C# Programming Language (Lecture 31-34) ...........................................................................111 PHP – Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)........................129 Modern Programming Languages-JavaScript
    [Show full text]
  • CRN What It Was Doing and Why It Was Cognitive Systems Vision Doing It, and to Recover from Mental Continued on Page 8 Expanding the Pipeline
    COMPUTING RESEARCH NEWS Computing Research Association, Celebrating 30 Years of Service to the Computing Research Community November 2002 Vol. 14/No. 5 DARPA’s New Cognitive Systems Vision By Ron Brachman and IPTO’s goal is to create a new to cope with systems both keep Zachary Lemnios generation of cognitive systems. growing. In order to make our systems more reliable, more secure, The impact of the Defense Mired in Moore’s Law? and more understandable, and to Advanced Research Projects Agency One benefit of such cognitive continue making substantial contri- (DARPA) on computing over the systems would be their help in butions to society, we need to do past 40 years has been profound. Led extracting us from a corner into something dramatically different. by the visionary J.C.R. Licklider and which our success seems to have his innovative successors in the painted us. The research that has The Promise of Cognitive Information Processing Techniques helped the industry follow Moore’s Systems Office (IPTO), DARPA initiated “Law” has created processors that are IPTO is attacking this problem by work that ultimately put personal remarkably fast and small, and data driving a fundamental change in computers on millions of desktops storage capabilities that are vast and computing systems. By giving systems Ron Brachman and made the global Internet a cheap. Unfortunately, these incred- more cognitive capabilities, we reality. In fact, the original IPTO, ible developments have cut two ways. believe we can make them more which lasted from 1962 to 1985, was While today’s computers are more responsible for their own behavior in large part responsible for estab- powerful than ever, we have been and maintenance.
    [Show full text]
  • Unix/Linux Command Reference
    Unix/Linux Command Reference .com File Commands System Info ls – directory listing date – show the current date and time ls -al – formatted listing with hidden files cal – show this month's calendar cd dir - change directory to dir uptime – show current uptime cd – change to home w – display who is online pwd – show current directory whoami – who you are logged in as mkdir dir – create a directory dir finger user – display information about user rm file – delete file uname -a – show kernel information rm -r dir – delete directory dir cat /proc/cpuinfo – cpu information rm -f file – force remove file cat /proc/meminfo – memory information rm -rf dir – force remove directory dir * man command – show the manual for command cp file1 file2 – copy file1 to file2 df – show disk usage cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if it du – show directory space usage doesn't exist free – show memory and swap usage mv file1 file2 – rename or move file1 to file2 whereis app – show possible locations of app if file2 is an existing directory, moves file1 into which app – show which app will be run by default directory file2 ln -s file link – create symbolic link link to file Compression touch file – create or update file tar cf file.tar files – create a tar named cat > file – places standard input into file file.tar containing files more file – output the contents of file tar xf file.tar – extract the files from file.tar head file – output the first 10 lines of file tar czf file.tar.gz files – create a tar with tail file – output the last 10 lines
    [Show full text]
  • Vmware Fusion 12 Vmware Fusion Pro 12 Using Vmware Fusion
    Using VMware Fusion 8 SEP 2020 VMware Fusion 12 VMware Fusion Pro 12 Using VMware Fusion You can find the most up-to-date technical documentation on the VMware website at: https://docs.vmware.com/ VMware, Inc. 3401 Hillview Ave. Palo Alto, CA 94304 www.vmware.com © Copyright 2020 VMware, Inc. All rights reserved. Copyright and trademark information. VMware, Inc. 2 Contents Using VMware Fusion 9 1 Getting Started with Fusion 10 About VMware Fusion 10 About VMware Fusion Pro 11 System Requirements for Fusion 11 Install Fusion 12 Start Fusion 13 How-To Videos 13 Take Advantage of Fusion Online Resources 13 2 Understanding Fusion 15 Virtual Machines and What Fusion Can Do 15 What Is a Virtual Machine? 15 Fusion Capabilities 16 Supported Guest Operating Systems 16 Virtual Hardware Specifications 16 Navigating and Taking Action by Using the Fusion Interface 21 VMware Fusion Toolbar 21 Use the Fusion Toolbar to Access the Virtual-Machine Path 21 Default File Location of a Virtual Machine 22 Change the File Location of a Virtual Machine 22 Perform Actions on Your Virtual Machines from the Virtual Machine Library Window 23 Using the Home Pane to Create a Virtual Machine or Obtain One from Another Source 24 Using the Fusion Applications Menus 25 Using Different Views in the Fusion Interface 29 Resize the Virtual Machine Display to Fit 35 Using Multiple Displays 35 3 Configuring Fusion 37 Setting Fusion Preferences 37 Set General Preferences 37 Select a Keyboard and Mouse Profile 38 Set Key Mappings on the Keyboard and Mouse Preferences Pane 39 Set Mouse Shortcuts on the Keyboard and Mouse Preference Pane 40 Enable or Disable Mac Host Shortcuts on the Keyboard and Mouse Preference Pane 40 Enable Fusion Shortcuts on the Keyboard and Mouse Preference Pane 41 Set Fusion Display Resolution Preferences 41 VMware, Inc.
    [Show full text]
  • 101 Useful Linux Commands - Haydenjames.Io
    101 Useful Linux Commands - haydenjames.io Some of these commands require elevated permissions (sudo) to run. Enjoy! 1. Execute the previous command used: !! 2. Execute a previous command starting with a specific letter. Example: !s 3. Short way to copy or backup a file before you edit it. For example, copy nginx.conf cp nginx.conf{,.bak} 4. Toggle between current directory and last directory cd - 5. Move to parent (higher level) directory. Note the space! cd .. 6. Go to home directory cd ~ 7. Go to home directory cd $HOME 8. Go to home directory (when used alone) cd 9. Set permissions to 755. Corresponds to these permissions: (-rwx-r-x-r-x), arranged in this sequence: (owner-group-other) chmod 755 <filename> 10. Add execute permission to all users. chmod a+x <filename> 11. Changes ownership of a file or directory to . chown <username> 12. Make a backup copy of a file (named file.backup) cp <file> <file>.backup 13. Copy file1, use it to create file2 cp <file1> <file2> 14. Copy directory1 and all its contents (recursively) into directory2 cp -r <directory1> <directory2>/ 15. Display date date 16. Zero the sdb drive. You may want to use GParted to format the drive afterward. You need elevated permissions to run this (sudo). dd if=/dev/zero of=/dev/sdb 17. Display disk space usage df -h 18. Take detailed messages from OS and input to text file dmesg>dmesg.txt 19. Display a LOT of system information. I usually pipe output to less. You need elevated permissions to run this (sudo).
    [Show full text]
  • Dig, a DNS Query Tool for Windows and Replacement for Nslookup 2008-04-15 15:29
    dig, a DNS query tool for Windows and replacement for nslookup 2008-04-15 15:29 Disclaimer dig (dig for Windows ) (dig is a powerful tool to investigate [digging into] the DNS system) Source of the binary is from ftp.isc.org Manual Page of dig, in the cryptic Unix style, for reference only. (1) Download: Windows 2000 or Windows XP or Windows Vista ( dig version 9.3.2) Create a folder c:\dig Download this dig-files.zip and save it to c:\dig Use winzip or equivalent to extract the files in dig-files.zip to c:\dig Note: If msvcr70.dll already exists in %systemroot%\system32\ , then you can delete c:\dig\msvcr70.dll Note: Included in dig-files.zip is a command line whois, version 4.7.11: The canonical site of the whois source code is http://ftp.debian.org/debian/pool/main/w/whois/ The whois.exe file inside dig-files.zip is compiled using cygwin c++ compiler. (2) Do a file integrity check (why ? Because some virus checkers destroy dll files) Click Start.. Run ... type CMD (a black screen pops up) cd c:\dig sha1 * You should see some SHA1 hashes (in here, SHA1 hash is used as an integrity check, similar to checksums). Compare your hashes with the following table. SHA1 v1.0 [GPLed] by Stephan T. Lavavej, http://stl.caltech.edu 6CA70A2B 11026203 EABD7D65 4ADEFE3D 6C933EDA cygwin1.dll 57487BAE AA0EB284 8557B7CA 54ED9183 EAFC73FA dig.exe 97DBD755 D67A5829 C138A470 8BE7A4F2 6ED0894C host.exe D22E4B89 56E1831F F0F9D076 20EC19BF 171F0C29 libbind9.dll 81588F0B E7D3C6B3 20EDC314 532D9F2D 0A105594 libdns.dll E0BD7187 BBC01003 ABFE7472 E64B68CD 1BDB6BAB libeay32.dll F445362E 728A9027 96EC6871 A79C6307 054974E4 libisc.dll B3255C0E 4808A703 F95C217A 91FFCD69 40E680C9 libisccfg.dll DFBDE4F9 E25FD49A 0846E97F D813D687 6DC94067 liblwres.dll 61B8F573 DB448AE6 351AE347 5C2E7C48 2D81533C msvcr70.dll BDA14B28 7987E168 F359F0C9 DD96866D 04AB189B resolv.conf 1112343A 319C3EEE E44BF261 AE196C96 289C70E2 sha1.exe 21D20035 2A5B64E2 69FEA407 4D78053F 3C7A2738 whois.exe If your hashes are the same as the above table, then your files pass the integrity check.
    [Show full text]
  • Streamlining Integrated Infrastructure Implementation “Dig Once” Strategy Development Workshop June 9, 2016
    Streamlining Integrated Infrastructure Implementation “Dig Once” Strategy Development Workshop June 9, 2016 Workshop Report February 2017 Sponsored By: Alliance for the Chesapeake Bay Local Government Advisory Committee (LGAC) Funding: National Fish & Wildlife Foundation (NFWF) Prepared By: Alliance for the Chesapeake Bay Hirschman Water & Environment, LLC 1. Workshop Overview and Focus The focus of this workshop was to explore better ways to integrate green infrastructure (GI) into other infrastructure projects, such as roads, school and park improvements, and other capital projects. The workshop was hosted by the Alliance for the Chesapeake Bay (ACB) in conjunction with the Local Government Advisory Committee to the Chesapeake Executive Council (LGAC), with funding from the National Fish & Wildlife Foundation (NFWF). Mary Gattis, Director of Local Government Programs for ACB, was the lead facilitator for the workshop. The workshop was held on June 9, 2016 at the Eisenhower Hotel in Gettysburg, Pennsylvania. The organizers targeted certain sector representatives for attendance in order to achieve the necessary cross-section of experiences and points of view. Figure 1 shows the breakdown of attendees by type of organization. A total of 58 individuals attended the 1-day workshop, 52 participants and six staff representatives. See Appendix A for a list of workshop participants. Prior to the workshop, the following problem statement and workshop goal Figure 1. Representation of 52 Workshop Attendees were sent to attendees as part of the agenda. This was done in order to maintain a clear focus for the workshop, as the topic of green infrastructure has many facets, each of which could fill the entire agenda for a one-day event.
    [Show full text]
  • “Linux at the Command Line” Don Johnson of BU IS&T  We’Ll Start with a Sign in Sheet
    “Linux at the Command Line” Don Johnson of BU IS&T We’ll start with a sign in sheet. We’ll end with a class evaluation. We’ll cover as much as we can in the time allowed; if we don’t cover everything, you’ll pick it up as you continue working with Linux. This is a hands-on, lab class; ask questions at any time. Commands for you to type are in BOLD The Most Common O/S Used By BU Researchers When Working on a Server or Computer Cluster Linux is a Unix clone begun in 1991 and written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. 64% of the world’s servers run some variant of Unix or Linux. The Android phone and the Kindle run Linux. a set of small Linux is an O/S core programs written by written by Linus Richard Stallman and Torvalds and others others. They are the AND GNU utilities. http://www.gnu.org/ Network: ssh, scp Shells: BASH, TCSH, clear, history, chsh, echo, set, setenv, xargs System Information: w, whoami, man, info, which, free, echo, date, cal, df, free Command Information: man, info Symbols: |, >, >>, <, ;, ~, ., .. Filters: grep, egrep, more, less, head, tail Hotkeys: <ctrl><c>, <ctrl><d> File System: ls, mkdir, cd, pwd, mv, touch, file, find, diff, cmp, du, chmod, find File Editors: gedit, nedit You need a “xterm” emulation – software that emulates an “X” terminal and that connects using the “SSH” Secure Shell protocol. ◦ Windows Use StarNet “X-Win32:” http://www.bu.edu/tech/support/desktop/ distribution/xwindows/xwin32/ ◦ Mac OS X “Terminal” is already installed Why? Darwin, the system on which Apple's Mac OS X is built, is a derivative of 4.4BSD-Lite2 and FreeBSD.
    [Show full text]
  • Exercise I: Basic Unix for Manipulating NGS Data
    Exercise I: Basic Unix for manipulating NGS data C. Hahn, July 2014 The purpose of this exercise is to practice manipulating NGS (Next Generation Sequencing) data using simple but incredibly powerful Unix commands. Try to solve the below tasks using your Unix skills. Do not hesitate to consult Google for help!! Hints for every task can be found on page 3 below. Possible solutions are suggested on page 4. 1. Download the testdata from https://www.dropbox.com/s/wcanmej6z03yfmt/testdata_1.tar?dl=0. Create a directory (exercise_1) in your home directory and copy the archive testdata.tar from ~/Downloads/ to this directory. 2. Decompress the archive. 3. Examine the content of the data files. For basic information on fastq format please visit: http://en.wikipedia.org/wiki/FASTQ_format. With this information try to interpret the content of your data files. Do you Know what all the lines represent? a) Which quality encoding (which offset) do these files use? b) What is the header of the third read in the file? Is this a single-end (forward) or a paired-end (reverse) read? c) What is the header of the last read in the file? Is this a forward or reverse read? 4. How many lines does the file have? 5. How many reads does the file contain? 6. How many single-end (“se” also referred to as forward reads) reads and how many paired-end (“pe” also reverse reads) reads does the file contain? 7. Extract all se/pe reads and write them to separate files testdata_1.fastq and testdata_2.fastq.
    [Show full text]