CS320, Programming Languages - PowerPoint PPT Presentation


PPT – CS320, Programming Languages PowerPoint presentation | free to download - id: 1ef1c0-ZDc1Z


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

CS320, Programming Languages


Optimization (optional) makes program smaller, faster, or use less memory ... parent(joanne, jake) parent(vern, joanne) grandparent(x, z) := parent(x, y), parent(y, z) ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 54
Provided by: cickovt


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: CS320, Programming Languages

Language Design
  • CS320, Programming Languages

Design and Implementation
  • Language Design Influences
  • Language Design Trade-offs
  • Implementation Methods
  • Language Evolution

Computer Architecture
  • Von Neumann Architecture is the most prevalent
  • Idea Instructions and data share memory
  • CPU processes instructions from MEM, invokes ALU,
    stores results in MEM

Execution on a von Neumann Machine
  • Proceeds as follows
  • Instructions are stored sequentially in memory
  • OS transfers control to user program at beginning
  • Control goes back to OS at the end

Building a Language
  • If we base it on von Neumann, we call this an
    imperative language
  • Any language whose central feature is variables
    and the assignment of values
  • Examples Fortran, Pascal, C, C, Java
  • What do variables model?
  • What does an assignment statement model?
  • Why is sequential instruction execution fast on a
    von Neumann machine?

Food for Thought
  • There are functional languages out there without
    these features whose only construct is applying
    functions to a set of arguments. Sounds simple
  • Examples Lisp, SCHEME
  • Von Neumann architectures are the most prevalent
  • So why have functional languages not become

Programming Methodologies
Categorizing Languages
Categorizing Debates
  • What do we call scripting languages?
  • Use the same metrics
  • What about markup languages (XML, HTML)?
  • They are description languages
  • And domain-specific languages?
  • Have their own classification schemes, really
  • So well stick to general purpose, programming

Tradeoffs in Language Design
  • Hoare (1973) There are so many important, but
    conflicting criteria, that their reconciliation
    and satisfaction is a major engineering task.
  • Lets go through some of the primary tradeoffs
    that we will sometime see.

Tradeoff 1 Reliability vs. Execution Time
  • The more runtime checks your perform, the slower
    your program will execute
  • Java is a classic example
  • All references to array elements get checked
    before use
  • C is the other side
  • You can access an array out of bounds
  • Itll trigger a memory access violation, or
    exhibit unpredictable behavior, or behave just
  • C is faster than the Java equivalent, Java is
    more reliable

Tradeoff 2 Readability vs. Writability
  • But wait, we said earlier that readability is a
    requirement of writability!
  • True, but sometimes a high level of writability
    reduces readability
  • Case in point APL
  • Lots of mathematical operators
  • High level of orthogonality operations on
  • Heres a one-line program that finds primes
  • Hardly readable!

Tradeoff 3 Writability vs. Reliability
  • C allows memory manipulation, through the pointer
    data type
  • If you access the wrong memory address again,
    access violations, unpredictable behavior, or
    normal execution could result
  • Java does not have pointers, and everything is
    automatically garbage collected. Thats safe.
  • C is thus more powerful, Java is more reliable
  • Is it clearer now, why C is often used to program
    operating systems?

Virtual Computers
  • This is what language tools (compilers,
    interpreters, etc.) create i.e. the aura of a
    Java computer
  • In reality, the computer itself understands its
    own machine language which we call
    macroinstructions, and the tools perform
    appropriate conversions

Sample Virtual Computers
  • Java Computer OS Java Compiler JVM
  • C Computer OS C Compiler
  • SCHEME Computer OS SCHEME Interpreter
  • Languages can directly or indirectly make system
    calls to the operating system
  • Request resources
  • Launch new processes
  • Open/close files

  • The user programs in a high-level language
  • But the computer can only understand machine
  • We need to convert between the two
  • This is the job of compilation
  • Advantage runtime speed

Lexical Analysis
  • Remove comments
  • Convert characters in the source into tokens
  • Example tokens
  • VAR(X)

Syntax Analysis
  • Takes the tokens as input
  • Knows the rules of the language, i.e. the
    language grammar
  • Produces syntax errors if there are any
  • For example, say in Java I left out a semicolon
  • int x 4
  • float y

Intermediate Code/Optimization
  • Simplified intermediate form generated
  • Semantic analyzer catches logic errors, like
    passing incompatible types
  • Optimization (optional) makes program smaller,
    faster, or use less memory
  • Whats the tradeoff with an optimizer?

Symbol Table
  • Acts as a database
  • Any user-defined names (variables or functions)
    and associated types are included
  • Lexical and Syntax Analyzer insert into the
  • Semantic Analyzer and Code Generator check it

