Programming Language Concepts CIS 280 - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Programming Language Concepts CIS 280

Description:

Main focus: machine state the set of values stored in memory locations ... is based on objects sending messages (methods applied to arguments) to other objects ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 32
Provided by: me6105
Category:

less

Transcript and Presenter's Notes

Title: Programming Language Concepts CIS 280


1
Programming Language Concepts (CIS 280)
  • Elsa L Gunter
  • NJIT
  • Fall 2001

2
WWW Addresses for SML
  • http//www.cis.njit.edu/elsa/280/110-smlnj.exe
  • ftp//ftp.research.bell-labs.com/dist/smlnj/releas
    e/110/110-smlnj.exe
  • http//cm.bell-labs.com/cm/cs/what/smlnj/index.htm
    l
  • http//cm.bell-labs.com/cm/cs/what/smlnj/doc/basis
    /pages/sml-std-basis.html

3
Language Paradigms
  • Imperative languages
  • Main focus machine state the set of values
    stored in memory locations
  • Command-driven Each statement uses current
    state to compute a new state
  • Syntax S1 S2 S3 ...
  • Example languages C, Pascal, FORTRAN, COBOL

4
Language Paradigms (continued)
  • Applicative (functional) languages
  • Programs as functions that take arguments and
    return values arguments and returned values may
    be functions
  • Programming consists of building the function
    that computes the answer function application
    and composition main method of computation
  • Syntax P1(P2(P3 X))
  • Example languages ML, LISP, Scheme

5
Language Paradigms (continued)
  • Rule-based languages
  • Programs as sets of basic rules for decomposing
    problem
  • Computation by deduction search, unification and
    backtracking main components
  • Syntax Answer - specification rule
  • Example languages (Prolog, Datalog,BNF Parsing)

6
Language Paradigms (continued)
  • Object-oriented languages
  • Classes are complex data types grouped with
    operations (methods) for creating, examining, and
    modifying elements (objects) subclasses include
    (inherit) the objects and methods from
    superclasses
  • Computation is based on objects sending messages
    (methods applied to arguments) to other objects
  • Syntax Varies, object lt- method(args)
  • Example languages Java, C, Smalltalk

7
Programming Language Implementation
  • Develop layers of machines, each more primitive
    than the previous
  • Translate between successive layers
  • End at basic layer
  • Ultimately hardware machine at bottom

8
Basic Machine Components
  • Data basic data types and elements of those
    types
  • Primitive operations for examining, altering,
    and combining data
  • Sequence control order of execution of primitive
    operations

9
Basic Machine Components
  • Data access control of supply of data to
    operations
  • Storage management storage and update of program
    and data
  • External I/O access to data and programs from
    external sources, and output results

10
Basic Computer Architecture
External files
Main memory
Cache memory
CPU
11
Typical Hardware Pipeline
  • Fetch next instruction in program
  • Decode op-code to determine next operation to
    perform
  • Load data from specified registers into operator
    buses
  • Execute operations
  • Store results in specified registers
  • One or more steps performed each clock cycle

12
Hardware Machine Components Data
  • Bits 0, 1
  • Bytes 8 bits
  • Words 16 bits, 32 bits, 64 bits
  • Op-codes typically one or two words long, not
    all words are codes (usually)

13
Operations
  • Correspond to (named by) op-codes
  • Copy data between main registers and main memory
    (or cache)
  • Perform arithmetic and logic operations on data
    in registers, putting results in registers
  • Alter flow of execution, conditionally or
    unconditionally
  • Copy data between I/O busses and memory

14
Sequence Control
  • Most instructions cause the program counter to
    increment by one as a side effect
  • Goto, aka jump, reset program counter
  • Gosub, aka, jump-save-return, same as goto,
    except save previous program counter to register
    first
  • Conditional operations allow a single step to be
    skipped
  • Conditional gotos, and gosubs

15
Data Access
  • Instructions specify data directly (as part of
    the word) or indirectly
  • Indirect access
  • Specify a register that contains data
  • Specify a memory location that contains data
  • Specify a register that contains a memory
    location that contains data

