Section 5: Pascal. Evolution of Software Languages

Similar documents
Section 4: ALGOL. Evolution of Software Languages

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Block-structured procedural languages Algol and Pascal. References:

CS 345. Functions. Vitaly Shmatikov. slide 1

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Section 13: CSP to OCCAM. Evolution of Software Languages

Section 3: Fortran. Evolution of Software Languages

Imperative Programming Languages (IPL)

Special Topics: Programming Languages

CA341 - Comparative Programming Languages

520 Principles of Programming Languages. Arithmetic. Variable Declarations. 19: Pascal

Chapter 5 Names, Binding, Type Checking and Scopes

LECTURE 18. Control Flow

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

procedure definition (or declaration - some make a distinction, we generally won t), e.g., void foo(int x) {... }

NOTE: Answer ANY FOUR of the following 6 sections:

Continuations provide a novel way to suspend and reexecute

CS558 Programming Languages

G Programming Languages - Fall 2012

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

Chapter 5 Names, Bindings, Type Checking, and Scopes

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

The ACK Modula-2 Compiler

COS 140: Foundations of Computer Science

Good Ideas - Revisited

CSE 307: Principles of Programming Languages

Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

CSC 533: Organization of Programming Languages. Spring 2005

CS558 Programming Languages

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

Programmiersprachen (Programming Languages)

Compiler Construction

Safe and Secure Software. Ada An Invitation to. Conclusion. Courtesy of. John Barnes. The GNAT Pro Company

Types. What is a type?

FORTRAN. FORTRAN Concepts/Contributions

CSc 520. The Oberon Programming Language Report. Manish Swaminathan, Bharathwaj 05/14/2008

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

Types. Chapter Six Modern Programming Languages, 2nd ed. 1

Draw a diagram of an empty circular queue and describe it to the reader.

Introduction. A. Bellaachia Page: 1

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no

COS 140: Foundations of Computer Science

Programming Languages, Summary CSC419; Odelia Schwartz

G Programming Languages - Fall 2012

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

Organization of Programming Languages CS 3200/5200N. Lecture 09

Compiler Construction

Compiler Construction

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

9. Subprograms. 9.2 Fundamentals of Subprograms

Data Types In Text: Ch C apter 6 1

Compiler Construction

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

22c:111 Programming Language Concepts. Fall Types I

Structure of Abstract Syntax trees for Colored Nets in PNML

CSCI312 Principles of Programming Languages!

Special Topics: Programming Languages

CSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixed-points. Typed Lambda Calculi. Least Fixed Point

UNIT V Sub u P b ro r g o r g a r m a s

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

--(1977b), 'Finite State Machine Theory and Program Design: A Survey', Computer Studies Quarterly, 1, to be published.

Names, Scopes, and Bindings II. Hwansoo Han

CSc 520. Principles of Programming Languages 25: Types Introduction

Compiler Construction

CS558 Programming Languages

Chapter 8. Fundamental Characteristics of Subprograms. 1. A subprogram has a single entry point

1 A question of semantics

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Compiler Construction

Pascal: operations on basic data structures (selection) (I) 2.3 Accessing and manipulating data

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Object-oriented Paradigm as Evolution of Structured approach in Programming

Chapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

Informatica 3 Syntax and Semantics

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Functional Languages. Hwansoo Han

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

The Pascal Programming Language. Bob Fraley HP Labs. January 15, 1980

CS 314 Principles of Programming Languages

Haskell 98 in short! CPSC 449 Principles of Programming Languages

CSE 3302 Programming Languages Lecture 5: Control

Review of the C Programming Language

Chapter 2. 5 * B => A V 6 7 (subscripts) S 1.n 1.n (data types)

Chapter 7 Expressions and Assignment statements

CMSC 330: Organization of Programming Languages

Chapter 5. Names, Bindings, and Scopes

Structure of Programming Languages Lecture 10

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Transcription:

Section 5: Pascal Evolution of Software Languages Theo D'Hondt Bachelor of Computer Science Faculty of Sciences and Bio-Engineering Sciences Vrije Universiteit Brussel Academic Year 2015-2016 Evolution of Software Languages 1 5: PASCAL

A return to simplicity One direction was: universal languages : ALGOL 68 was proposed by the academic community as the universal programming language IBM had proposed PL/I as FORTRAN VI COBOL had the quasi-monopoly in the commercial world These languages are big and unmanageable; PL/I is considered as an example of the Swiss Army knife approach Evolution of Software Languages 2 5: PASCAL

Extensible languages1 An other approach are extensible languages : a kernel and constructors There was a need for a simple kernel (e.g. ALGOL 60-subset) There were several mechanisms for language extension constructors Evolution of Software Languages 3 5: PASCAL

