CSCI 431 Lecture Notes - Introduction to CSCI 431

What is a Programming Language?

Features that a programming language should have:

Examples

Each of the new languages listed above meets some specialized goal. For instance, AMPL is designed for expressing mathematics; HTML is a mark-up language for hypertext documents; and Active VRML, which was derived from the CAML family of languages, has been designed by Microsoft to enable transmission of active virtual reality scenarios across networks.

a few different forms of the expression x + 1

 x + 1          C, Pascal, Ada, Algol
 $x + 1         Perl
 x 1 add        Forth, Postscript
 (+ x 1)        Lisp, Scheme
 add $1 $2 $3   Assembly language

What is this Subject About?

Why do we need to understand programming languages?

What does it mean to understand a programming language?

Let us illustrate the problem via an example. Consider the following statement:

set x[i] to x[i] + 1

Example (continued)

Example (continued)

Example (continued)

What do we need to know to program in a language?

What we need to know (continued)

What we need to know (continued)

Computer Language Levels

Implementation Methods

In theory it is possible to construct a hardware computer to execute directly program written in any particular programming language. But practical considerations favor computers with low-level machine languages, on the basis of speed, flexibility and cost.

The solution:

Translation (compilation)

Translate from the high-level language to the host computer machine language.

Example of translation

C source code:

void initialize(int U[], int size, int init)
{
   int j;

   for (j=0; j < size; ++j)
       U[j]=init;
} 

Example of translation (continued)

corresponding assembly language code:

 #      1 void initialize(int U[], int size, int init)
				; $16 holds U
				; $17 holds size
				; $18 holds init
initialize:
	sextl	$17, $17	; sign-extend $17 to 64 bits
	sextl	$18, $18	; sign-extend $18 to 64 bits

 #      3    int j;
 #      4 
 #      5    for (j=0; j < size; ++j)
	ble	$17, L$5       ; if $17 leq 0, go to L$5

	clr	$1		; $1 holds j, $1 =  0

L$6:
	addl	$1, 1, $1	; add one to $1

 #      6        U[j]=init;
	stl	$18, ($16)	; store $18 in the location that $16 holds

	cmplt	$1, $17, $3	; $3 = $1 lt $17

	lda	$16, 4($16)	; increment $16 to point to next element
	bne	$3, L$6		; branch if j lt size

L$5:

	ret	($26)		; $26 holds return address


Interpretation (software simulation)

Hybrid Systems

Computational Paradigms

The focus of this course is general purpose, high-level languages.

Machine-readable - unambiguous, finite algorithm to translate language, not too complex, has context-free grammar

there are different paradigms of programming languages (similar to different phyla in biology)

Imperative Languages

Procedural Languages

Object-Oriented Languages

Parallel Processing Languages

Functional Languages

Logic Programming Languages

Language Criteria

How to evaluate the features of the various languages