CSCI 431 Lecture Notes - Implementation and Binding

Computer Language Levels

How do we describe a programming language?

How do we implement a programming language?

A language implementation provides a couple of very standard capabilities:

Implementation Methods

In theory it is possible to construct a hardware computer to execute directly programs 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

The structure of a translator.

Identifiers and Binding

More about Bindings

Environments