Docsity

CS360: Programming Language Concepts - Welcome and Overview, Study notes of Programming Languages

Toggle sidebar
bg1
1
3/31/2005
1
Welcome to CS360
Programming Language
Concepts
Dr. Amie Souter
3/31/2005
2
Announcements
• Homework 1: posted next week
• Lecture notes on course web page
• Reading chapters 1 – 3
• Mailing list, did everyone get mail?
3/31/2005
3
Some Extra Bits
•http://www.oreilly.com/news/graphics/prog_lang_
poster.pdf
•A computer language is a language used by, or in
association with, computers. Often, the term is
used synonymously with programming language,
but in general a computer language need not be a
programming language. For example, markup
languages like HTML are generally not held to be
programming languages, but they are computer
languages. [Wikipedia]
3/31/2005
4
What is a programming language?
• Break into groups of 5.
• Define: programming language
• List as many programming languages
as you can.
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download CS360: Programming Language Concepts - Welcome and Overview and more Study notes Programming Languages in PDF only on Docsity!

3/31/2005 1

Welcome to CS

Programming Language

Concepts

Dr. Amie Souter

3/31/2005 2

Announcements

• Homework 1: posted next week

• Lecture notes on course web page

• Reading chapters 1 – 3

• Mailing list, did everyone get mail?

3/31/2005 3

Some Extra Bits

  • http://www.oreilly.com/news/graphics/prog_lang_

poster.pdf

  • A computer language is a language used by, or in

association with, computers. Often, the term is

used synonymously with programming language ,

but in general a computer language need not be a

programming language. For example, markup

languages like HTML are generally not held to be

programming languages, but they are computer

languages. [Wikipedia]

3/31/2005 4

What is a programming language?

• Break into groups of 5.

• Define: programming language

• List as many programming languages

as you can.

3/31/2005 5

• Louden’s Defintion:

  • A notational system for describing computation in

machine-readable and human-readable form.

• Bruce MacLellan’s definition:

  • A language that is intended for the expression of

computer programs and that is capable of

expressing any computer program.

• Ravi Sethi’s definition:

  • Notations used for specifying, organizing, and

reasoning about computations.

What is a programming language?

3/31/2005 6

Why Are There So Many

Programming Languages?

• Evolution

– We have learned better ways of doing things

over time

• Socio-economic factors

– Proprietary interests, commercial advantage

• Special purposes

• Personal preference

3/31/2005 7

What Makes a Language Successful?

• Easy to learn

  • Basic, Pascal

• Easy to express things

  • ā€œPowerfulā€
  • Easy to use once known
  • C, Lisp

• Easy to implement

  • Small machines, limited resources
  • Basic, Forth

3/31/2005 8

What Makes a Language Successful?

• Efficient compilers

  • Generate small / fast code
  • Fortran

• Backing of a powerful sponsor

  • Ada, Visual Basic

• Wide dissemination at a minimal cost

  • Pascal, Java

• Inertia

  • Fortran, Cobol

3/31/2005 13

Course Information

• Instructor: Dr. Amie Souter

– E-mail: [email protected]

– Office: 106 Crossings

– Office Hours: 5:00-6:00 Monday and

2:30-3:30 Thursday or by

appoint.

– Teaching assistant: Yogi Mehta

[email protected]

– Class web page:

http://www.cs.drexel.edu/~souter/cs360/sp

3/31/2005 14

Course Prerequisites

  • CS 171 (Prog. I), 172 (Prog. II), and 260 (Data structures)
  • Comfortable with an object-oriented language (ideally should have seen at least two languages)
  • Ideal:
    • CS 281 (Systems Architecture I) – understanding of the underlying of basic computer architecture (assembly language, machine organization)
    • CS 270 (Foundations of Computer Science) – should be comfortable with the mathematical tools used to describe and analyze programming languages (logic, recursion – material on finite state machines and grammars useful but will be covered in this class)

3/31/2005 15

Course Objectives

  1. Understand how to compare and evaluate different programming languages and know what factors need to be taken into account.
  2. Be comfortable with the major programming paradigms and be able to use at least one language from each paradigm.
  3. Understand some of the issues involved in implementation of programming languages; this should help them program more efficiently.
  4. Be familiar with elementary concepts of formal language theory such as context-free grammar.
  5. Be able to formally specify the syntax of programming languages.
  6. Be familiar with the essentials of lexical analysis and elementary parsing procedures.
  7. Understand dynamic and static scope, dynamic and static binding and the issues they give rise to.
  8. Understand the advantages and disadvantages of strong/weak type checking.
  9. Understand the different methods of parameter passing and how they might be implemented and understand some of the issues involved in calling subroutines. 10.Understand implementation issues associated with oo programming. 3/31/2005 16

Assignments and Exams

  • Programming assignments (35%)
    • Interpreter project
    • starts in a few weeks
  • Homework assignments (20%)
    • 4 written assignments or short programming assignments
  • 2 Midterm exams (20%)
    • Closed book, closed notes
  • Final exam (20%)
    • Closed book, closed notes
    • Comprehensive
  • Attendance and Class Participation (5%)
    • Attendance is expected
    • Active participation is also excepted

3/31/2005 17

• YOU ARE GRANTED 2 LATE DAYS

– Use them as you see fit.

– Send email to TA to let him know.

– After 2 days are used up, assignments

will not be accepted.

