Lecture 1
CSC447: Programming Language Concepts
Professor: Karen L. Bernstein
Tuesdays, 5:45 - 9:00 pm
CS&T Center, Room 218
Why study Programming Languages?
learn new languages more easily
choose appropriate languages
program better
design better languages
Overview of Course
Overview of Todays Lecture
Class Information
Overview of Programming Languages
Describing Syntax
Issues for Imperative Languages
Introduction to Perl
Contact Information
Office: CS&T Center 462
Office Hours:
Monday 4:00 - 5:30, Tuesday 4:00 - 5:30, and by appt
Phone: (312) 362-5315, Fax: (312) 362-6116
Email:
kbernstein@cs.depaul.edu
Course Web Page:
http://www.depaul.edu/~kbernste/csc447
Texts
Ravi Sethi, Programming Languages: Concepts and Constructs, Addison-Wesley, 1996
Randal Schwartz, Learning Perl, O'Reilly & Associates
Bruce Eckel, Thinking in C++, Prentice Hall, 1995
Meyers, Clack and Poon, Programming with Standard ML, Prentice Hall, 1993
Prerequisites:
C Programming (CSC215 or CSC225)
Foundations of Computer Science (CSC415, CSC416, CSC417)
Operating Systems (CSC343)
Computer Architecture (CSC345)
Discrete Mathematics (MAT 140)
Grading
Plagiarism
Students are expected to write their own assignments. The penalty for plagiarism is a grade of F in the course.
Late Policy
Each student is allowed four free late days on the homework assignments for the term. Please use the late days wisely since I will not give out any additional extensions on the assignments.
Web Pages
Course Page
Announcements
Syllabus
Calendar
Lectures
HW Assignments
Useful Links
Video Students
Same due dates and assignments
Must come to Midterm and Final
Get assignments from the web page
Keep in touch (email, telephone, office)
Come to class when you can
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
Structure of Programming Languages
Syntax
Legal programs
Static Semantics
Type system
Dynamic Semantics
Program execution
Lexical Structure
identifiers
keywords
operators
seperators
literals
comments
Expressions
Prefix
Postfix
Infix
Associativity
Precedence
Mixfix
Tree Representation of Expressions
BNF (Context Free Grammars)
A set of tokens
A set of non-terminals
A set of rules
A designated start symbol
Issues with Parsing
Concrete vs. Abstract Syntax
Syntactic Ambiguity
Parsing Methods (top-down vs. bottom-up)
Error generation
Extended BNF
Braces, {}, zero or more repetitions
Brackets, [], optional construct
Vertical bar, |, choice
Parenthesis, (), grouping
Syntax Chart
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
Imperative Programming
Data and Types
State
Flow of Control
Program Composition
Data
imperative languages are based on assignment
size and layout of data structures are determined statically (at compile-time)
storage is allocated and deallocated explicitly
the type declaration determines the data representation
Issues with Types
definition vs. declaration
constant declarations
uninitialized variables
renaming and aliasing
several names, one object
overloading
several objects, one name
Basic Types
characters
integer numbers
precision
signed / unsigned
real numbers (floating point)
precision
Compound Types
Enumeration Types
Arrays
Lists
Sets and bags
Records
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).
Why
system administrators are a lot like
Santa Claus (from rec.humor.funny)
When you ask Santa for something, the odds of receiving what you wanted are infinitesimal.
Santa seldom answers your mail.
When you ask Santa where he gets all the stuff he's got, he says, "Elves make it for me."
Santa doesn't care about your deadlines.
Nobody knows who Santa has to answer to for his actions.
Santa laughs entirely too much.
Santa thinks nothing of breaking into your $HOME.
Only a lunatic says bad things about Santa in his presence.
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
I wrote the homework parsing program in Perl
Pragmatics
How to get Perl
How to run Perl
Perl is interpreted but...
The program is parsed before the first statement is executed
Since it is interpreted, no object code is generated
Our First Perl Program
print "Hello, world!\n"
A little more..
print "What is your name?";
$name = <STDIN>;
chop($name);
print "Hello, $name!";
Data and Types (Perl)
Scalar Data
Numbers
Strings
Scalar Variables start with $
if uninitialized, have undef value
Arrays/Lists
Array variables start with @
Associative Arrays
Associative array variables start with %
Scalar Data
all numbers are the same, everything is stored as a float
strings have no limit on length (can fill all of memory)
single quoted strings
hello
don\t
silly \\ me
hello\n
double quoted (like C)
"hello\n"
"coke\tsprite
Operators
arithmetic basically same as C
with string operators
"hello " . "world" (concatenation)
"hello world" x (2 + 1) (repetition)
no overloading, lots of coercions
"hello world" . (2+1)
"hello world" * (2+1)
binary operators (orthogonality)
$a = $a + 5; $a += 5;
$str .= more stuff;
two language features that can be combined freely with out restricting each other are said to be orthogonal
Binary operators (orthogonality)
$a = $a + 5; $a += 5;
$str .= more stuff;
two language features that can be combined freely with out restricting each other are said to be orthogonal
Expressions
have side-effects, can change internal state
assignments have the value of the assigment
chop
$a = 3;
$b = ($a+=2) * ($a-=2);
$a = hello;
$b = chop($a) . chop($a);
Arrays
(1,2,3), (hello, 13)
printing arrays
$name = Karen;
print (Hello,$karen,"/n");
more...
@test = (1,2,3);
@test[1] = 2;
$a = @test;
@test2 = (0,@test, 4)
More on Arrays
slices
@test[1,2,3] = @test[3,2,1];
are also like lists
@test = (@test, 4)
@($a, @test) = @test
Associative
Arrays
(non-linear indexing)
Examples:
$test{Jim} = "Hello";
$test{Tom} = 100;
$test{1} = keys(%test);
$a = keys(%test);
@test2 = %test;
Flow of Control
if - else (no dangling else)
false: 0, undef, ""
true: "00", "hello", "1", 1
why (undef = true) is dangerous
print "What is your name?";
if ($a = <STDIN>)
{chop($a);
print ("Hello ",$a);}
else
{print("Why dont you answer me?)}
more Control Structures
while/until
for
foreach
@in = <STDIN>
foreach $I (0 .. $#in){chop($in[$i]);}
last, next, redo
&&, ||, ?
Next Class
More Perl
Regular Expressions
Formats
Abstract vs. Concrete Syntax
Programming exercise
Parameter Passing Methods