Extensible languages2 Definition of additional operators via function definitions : operator "#"(x, y); value x,y; integer x,y; return abs(x-y) end Evolution of Software Languages 4

Evolution of Software Languages 5 5: PASCAL Extensible languages3 Using syntax macro's real syntax sum from i = lb to ub of elem; value lb,ub; integer i, lb, ub; real elem; real s; s := 0; for i := lb step 1 until ub do s := s + elem return s end... Total := sum from k=1 to 10 of x[k]

Extensible languages4 Drawback: extensible languages are inefficient: a variable syntax makes code-optimisation impossible it is nearly impossible to link syntax errors in an extensible languages program to the original program text are used with extensible datatypes (and possibly macros) Evolution of Software Languages 6

Evolution of Software Languages 7 5: PASCAL Design1 Pascal was designed as: successor to ALGOL 60 alternative to ALGOL 68 extremely simple language a viable alternative to FORTRAN: powerful and still efficient general purpose with symbolic data structures

Evolution of Software Languages 8 5: PASCAL Design2 A.P.I.C. Studies in Data Processing No. 8 STRUCTURED PROGRAMMING Lecture Notes in Computer Science O.-J. DAHL Universitet i Oslo, Matematisk Institut, Blindern, Oslo, Norway Edited by G. Goos and J. Hartmanis E. W. DIJKSTRA Department of Mathematics, Technological University, Eindhoven, The Netherlands C. A. R. HOARE Department of Computer Science, The Queen's University of Belfast, Belfast, Northern Ireland 18 Kathleen Jensen Niklaus Wirth 1972 ACADEMIC PRESS LONDON AND NEW YORK PASCAL User Manual and Report http://dl.acm.org/citation.cfm?id=1243380&cfid=588262404&cftoken=69334518 http://93.174.95.27/get/05703fb4c22e127f289cbe6b543edfc3/ PASCAL%20user%20manual%20and%20report.pdf

Design3 Pascal was both a language and a system: short report (as in ALGOL 60) capable of supporting itself the first Pascal-system ===> compiler if ±6000 lines Pascal (on a CDC), public domain later the p-system, also public domain, was the basis for most µcomputer versions Evolution of Software Languages 9 5: PASCAL

Innovations in data types1 Enumeration: CHAR became a first-class type Enumerated types implement the security principle the ordering relation is generalised to symbolic data: = <> < > <= >= PRED SUCC ORD Enumerated types introduce the first real abstract data types Enumerated types are efficient with respect to both time and space: colour = (red,orange,green,blue,indigo,violet) only 3 bits/value! Evolution of Software Languages 10 5: PASCAL

Innovations in data types2 Subranges: subrange types are a further implementation of the security principle subrange types ensure space optimisation small = 0..15 only four bits/value subranges also implement the abstraction principle Evolution of Software Languages 11 5: PASCAL

Innovations in data types3 Sets: almost perfect example of a data structure high level very compact: 1 bit per element very efficient VAR s1, s2, s3: SET OF 'A'..'Z';... s1 := s2 + s3......c IN s1... SA1 s2 SA2 s3 BX6 X1+X2 SA6 s4 SA1 c SA2 s1 SB7 X1-'A' LX2 X2,B7 Evolution of Software Languages 12 5: PASCAL

Evolution of Software Languages 13 5: PASCAL Innovations in data types4 Arrays: more consistent than ALGOL 60 a = array [ index ] of component enormously safer than in FORTRAN

Innovations in data types5 Design criteria for arrays : all types are fully determined at compile-time both index and component are types, hence arrays are static an array is a type parameter binding is strong, hence formal array types do not allow parametrised index types the original Pascal is therefore in practice difficult to use; reason: conflict between design criteria that seem very reasonable taken separately Evolution of Software Languages 14 5: PASCAL

Innovations in data types6 Records: inspired by COBOL arrays are dynamically indexed and have uniformly typed components; records are statically indexed but can have variously typed components record-qualification can be analysed by the compiler, hence efficient the with-command opens up an environment and is the precursor of e.g. the modula2 import statement Evolution of Software Languages 15 5: PASCAL

Innovations in data types7 Records with variants are an important abstraction of the COBOL redefines but are not 100% safe, even with an explicit tag field type Complex = record case kind: (cartesian, polar); cartesian:(r, I: real); polar:(a, R: real) var end horrible = record case boolean of true:(p: ^char); false:(seg,off:integer) end Evolution of Software Languages 16 5: PASCAL

Innovations in data types8 Pointers and files: Inspired by pointers in PL/I, C,... Combined with strong typing => typed pointers File-buffers are inspired by file description and data records in COBOL, but adapted to the notion of (explicit) strong typing Evolution of Software Languages 17 5: PASCAL