– Read course syllabus for details!!

Late Submission Policy

3/31/2005 18

Required Textbook

• Programming Languages Principles and

Practice 2 nd^ edition, Kenneth Louden,

3/31/2005 19

Why do we have programming

languages? – What is a language for?

  • Way of thinking
    • way of expressing algorithms
    • languages from the user's point of view
  • Abstraction of virtual machine
    • way of specifying what you want the hardware to do without getting down into the bits
    • languages from the implementor's point of view
  • This course tries to balance coverage of these two

angles. We will talk about language features for

their own sake, and about how they can be

implemented.

3/31/2005 20

What different categories of

languages exist?

• http://en.wikipedia.org/wiki/Categori

cal_list_of_programming_languages

3/31/2005 25

Attributes of a Good Language

• Support for abstraction

  • program data reflects problem being solved

• Reliability of programs

  • Does the program behave the same way every time it

is run with the same input data?

• Cost of use:

  • Cost of program creation
  • Cost of program translation
  • Cost of program execution
  • Cost of program maintenance

3/31/2005 26

What does a programming language

need to be useful?

3/31/2005 27

Compilation and Interpretation

• A compiler is aprogram that translates

high-level source programs into target

program

• An interpreter is a program that

executes another program

3/31/2005 28

Mixing Compilation and Interpretation

• Fuzzy difference:

– A language is interpreted when the

initial translation issimple

– A language is compiled when the

translation process iscomplicated

3/31/2005 29

Groups

• Class discussion: Half the class will

represent the advantages of

interpretation , the others the

advantages of compilation. Which is

better?

Compiled Interpreted

Where do languages fall on the following spectrum?

3/31/2005 30

Compilation and Interpretation

• Interpretation

  • Greater flexibility, better diagnostics
  • Allow program features (data types or sizes) to

depend on the input

  • Lisp, Prolog: program can write new pieces of itself

and execute them on the fly

  • Java: compilation, then interpretation (JIT)

• Compilation

  • Better performance
  • Many decisions are made only once, at compile time,

not at every run time

  • Fortran, C

3/31/2005 31

Phases of Compilation

3/31/2005 32

Example

• Example program:

read A

read B

sum := A + B

write sum

write sum / 2

3/31/2005 37

Code Generation

• Target code:

.data A: .long 0 B: .long 0 sum: .long 0 .text main: jsr read movl d0,d movl d1,A jsr read movl d0,d movl d1,B movl A,d

movl B,d addl d1,d movl d1,sum movl sum,d movl d1,d jsr write movl sum,d movl #2,d divsl d1,d movl d1,d jsr write

3/31/2005 38

Back-end

• Target code generation

  • Generate assembly or machine language
  • Traverses the syntax tree to generate

elementary operations: loads and stores,

arithmetic operations, tests and branches

• Code improvement (optional)

  • A.k.a ā€œoptimizationā€
  • Transform program into a new version with

same functionality, but more efficient (faster,

uses less memory)

3/31/2005 39

Error classification

• Lexical: character-level error, such as

illegal character (hard to distinguish from

syntax).

• Syntax: error in structure (e.g., missing

semicolon or keyword).

• Static semantic: non-syntax error prior to

execution (e.g., undefined vars, type

errors).

• Dynamic semantic: non-syntax error during

execution (e.g., division by 0).

• Logic: programmer error, program not at

fault.

3/31/2005 40

Sample Errors (Java):

public int myexample ( int v# ) // lexical

{ int z = value // syntax - missing ;

y = v; // static semantic - y undefined

while ( y >= 0 ) // dynamic semantic -

// division by zero

{ int t = z/y; }

return y; // logic - should return t

3/31/2005 41

Examples in three languages

(Euclid’s gcd algorithm):

Compute the greatest common divisor

of two integers input by the user, and

print the result. For example, the gcd

of 15 and 10 is 5.

3/31/2005 42

C (Figure 1.7, p. 26):

#include <stdio.h> int gcd(int u, int v) /* ā€œfunctionalā€ version / { if (v == 0) return u; else return gcd (v, u % v); / ā€œtailā€ recursion / } main() / I/O driver */ { int x, y; printf("Input two integers:\n"); scanf("%d%d",&x,&y); printf("The gcd of %d and %d is %d\n", x,y,gcd(x,y)); return 0; }

3/31/2005 43

Java (Figure 1.9, p. 27):

import java.io.; class IntWithGcd { public IntWithGcd( int val ) { value = val; } public int getValue() { return value; } public int gcd ( int v ) { int z = value; / ā€œimperativeā€ version */ int y = v; while ( y != 0 ) { int t = y; y = z % y; z = t; } return z; } private int value; }

3/31/2005 44

Java (continued):

class GcdProg /* driver / { public static void main (String args[]) { System.out.println("Input two integers:"); BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); try / must handle I/O exceptions / { IntWithGcd x = / create an object */ new IntWithGcd(Integer.parseInt(in.readLine())); int y = Integer.parseInt(in.readLine()); System.out.print("The gcd of " + x.getValue()

  • " and " + y + " is "); System.out.println(x.gcd(y)); } catch ( Exception e) { System.out.println(e); System.exit(1); } } }

3/31/2005 49

Summary

• What is a programming language?

• Why study programming languages?

• What kinds of programming languages

exist?

• How is a programming language

implemented?

• Different programming paradigms