CSC447: Programming Language Concepts
Lecture 10
March 11, 1997
Todays Lecture
Return Homework 7
Outstanding grading
Homework 6 (due March 18)
Course overview / Review for Final
Where can you go from here
(programming Languages activities at DePaul)
Why study Programming Languages?
learn new languages more easily
choose appropriate languages
program better
design better languages
Overview of Course
Imperative Programming Languages (Algol-like languages)
Fortran I, Fortran II, Fortran IV, Fortran 77, Fortran 90
ALGOL 58, ALGOL 60, ALGOL W
CLU
Pascal, MODULA-2, MODULA-3, Oberon
CPL, BCPL, B, C, ANSI C
BASIC, QuickBASIC, True BASIC, Visual Basic
COBOL, PL/1
ADA
APL
Functional Programming Languages
Lisp, Mac Lisp, Scheme, Common Lisp
ML, Standard ML, CAML
SASL
Miranda
Haskell, Gofer
Object-Oriented Programming Languages
Simula
Smalltalk
C++
Eiffel
Java
Other Programming Paradigms
Logic
Concurrent
Constraint
Visual
Real-time
Some Language Evaluation Criteria
Syntax
Control Structures
Data types
Support for Abstraction
Expressiveness
Type System
Efficiency
Some Influences on Programming Language Design
Application Domain
Available Hardware
Programming Methodology
Implementation Methods
Programming Environments
Structure of Programming Languages
Syntax
Legal programs
Static Semantics
Type system
Dynamic Semantics
Program execution
Programming Language Descriptions
Tutorials
Reference Manuals
Formal Definitions
operational semantics
denotational semantics
axiomatic semantics
Programming Language Implementation
Implementation Strategies
Implementing Debuggers
code specially compiled with symbol table information
debugger instruments object code for breakpoints
Issues:
optimized code
declarative languages
Things
you should be able to do with Context-free grammars:
Given a grammar, describe the language
Given a language, write the (E)BNF
Prove that a given grammar is ambiguous
Give a common ambiguous construct
Why look at Perl in this Class?
It is very different from C, C++ and SML
It breaks every rule of "good" language design
It is very popular and useful
It is enough like C, so you can get started quickly
What is
Perl?
Practical Extraction
and Report Language
Perl's author, Larry Wall, describes Perl:
Perl is an interpreted language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It's also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).
Interesting Aspects of Perl
Flexible data structures
No type errors, lots of type coercion
Automatic Memory Management
Very large language
Parameter Passing Methods
Call-by-value
Call-by-reference
Call-by-value-result (copy-in/copy-out)
Macro Expansion
Call-by-name
Lexical vs. Dynamic Scoping
program scope;
var n: char;
procedure W;
begin
writeln(n)
end;
Memory layout for C programs
Elements of an Activation Record
Static link (Access link)
Dynamic link (Control link)
Saved state (program counter, registers)
Parameters
Function result
Local Variables
Object-Oriented
Design
(focus on data
rather than functions)
Data encapsulation
Inheritance
Dynamic binding
Object-Oriented Thinking
object: A collection of data and operations
class: A description of a set of objects
subclass: A subset of a class, with additional properties
instance: An object of a class
method: A procedure implementing an operation
message: A request for the execution of a method
Object Model
Abstraction
Encapsulation
Modularity
Hierarchy
Abstraction
"An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer."
Booch
An
Example Abstraction
(function prototypes)
class stack{
public:
void push(int v);
int pop(void);
private:
int buffer[100];
int top;
};
Encapsulation
The process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation.
Booch
Provides information hiding
Simplifies changes to implementation
Modularity
Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.
Booch
Hierarchy
A ranking or ordering of abstractions.
Booch
Inheritance (is a)
Aggregation (has a)
What is
an object?
It is an instance of a class!
It has State
It exhibits well-defined behavior
It has a unique identity
Basic Operations on Objects
Modifiers
(alters state)
Selectors
(accesses state)
Iterators
(permits all parts of an object to be accessed)
Constructors
Destructors
Relationships among Objects
Links (visibility)
Aggregation (parts)
Reference Variables
int val = 10;
int &refval = val; //okay
int &refval2; // error: uninitialized
refVal += 2;
int ii = refVal;
ii += 2;
Argument
Passing
(supports call by reference)
void swap (int v1, int v2){
int tmp = v2; v2 = v1; v1 = tmp }
void pswap (int *v1, int *v2){
int tmp = *v2; *v2 = *v1; *v1 = tmp }
void rswap (int &v1, int &v2){
int tmp = v2; v2 = v1; v1 = tmp }
Scoping
file scope (global)
local scope
class scope
Scope Operator
#include <iostream.h>
const max = 65000;
const lineLength = 12;
void fib (int max)
{ if (max < 2) return;
cout << "0 1";
int v1 = 0, v2 = 1, cur;
for (int ix =3; ix <= max; ++ix){
cur = v1 + v2;
if (cur > ::max) break;
cout << cur << " ";
v1 = v2; v2 = cur;
if (ix % lineLength == 0) cout << endl; }
}
Class Scope
int height;
class FooBar {
public:
FooBar () {height = ::height}
private:
short height;
};
In contrast, Local Scope
int height = 66;
localFunc() {
int hi = height;
int height = 24;
hi = height;
};
int height = 66;
badPractice(){
int height = height;
}
Virtual functions / Dynamic Binding
Some Properties of Standard ML
programs are made up of functions
program with values not states
no side-effects
no assignment statements
no storage allocation
names and expressions have unique values that will never change, referential transparency.
lists and trees are principal data structures
types are inferred automatically!
language is small and elegant
programs are easy to reason about
Higher-order functions
fun map(F,[]) = []
| map(F,(x::xs)) = ((F x)::map(F,xs));
val map: (('a -> 'b) * 'a list)->'b list
fun square (x:int) = x * x;
val square : int -> int
map (square, [1,2,3]);
val it = [1,4,9] : int list;
map (~, [1,2,3]);
val it = [~1, ~2, ~3] : int list;
Type Inferencing
Base types
Type inference rules
Polymorphism is hard...
Functional Languages
Languages
Miranda
Scheme
Haskell ( Gofer)
Standard ML (CAML)
Implementations
Lazy
Evaluation
(call-by-name, call-by-need)
cond expr (laziness in a call-by-value language)
const functions
lazy lists, streams
Structure of Programming Languages
Syntax
Legal programs
Static Semantics
Type system
Dynamic Semantics
Program execution
CSC 535
Formal Semantics of Programming Languages
(Spring 1998)
Dynamic semantics
Designing programming languages
Reasoning about programs
Functional programming
New
Course Announcement
CSE599: Principles of Concurrent System Design
In this course, you will learn rigorous approaches for designing and analyzing concurrent (parallel, distributed, reactive) systems. Topics include:
Models of concurrent systems
Temporal logic
How to use existing CASE tools for concurrent systems
SE 533: Software Validation and Verification
Techniques, methods and tools for software inspection and testing. Theory and applications of formal verification of programs. Techniques and tools for automated analysis of programs. This course will focus on distributed programs and will meet together with CSC599.
If you think that you might be interested in taking either of these courses, please send me email.
What is Model Checking?
Some
Characteristics of
Model Checking Systems
Automated!
Exhaustive case analysis of all possible states
Model checkers can analyze state spaces with a size on the of
Partial verification (finds bugs)
Successes
with Model Checking
(finite state reactive systems)
network protocols
synchronous/asynchronous circuits
cache coherence protocols
telephone switching systems
distributed programs
Alternating Bit Protocol
An Example of a Reactive System
"reacts" to stimulus from environment
does not terminate
Analysis with Model Checking
Build a finite state (usually abstract) model of the protocol
Check automatically that the desired temporal property holds,
or...
Produce a counter example
Building the Finite State Model
Draw it! (many tools provide a GUI)
Automatically generate it from specifications written in a language such as:
CSP (Communication Sequential Processes, Hoare), or
CCS (Calculus of Communicating Systems, Milner)
Temporal Properties
To reason about reactive systems and the interaction of their components, we need to be able to state temporal properties.
for example:
Every message sent is eventually received
A message is not received unless it was previously sent.
If x is sent before y, then x is received before y.
Some properties of the components
Sender continues to resend msg until ack
If channel continues to receive input, it will eventually transmit a msg
Receiver does not produce ack before message is output
...
Temporal Properties
Safety property: something bad will not happen. Can be proven false by exhibiting a finite run.
Liveness property: something good will eventually happen. Can only be proven false by exhibiting an infinite run.
Temporal Logic (Pneuli)
"every time a message input, the same message is eventually output"
G(input(x) Þ F output(x))
"infinitely often" (fairness)
GFp means p occurs infinitely often
("always eventually p")
GF send_on_chan (x) Þ GF recv_on_chan (x)
"if message is sent infinitely often, it is received infinitely often"
Verifying the Specification
Computer-Aided Verification Tools
The Concurrency Workbench (Edinburgh)
FDR (Oxford)
The Concurrency Factory (SUNYSB)
HyTech (Berkley)
Murphi (Stanford)
PVS (SRI)
SPIN (Bell Labs)
Meije (INRIA)
COSPAN (Bell Labs)
A research project
COBOL
Legacy System
Why Model Checking has not been applied to software
Infinitely many states
Too many properties to prove to be useful
Properties are complicated
Why this application is different!
Regulations are relatively simple properties
It is very important that these properties are satisfied
COBOL has relatively simple data and flow of control
The programming style has a lot of structure
Testing is very expensive and tedious
CSC599: Advanced Topics in Programming Languages
project-based course with a focus on systems-oriented topics and experimentation with programming environments
2 credits each term
no exams
read research papers and do a course project
Purpose of the seminar
To investigate current programming languages and programming environments.
To provide for the scholarly development of students beyond the usual coursework
To identify new applications of current technology and needs for new technology.
To build a group at DePaul of people with interests in programming languages and programming environments.
Some of the things you can do in do in the seminar
Learn and evaluate new languages, environments, tools.
Give talks/posters (at school, local seminars, conferences).
Write about your discoveries (for seminar, school, your company, the press).
Develop new languages, environments, tools.
Develop tools for public distribution.
Write research papers.
Ground
rules
(Student responsibilities)
There aren't any assignments or specific requirements. Students are expected to set their own goals and motivate themselves.
Every student should do something every week.
Develop some specific short and long term goals.
Participate as a member of the "team"
(listen, provide feedback, encourage, collaborate).
My responsibilities
To encourage students to extend themselves
To get resources (equipment, books, software, develop new courses ...)
To introduce you to new resources and opportunities
To provide feedback for your work
To be an active participant.
Student Projects This Term
Compiling to Java byte-code
A user interface for Standard ML
Public domain COBOL compiler
CORBA implementation
Other Courses
CSC 448/548 Compiler Design
Software Engineering Courses
SE 451: Distributed Software Development
CSC 458/358 Symbolic Programming
Software Research Studio
Software Engineering
Database
Programming Languages and Environments