Name binding1 labels, constants (explicitly and enumerated), types, variables, functions en procedures constants are a (poor) compile-time substitute for dynamic arrays in ALGOL 60 the record allows the binding of a name to a composition of data; the procedure allows the binding of a name to a composition of commands procedures can be nested and lexical scope applies Evolution of Software Languages 18 5: PASCAL

Name binding2 records and procedures introduce visibility rules declarations apply downstream within surrounding block formal parameters are visible in own body homonyms are allowed between separate levels Pascal was designed for a single-pass compiler, hence only downstream visibility with procedures and forward pointer declarations Evolution of Software Languages 19 5: PASCAL

Innovations in control1 disappearance of the ALGOL block no solution for the missing end simplification of the for: allowing an abstract for-index eliminating side effects generating efficient code explicit while and repeat structured switch becomes case much more consistent no loss of efficiency contribution to abstraction Evolution of Software Languages 20 5: PASCAL

Evolution of Software Languages 21 5: PASCAL Innovations in procedures1 no call-by-name but call-by-reference call-by-name via functional parameters call-by-value as in ALGOL 60 call-by-constant would have been more efficient, but... program Sick; var z:integer; procedure ZeroEqualsOne(x: integer); writeln(x); z := 0; writeln(x) end; x := 1; ZeroEqualsOne(x) end.

Innovations in procedures2 procedural parameters are second class objects return-value in a function: same problems as in ALGOL 60 function Absurd: integer; var x, Absurd: real; x := Absurd; {recursion doesn t work} Absurd := x {return doesn t work either} end; Evolution of Software Languages 22 5: PASCAL

Conclusion Pascal is also a milestone Pascal satisfies the original design objectives (simple, consistent, efficient didactical language) Pascal is the basis for many subsequent languages (e.g. ADA) Pascal was extended with essentially production-oriented elements (e.g. UCSD pascal) Almost all criticism of Pascal is caused by an improper use of Pascal; it is remarkable that Pascal has been successfully used for a number of tasks that it was never designed for Evolution of Software Languages 23 5: PASCAL

Assignment 1. Investigate functional/ procedural parameters in Pascal 2. Evaluate the Pascal program on the next pages Evolution of Software Languages 24 5: PASCAL

Evolution of Software Languages 25 5: PASCAL Example1 program DSW; const LowAddress = -32767; HighAddress = -32737; Null = 0; type Address = LowAddress..HighAddress; ConsCell = record Left: integer; Right: integer end; var M: array[address] of ConsCell; Root: integer; freelist: integer; procedure collectgarbage; var flag: array[address] of (tryleft, tryright, backleft, backright); procedure markallfree; var adr: Address; for adr := LowAddress to HighAddress do flag[adr] := tryleft end; {markallfree} procedure sweepfromroot (adr: integer); var this, previous: integer; continue: boolean;

Evolution of Software Languages 26 5: PASCAL Example2 procedure rotate (var A, B, C: integer); var X: integer; X := A; A := B; B := C; C := X end;{rotate} if adr < 0 then this := adr; previous := Null; continue := true; while continue do case flag[this] of tryleft: if M[this].Left < 0 then flag[this] := backleft; rotate(previous, this, M[this].Left) end else flag[this] := tryright; tryright: flag[this] := backright; if M[this].Right < 0 then rotate(previous, this, M[this].Right) end;

Evolution of Software Languages 27 5: PASCAL Example3 backleft, backright: continue := (previous = Null); if continue then case flag[previous] of backleft: rotate(m[previous].left, this, previous); flag[this] := tryright end; backright: rotate(m[previous].right, this, previous) end end end end end; {sweepfromroot} procedure releaseremainingfree; var adr: Address; for adr := LowAddress to HighAddress do if flag[adr] = tryleft then M[adr].Left := freelist; freelist := adr end end; {releaseremainingfree}

Example4 markallfree; sweepfromroot(root); releaseremainingfree; end; {collectgarbagenr} function NewCell: integer; var oldfreelist: Address; if freelist = Null then collectgarbage; if freelist = Null then Writeln('Memory overflow'); NewCell := freelist; oldfreelist := freelist; freelist := M[oldFreeList].Left; M[oldFreeList].Left := Null; M[oldFreeList].Right := Null end; {NewCell} procedure Initialize; var adr: Address; for adr := LowAddress to pred(highaddress) do M[adr].Left := succ(adr); M[HighAddress].Left := Null; freelist := LowAddress; Root := Null end; {Initialize} {test code here} end. Evolution of Software Languages 28 5: PASCAL