16
Storage Management
  • Basically all computes need to move data between
    registers and main memory
  • Increasingly, most computers have cache in
    between registers and main memory for temporary
    storage
  • Secondary caches becoming more common
  • Multiple processors accessing same memory, but
    with separate caches need coherent view of memory

17
External Environment (I/O)
  • Computer (CPU) must control access to external
    devises
  • Extended memory
  • Hard drives
  • CD-ROM, floppies, etc.
  • Input devices, eg, keyboards, mice,
    analog-to-digital converters
  • Output devices, eg, consoles, sound boards

18
Virtual (Software) Machines
  • At first, programs written in assembly language
    (or at very first, machine language)
  • Hand-coded to be very efficient
  • Use layers of software (eg operating system)
  • Now, no longer write in native assembly language
  • Each layer makes a virtual machine in which the
    next layer is defined

19
Example Layers of Virtual Computers for a C
Program
Input data
Output results
20
Virtual Machines Within Compilers
  • Compilers often define layers of virtual machines
  • Functional languages Untyped lambda calculus -gt
    continuations -gt generic pseudo-assembly -gt
    machine specific code
  • May compile to intermediate language that is
    interpreted or compiled separately
  • Java virtual machine, CAML byte code

21
To Class
  • Name some examples of virtual machines
  • Name some examples of things that arent virtual
    machines

22
Interpretation Versus Compilation
  • A compiler from language L1 to language L2 is a
    program that takes an L1 program and for each
    piece of code in L1 generates a piece of code in
    L2 of same meaning
  • An interpreter of L1 in L2 is an L2 program that
    executes the meaning of a given L1 program
  • Compiler would examine the body of a loop once
    an interpreter would examine it every time the
    loop was executed

23
Bindings of Program Elements
  • A binding of a program element is the selection
    of a particular value for it from a set of
    possible values
  • The binding time is when that selection is made
  • Binding time can depend on whether we use a
    compiler or an interpreter

24
Binding Times
  • Language definition time language syntax and
    semantics
  • Language implementation time interpreter versus
    compiler, aspects left flexible in definition,
    set of available libraries

25
Binding Times
  • Compile time data layout, internal data
    structures
  • Link time (load time) binding of values to
    identifiers across program modules
  • Run time (execution time) actual values assigned
    to non-constant identifiers

26
To class
  • In expression x y 5 what bindings can you
    identify, and when are they most likely made?

27
Program Aspects
  • Syntax what valid programs look like
  • Semantics what valid programs mean what they
    should compute
  • Compiler must contain both information

28
Major Phases of a Compiler
  • Lex
  • Break the source into separate tokens
  • Parse
  • Analyze phrase structure and apply semantic
    actions, usually to build an abstract syntax tree
  • Semantic analysis
  • Determine what each phrase means, connect
    variable name to definition (typically with
    symbol tables), check types

29
Major Phases of a Compiler
  • Translate to intermediate representation
  • Instruction selection
  • Optimize
  • Emit final machine code

30
Major Phases of a Compiler
Source Program
Lex
Relocatable Object Code
Instruction Selection
Tokens
Linker
Parse
Unoptimized Machine-Specific Assembly Language
Abstract Syntax
Machine Code
Semantic Analysis
Optimize
Optimized Machine-Specific Assembly Language
Symbol Table
Translate
Emit code
Intermediate Representation
Assembly Langague
Assembler
Modified from Modern Compiler Implementation in
ML, by Andrew Appel
31
Example of Optimization
  • Program code X Y Z W
  • Load reg1 with Y
  • Load reg2 with Z
  • Add reg1 and reg2, saving to reg1
  • Store reg1 to tmp
  • Load reg1 with tmp
  • Load reg2 with W
  • Add reg1 and reg2, saving to reg1
  • Store reg1 to X
  • Eliminate two steps marked
Write a Comment
User Comments (0)
About PowerShow.com