Code Generation
  • Performs final conversion to machine language
  • Can we use the same code generation for all
    architectures (Intel, SPARC, etc.)?

  • What if we need to use other machine code?
  • For example, in C, if I want to print an integer
    x to the screen
  • printf(d, x)
  • Wheres the machine code for printf?
  • Answer It is contained within system files. We
    must thus link this machine code.

Linking Step
Something to remember
  • The von Neumann bottleneck
  • Remember, instructions and data each reside in
  • Loading an instruction from memory is in general
    much slower than executing the instruction.
  • Solution Parallel Computing
  • Important area of research

  • An interpreter is a software program which takes
    the source program and interprets its
  • Advantage Good debugging
  • Disadvantages
  • Slow execution time
  • Takes more memory

Hybrid (Java, Perl, Python..)
  • Java statements are first compiled to
    intermediate byte code
  • Byte code is then interpreted by the JVM
  • More tools have been developed recently
  • Machine language translators and JIT

Food for Thought
  • Why would having both a compiled and interpreted
    language implementation be a good thing?

  • Executed before compilation, performs
    substitutions in source code.
  • Seen more with C
  • Preprocessor can paste in the contents of a
  • include myFile.h
  • Preprocessor can substitute a value for an
  • define PI 3.1415926535

Interactive Development Environments
Evolution of Programming Languages
Anyone seen this before? Theres a more updated
version in your textbook! Rest of the class
will be a history lecture
The first language Plankalkul (1945)
  • Invented by the German scientist Konrad Zuse
  • Integer and floating point operations
  • Arrays and records
  • If statement, and looping
  • Ran on the Z4
  • Sample program to assign A5 A41,with A
    being an array of n-bit integers
  • A 1 gt A
  • V 4 5
  • S 1.n 1.n

Plankalkuls arrival got delayed..
  • In the meantime, people started programming in 0s
    and 1s
  • Each instruction for hardware was a series of
    on/off signals
  • Hard to read
  • If your program is stored sequentially in memory
    and instructions reference each other, adding or
    removing them becomes problematic
  • So we found our own need for higher level
  • Even though, really, Zuse had done it 10 years

Short Code (1952)
  • A bit higher level, operators represented by
    integer codes
  • For example
  • X0 sqrt(abs(Y0))
  • Would look like this
  • 00 X0 03 20 06 Y0
  • 50 times slower than machine code!
  • UNIVAC compiler was the first in 1953
  • Speedcoding introduced floating point operations
    in 1954

Fortran (1954)
  • IBM 704 included floating point operations in
  • Sparked the Laning and Zierler system (compiler)
  • Stands for FORmula TRANslating System FORTRAN
  • Fortran 0 Experimental
  • Fortran I (1957) I/O, six-character naming
    schemes, subroutines, if, do
  • Fortran II (1958) Independent subroutine
  • Fortran 66 (1966) Variable declarations
  • Fortran 77 (1977) Strings, else
  • Fortran 90 (1990) Dynamic arrays, records,
  • Fortran 95 (1995) forall
  • Fortran 03 (2003) OOP

LISP (1958)
  • Emerged from interests in list processing and AI
  • Two kinds of data structures
  • Atoms
  • Lists (contain atoms or other lists)
  • (A (B C) D (E (F G)))
  • A list means the application of a function, what
    are the functions above? You can write your own
  • (defun square (x) ( x x))
  • (square 4) lt- Returns the value 16
  • Descendants SCHEME (1975) and COMMON LISP (1996)

ALGOL 60 (1960)
  • This was the first attempt at a universal
    programming language. The ALGOrithmic Language.
  • Goals
  • Syntax close to mathematical notation
  • Use to describe an algorithm
  • Programs must translate to machine language
  • Success only as an algorithmic language
  • Failure as a programming language
  • Too much debate on features
  • No I/O
  • Features were too complex at the time people
    still entrenched with Fortran

COBOL (1960)
  • Designed primarily for business applications
  • Still the most widely used
  • Strengths Ease of use and readability
  • Sacrificed Computing power
  • But for the domain, thats really ok!
  • Biggest contribution The record
  • See an example, pages 65-67

