



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































Nate Clark
(many slides from Bodik and August)
i i
th
i t
ti
store the program in memory!
stored-program
electronic digital computer (by Maurice Wilkes)
to be spent in finding errors in ... programs”
f^
construct
it was assembler nearly as we know it, called AutoCode
-^
a loop example, in MIPS, a modern-day assembly code:
p
p
,^
,^
y
y
loop: addi $t3, $t0, -
addi $t4, $t0, -4l
$ 1
h
($ 3)
# G
h^
l
lw $t1, theArray($t3)
# Gets the last
lw $t2, theArray($t4)
#^
two elements
add $t5, $t1, $t
# Adds them together...
sw $t5, theArray($t0)
# ...and stores result
$
,^
y($
)
#
addi $t0, $t0, 4
# Moves to next "element“# of theArray
blt $t0, 160, loop
# If not past the end of
j
$
# th A
t
jr $ra
# theArray, repeat
An interpreter for a high level language
assemblyassembly
bi
i^
t^
bl
7
A good language protects against bugs, but lessons take a while.
-^
An example that cause a failure of a NASA planetary probe:
buggy line:
DO 15 I = 1.
what was intended (a dot had replaced the comma):what was intended (a dot had replaced the comma):
DO 15 I = 1,
because Fortran ignores spaces, compiler read this as:
DO15I = 1 100DO15I
which is an assignment into a variable DO15I, not a loop.
-^
This mistake is harder (if at all possible) to make with the modern
(^
p
)
lexical rules (white space not ignored) and loop syntax
for (i=1; i < 100; i++) { … }
The need to express that more than one objectsupports draw() :^ draw(2DElement p) {
switch (p.type) {
SQUARE: … // draw a squareSQUARE: … // draw a square
break;
CIRCLE: … // draw a circle
break;
} }
-^
Problem:^ – unrelated code (drawing of SQUARE and CIRCLE)
mixed in same procedure;
p
;
Solution:^ – Object-oriented programming with inheritance
class Circle extends 2DElement {
void draw() {
p.draw()
which means hiding often repeated code
fragments
new language constructs hide more of theselow-level details.
Be the wizard not the typist
Source Code
LanguagePreprocessor
Trivial errors
Processing of#include, #defines#ifdef etc#ifdef, etc
Preprocessed source code (foo.i)
Lexical AnalysisSyntax AnalysisSemantic Analysis
Errors
AbstractSyntax Tree
Note: gcc –E foo.c –o foo.ito invoke just thepreprocessorp^
p
Preprocessed source
if (b == 0) a = b;
Preprocessed sourcecode, read char by char
Lexical Analysis or Scanner
if^
(^
b^
==
0
)^
a^
=^
b^
;
L^
i^
l^
l^
i
Lexical analysis