Programming Languages The Beginning. In the beginning... Computers were very expensive; programmers were cheap Programming was by plugboards or binary.

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

Programming Languages and Paradigms
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Names and Bindings.
CS 415: Programming Languages Algol Aaron Bloomfield Fall 2005.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
PZ09B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09B - Parameter transmission Programming Language Design.
Lecture 16 Subroutine Calls and Parameter Passing Semantics Dragon: Sec. 7.5 Fischer: Sec Procedure declaration procedure p( a, b : integer, f :
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Gary MarsdenSlide 1University of Cape Town Statements & Expressions Gary Marsden Semester 2 – 2000.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
MacLennan Chapter 1 The Beginning: Pseudo-code Interpreters.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
High-Level Programming Languages
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
ISBN Chapter 9 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Introduction Two fundamental abstraction facilities.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Introduction and Syntax. Course objectives Discuss features of programming languages. Discuss how the features are implemented in a simple computer architecture.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
Adapted from Dr. Craig Chase, The University of Texas at Austin.
1 Programming Languages Examples: C, Java, HTML, Haskell, Prolog, SAS Also known as formal languages Completely described and rigidly governed by formal.
© 2003 G. Drew Kessler and William M. Pottenger1 Subroutines (Part 1) CSE 262, Spring 2003.
Programming Languages
Names Variables Type Checking Strong Typing Type Compatibility 1.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
CS 2104 Prog. Lang. Concepts Subprograms
Chapter 1 - Introduction
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
CPS120: Introduction to Computer Science Decision Making in Programs.
Subprograms subroutines, procedures, functions, methods.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
Programming Languages and Paradigms Imperative Programming.
I Power Higher Computing Software Development High Level Language Constructs.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
CPS120: Introduction to Computer Science Variables and Constants.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages Dr. Carter Tiernan.
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
1 jcmt Summer 2003Programming Languages CSE3302 Programming Languages Summer 2003 Dr. Carter Tiernan.
Syntax Analysis Or Parsing. A.K.A. Syntax Analysis –Recognize sentences in a language. –Discover the structure of a document/program. –Construct (implicitly.
Expressions and Assignment Statements
CSE3302 Programming Languages (notes continued)
Expressions and Assignment Statements
Programming what is C++
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
CS 326 Programming Languages, Concepts and Implementation
Expressions and Assignment Statements
Algol 60 John Cowan N Languages in N Months Meetup June 7, 2016
Lecture 3 of Computer Science II
Expressions and Assignment Statements
CSCI 3370: Principles of Programming Languages Chapter 9 Subprograms
CSE 3302 Programming Languages
Expressions and Assignment Statements
Object-Oriented Programming Using C++ Second Edition
Names and Binding In Text: Chapter 5.
Chapter 7 Expressions and Assignment Statements.
Language Translation Issues
The C Language: Intro.
Language Translation Issues
Presentation transcript:

Programming Languages The Beginning

In the beginning... Computers were very expensive; programmers were cheap Programming was by plugboards or binary numbers (on-off switches) Memories were maybe 4K and up Cycle times were in milliseconds No compromises for programmer's ease

Early compromises Assembly language –reduced human error –programs were just as efficient FORTRAN –the compiler generated very efficient code –easier to read, understand, debug –need to compile was still extra overhead –the idea was: compile once, run many times

Automation Mechanical, tedious, or error-prone activities should be automated –Higher-level languages are an example –Assembly language automates writing binary code –FORTRAN automates writing assembly language or binary code

FORTRAN Efficiency was everything Card oriented, with information in fixed columns First language to catch on in a big way Because it was first, FORTRAN has many, many "mistakes" Algol 60 was a great leap forward

Expressions In FORTRAN, an expression... –In a WRITE statement, could be c (constant), v (variable), or v+c, or v-c –As a parameter, could be c or v –As an array subscript, could be c, v, c*v, v+c, v-c, c*v+c, or c*v-c –On the RHS of an assignment, could be anything In Algol 60, an expression is an expression is an expression!

Regularity Regular rules, without exceptions, are easier to learn, use, describe, and implement. –Arithmetic expressions in FORTRAN vs. Algol are an example –BNF is a great aid to imposing regularity

Lexical Conventions Reserved words, used in most modern languages (C, Pascal, Java) –Easier for experts, somewhat harder for novices Keywords, unambiguously marked –Hard to type and often hard to read Keywords in context (FORTRAN, PL/1) –If it makes sense as a keyword, it's a keyword, otherwise it's something else

The Reserved Word Controversy FORTRAN had no reserved words IF (I) = 1 was an array assignment Advantages of reserved words –Easier for the compiler writer –Helps avoid ambiguities in the language Disadvantages of reserved words –Programmer has to know them all –Few reserved words imply less language power?

Other FORTRAN "Mistakes" The FORTRAN compiler ignored blanks –DO 50 I=1,10 became DO50I=1,10 Did not require variable declarations –Misspellings were automatically new variables Earliest versions did not have subprograms –But they did have callable library routines DO, IF, and GO TO were the only control structures

The Impossible Error Principle Making errors impossible to commit is preferable to detecting them after their commission. –In FORTRAN, variables were declared simply by appearing in a program –DO 50 I = is an assignment to DO50I –In general, the earlier an error can be detected, the better

Algol 60 Introduced the idea of a virtual machine Used BNF to define syntax formally Introduced nested scopes Introduced free-format programs Introduced recursion Required declarations of all variables Introduced if-then-else and flexible loops

BNF BNF is a simple notation used to describe syntax precisely Example: ::= | ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Algol 60 was three+ languages The language definition was given in the reference language Algorithms were published using the publication language, in which keywords were boldface Programs were in a hardware representation –Often looked like: 'IF' X < Y 'THEN' X := X + 1 –Difficult to type, difficult to read

Algol 60 Shortcomings Algol 60 had no input/output! –I/O was considered to be too hardware-specific –Most implementations “borrowed” FORTRAN's I/O Used “call by name” semantics –powerful, but hard to implement –sometimes hard to understand Few but very flexible control structures were considered to be “baroque”

Functions and Procedures In mathematics, a function: –returns a value –has no side effects (except maybe I/O) –does not alter its parameters A procedure (a.k.a. subroutine): –does not return a value –is called precisely for its side effects –may (probably does) alter its parameters

C Has No Procedures Functions may return void (no value) Functions really can’t alter their parameters This is inadequate for real programs There are workarounds, such as passing pointers to values Hence, “functions” in C are seriously distorted

Predicates A predicate is a binary (two-valued) function In some languages, a predicate returns “true” or “false” In other languages (Snobol IV, Prolog, Icon), a predicate “succeeds” or “fails”

Methods A procedure or function is called directly In an O-O language, an object has methods A message is sent to an object The object decides what to do about the message Typically, the object chooses a method to execute

Scope Rules The scope of a variable is the part of a program in which it is defined and accessible FORTRAN: scope is the enclosing subprogram Prolog: scope is the (one) enclosing clause Java: scope is from point of definition to } Algol, Pascal: scopes are nested

Nested Scopes begin int x, y; --int x and int y are defined here begin float x, z; -- int y, float x, float z are defined here -- this is a “hole” in the scope of int x end -- int x, int y are defined here end

Actual and Formal Parameters Parameters are passed to subprograms in a variety of ways Actual parameters are the values used in a call to the subprogram Formal parameters are the names used for those values in the subprogram

Parameter Transmission Call by reference (FORTRAN, Pascal, Java) Call by value (C, Pascal, Java) Call by name (Algol 60) Call by value-result (Ada) Call by unification (Prolog)

Call by Reference Every value (data item) is stored at some particular machine address The subprogram is given that address The subprogram directly manipulates the original data item This is the most efficient way to pass parameters In FORTRAN, could alter “constants” this way

Example of Call by Reference procedure A int X X = 5 call B (X) end call B (X) end procedure B (Y) Y = Y + 1 end X is stored in only one place (that place is in A), and B is made to refer to that place.

Call by Value Subprograms are given a copy of the formal parameter Subprograms are free to change their copy The changed value is not copied back Safe, but not efficient or flexible C uses call-by-value exclusively –workaround: pass a pointer to the data item

Example of Call by Value procedure A int X X = 5 call B (X) end call B (X) end procedure B (Y) Y = Y + 1 end Value is copied down when B is called, and never copied back up

Call by Name Used in Algol 60, hardly anywhere else Uses the copy rule: the subprogram acts as if it had a textual copy of the formal parameter Mathematically, this is very neat Doesn’t play well with scope rules Violates information hiding (names matter) Difficult to implement and usually inefficient

Example of Call by Name int a, r; function fiddle (int x) { int a = 3, b = 5; return a * x + b; // means a * (a+1) + b } a = 9; r = fiddle (a+1); // should return 17 print (r);

Algol Supported Recursion Example: integer function factorial (n) begin if (n = 0) then return 1 else return n * factorial (n - 1) end

The End