PL/I (1965)
  • Another attempt at a universal language.
  • ..
  • Triggered by two separate groups of users
  • Goal replace Fortran, COBOL and LISP
  • ..
  • Contributions
  • Exception handling
  • Pointers
  • Array cross sections
  • Main problem was the large size (too many

SIMULA (1967)
  • Beginnings of data abstraction
  • Began the concept of a class
  • Designed mostly for simulation, struggled for
    acceptance outside of that area
  • What does this and the experience of ALGOL 60
    (which introduced blocks and good control
    structures) tell us?
  • Descendants of this and ALGOL are used today!

ALGOL 68 (1968)
  • Main goal was orthogonality
  • User-defined data types
  • Flexi-arrays
  • Goal was writability, compare to PL/I
  • PL/I achieved it by providing a large number of
  • ALGOL 68 provided a few basic constructs, but
    maintained orthogonality
  • Effectively an unlimited set of data types
  • Descendants Pascal, C, C, Java

BASIC (1971)
  • Designed for the user
  • Easy to learn
  • Pleasant and friendly
  • Biggest contribution Timesharing
  • GE 255 at Dartmouth University had the compiler
  • 14-20 students could execute batch jobs
  • At the time punch cards were popular
  • Early versions were not conducive to complex
  • Resurged in the 90s with True and Visual Basic
  • Example, p. 69

SNOBOL (1971)
  • First language designed for text processing
  • Powerful operations for string pattern matching
  • Where could this be applied?

Pascal (1973)
  • Designed as a teaching language
  • Most popular for teaching programming up through
    the late 1990s
  • Balanced simplicity and expressive power well
  • Not designed for scientific or performance
    intensive tasks

Prolog (1975)
  • Main logic language
  • Uses declarative semantics you can discern the
    meaning of a statement independently of context
  • High-level
  • Specifies the form of the result
  • Not how its computed
  • Example (evaluates to true)
  • parent(joanne, jake)
  • parent(vern, joanne)
  • grandparent(x, z) parent(x, y), parent(y, z)
  • grandparent(vern, jake)

C (1978)
  • BCPL (1969), simple systems language
  • B (1970)
  • Typeless
  • Everything considered in terms of (1 or more) 32
    bit words
  • C
  • Statically typed
  • Provides flexibility, sacrifices safety
  • No complete type checking
  • Memory management
  • Connections to UNIX

Smalltalk (1980)
  • Took SIMULA to the extreme
  • Completely object-oriented
  • Everything is an object, all computing follows
    the following procedure
  • Send a message to an object, invoking a member
  • Object replies by sending another object
    (message) back

Ada (1983)
  • 450 programming languages in use by the
    Department of Defense a problem
  • This was an attempt to standardize
  • Main features
  • Exception handling (clean recoveries from error)
  • Generic program units
  • Types can be unspecified, determined at compiled
  • Concurrent execution of procedures
  • Termed a rendezvous
  • Procedures could communicate and share data

Perl (1987)
  • Scripting language
  • Memory efficient arrays
  • Gaps do not take up space
  • Allows string-indexing
  • Implicitly declared variables
  • Scalars start with
  • Arrays start with _at_
  • Associative arrays start with
  • Look at p. 85 for an example.
  • Great for text processing (like SNOBOL)

C (1990)
  • Builds on C, support some of the features of
  • In fact, it was originally termed C with
  • Supports procedural and object-oriented
  • Can inherit from multiple superclasses
  • Virtual functions
  • Operators can be overloaded (meaning can
  • Functions generic by type (templates)
  • VERY popular language
  • Backcompatible with C and tools are inexpensive
  • Has similar insecurities and flexibility of C
  • Compare Eiffel (1992) and Delphi (Pascal,

Java (1993)
  • Derived from C
  • Goals Smaller, simpler and safer
  • Initially for embedded systems
  • Cannot write standalone programs all control
    proceeds through member functions starting with
  • Supports only object-oriented programming
  • No multiple inheritance
  • Supports concurrent execution
  • Implicit garbage collection
  • Safe type coercions
  • Unlike C, where a float could be coerced to an int

Java also wanted portability
  • So they implemented a two-step process
  • Compile source code to byte code
  • Run the JVM software to interpret the byte code
  • Any machine with a JVM could use Java
  • Problem Much slower than a fully compiled
    language which runs machine code on the hardware
  • Fix Just-In-Time Compilation
  • A third step
  • When a program is loaded into memory, translate
    byte code to machine code, then run it
  • So you only have an initial translation

Scripting Languages
  • JavaScript (1998)
  • Runs on a client, can create/modify HTML
  • PHP (2000)
  • Runs on a server, replaces its own source with
  • Can interact with databases
  • Python (2004)
  • Object-oriented, dynamically typed, lists,
    tuples, dictionaries, pattern matching, exception
    handling, garbage collection, can call
    precompiled C code
  • NEWS FLASH Popularity climbing
  • Ruby (2005)
  • Purely object-oriented, dynamic class definitions

C (2002)
  • Purpose Component-based software development
  • Brings back the features of C that Java took
  • Except multiple inheritance
  • Delegates allow functions to be passed around
    and assigned to variables
  • foreach statement useful for iterating over
    members of a container
  • Designed for use with .NET
About PowerShow.com