Title: Administrivia
1Administrivia
- First pieces of assignment 5
- Comments about assignment 5
- Assignment 6
- Labs 5 and 6
2Some bytes
- 0000000 5089 474e 0a0d 0a1a 0000 0d00 4849 5244
- 0000020 0000 9001 0000 2c01 0208 0000 6200 72d5
- 0000040 0095 2000 4900 4144 7854 ccda 79fd 24d4
- 0000000 5089 474e 0a0d 0a1a 0000 0d00 4849 5244
- 0000020 0000 9001 0000 2c01 0208 0000 6200 72d5
- 0000040 0095 2000 4900 4144 7854 d4da 61fd 648c
3Object oriented programming
- Figure out characteristics of your data
- objects
- Figure out operations you will want to perform
- Methods
- Modern idea in programming.
4Objects
- Traffic light at intersection involves
- Lights in each direction
- Call them red, yellow and green and not 0,1,2
- Sensors in each direction
- Timing (rate of change in each direction)
- Timings neednt be the same
- Neighboring Lights
- May affect change as much as sensors
5Methods
- Method of querying color of light
- Method of changing color of light
- Method of scheduling a color change later
6What happens to the program?
- Compiled or interpreted
- Eventually it gets translated into machine
language - If compiled
- Can store executable and run again
- If interpreted
- Interpret each time it is executed
7What does the compiler do?
- Identifies variables (need space in RAM)
- Uses stores and loads to get values to registers
- Parses commands
- Turns each command into a string of machine
language commands - Sets things up for execution
8Steps in compilation
- Lexical analysis
- Identify all keywords
- Identify all operators
- Identify all variables
- Make everything into tokens
- Parsing
- Turn the tokens into operations
- Build a computation tree
- Code generation
- Generate machine code
9Lexical analysis
- Keywords
- If Then .. End If
- If .. Then .. Else End If
- Do While Loop
- Private sub .
- End sub
- Dim as Integer
- Operators
- (in 2 contexts)
- If (Light 0)
- Light 1
- - /
- - also in 2 contexts (unary or binary)
10Simple code fragment
- Sub print_ftoc(low As Integer, high As Integer)
- Dim fahrenheit As Double, celsius As Double
- For fahrenheit low to high
- celsius 5 / 9 (fahrenheit - 32)
- print fahrenheit, celsius
- Next fahrenheit
- End Sub
11Simplified code fragment
- Dim low As Integer, high As Integer
- Dim fahrenheit As Double, celsius As Double
- For fahrenheit low to high
- celsius 5 / 9 (fahrenheit - 32)
- print fahrenheit, celsius
- Next fahrenheit
- End
12Code fragment (lexed)
- Dim low As Integer, high As Integer
- Dim fahrenheit As Double, celsius As Double
- For fahrenheit low to high
- celsius 5 / 9 (fahrenheit - 32)
- print fahrenheit , celsius
- Next fahrenheit
- End
- Keywords, variables, constants, operators,
functions, separators
13Code fragment (cont.)
- Dim lttag1gt As Integer, lttag2gt As Integer
- Dim lttag3gt As Double, lttag4gt As Double
- For lttag3gt lttag1gt to lttag2gt
- lttag4gt 5 / 9 (lttag3gt - 32)
- print lttag3gt , lttag4gt
- Next lttag3gt
- End
- Replace variables by tags
- these are really locations in RAM
- How things are defined determines
- how much RAM they need
- how operations on them work
14Code fragment (cont.)
- For lttag3gt lttag1gt to lttag2gt
- lttag4gt 5 / 9 (lttag3gt - 32)
- print lttag3gt , lttag4gt
- Next lttag3gt
- The instructions in the loop must be unwound
- lttag3gt lttag1gt
- lttag4gt 5 / 9 (lttag3gt - 32)
- print lttag3gt , lttag4gt
- lttag3gt lttag3gt 1
- If lttag3gt gt lttag2gt go back
15The unwound loop can be translated into machine
language
Store 32 in R3 Store 5/9 in R4 Store 1 in R5 Load
lttag1gt into R1 Store R1 into lttag3gt Load
lttag3gt into R2 Subtract R3 from R2 and store in
R2 Multiply R4 by R2 and store in R2 Store R2 in
lttag4gt Print R1,R2 Add R5 to R1 and store in
R1 Store R5 in lttag3gt Load lttag2gt into
R6 Subtract R6 from R5 and store in R5 Go back to
if R6 gt 0
- lttag3gt lttag1gt
- lttag4gt 5 / 9 (lttag3gt - 32)
- print lttag3gt , lttag4gt
- lttag3gt lttag3gt 1
- If lttag3gt gt lttag2gt go back
16Parsing
- Language is defined by a grammar
- Grammar is defined by production rules
- Parsing is done by unwinding
17How do we specify a grammar?
- 2 aspects to a language
- Symbols
- Rewriting rules
- Simple language for generating numbers
- Symbols
- Non-terminals
- ltnumbergt, ltdigitsgt, ltsigngt, ltdigitgt
- Terminals
- - . 1 2 3 4 5 6 7 8 9
18Simple rewriting rules
- ltnumbergt ? ltsigngt ltdigitgtltdigitsgt . ltdigitsgt
- ltsigngt ? -
- ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt e
- ltdigitgt ? 0 1 2 3 4 5 6 7 8 9
19An example
- ltnumbergt ? ltsigngt ltdigitgtltdigitsgt . ltdigitsgt
- ltsigngt ? -
- ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt e
- ltdigitgt ? 0 1 2 3 4 5 6 7 8 9
- ltnumbergt ?
- ltsigngtltdigitgtltdigitsgt.ltdigitsgt ?
- ltsigngtltdigitgtltdigitgtltdigitsgt.ltdigitsgt ?
- ltsigngtltdigitgtltdigitgt.ltdigitsgt ?
- ltsigngtltdigitgtltdigitgt.ltdigitgtltdigitgt ?
-
- 98.65
20Simplifying the rules
- ltnumbergt ? ltsigngt ltdigitgtltdigitsgt . ltdigitsgt
- ltsigngt ? -
- ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt e
- ltdigitgt ? 0 1 2 3 4 5 6 7 8 9
- ltnumbergt ? ltsigngtltdigitsgt.ltdigitsgt
ltsigngtltdigitsgt - ltsigngt ? -
- ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt
- ltdigitgt ? 0123456789
21Parsing
- ltnumbergt ? ltsigngtltdigitsgt.ltdigitsgt
ltsigngtltdigitsgt - ltsigngt ? -
- ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt
- ltdigitgt ? 0123456789
- What rules were applied to get 123.45?
22What about real languages?
- The complete grammar for C
- around 400 lines long
- 58 tokens (based on keywords)
- 65 basic productions (each with many options)
- Only a few complex situations
23Programming language tradeoffs
- Branching vs. locality
- Should the program be in blocks or look like
spaghetti - Type declarations
- If you Dim something as an integer and then try
to make it hold a double, what should happen? - Verification
- How do you tell if your specification is right?
- How do you tell if your program meets your
specification?
24History of Programming Languages
- Fortran (1954) for scientific
- Cobol (1959) for business
- Algol (1958) more universal Fortran
- Lisp (1958) string/concept oriented
- APL (1960) formula oriented
25History of Programming Languages
- PL/1 (1964) from Algol Fortran
- Basic (1964) for everyone to use
- Simula (1967) combines with Algol to yield
Smalltalk (1969) object oriented - BCPL ? B ? C (1971)
- Algol ? Pascal (1971) ? Modula 1,2,3,
26History of Programming Languages
- C (1983) C with object oriented features
- Often C is still used
- Awk (1978) ? Perl (1987) report generators
- Web programming language
- Java (1991) object oriented and portable
- Web applets, devices
- Visual Basic(1991) macros and programs
- Core of Microsoft systems
27What makes a good language
- Does the task you want
- Keeps you from making mistakes
- Supports debugging when you need it
- Has a strong tool kit
28Big number bug
On June 4, 1996 an unmanned Ariane 5 rocket
launched by the European Space Agency exploded
just forty seconds after its lift-off from
Kourou, French Guiana. The rocket was on its
first voyage, after a decade of development
costing 7 billion. The destroyed rocket and its
cargo were valued at 500 million. A board of
inquiry investigated the causes of the explosion
and in two weeks issued a report. It turned out
that the cause of the failure was a software
error in the inertial reference system.
Specifically a 64 bit floating point number
relating to the horizontal velocity of the rocket
with respect to the platform was converted to a
16 bit signed integer. The number was larger than
32,768, the largest integer storeable in a 16 bit
signed integer, and thus the conversion failed.
29Pentium II bug
- Software bug encoded in hardware
- Division algorithm uses a lookup table of 1066
entries - Only 1061 of the entries are downloaded to the
PLA (programmed logic array from which the data
are used) -
- Intel had to recall all versions of the chip
30- NASA Mariner 1 , Venus probe (1992)
- Intended to be the first US spacecraft to visit
another planet, it was destroyed by a range
officer on 22 July 1962 when it behaved
erratically four minutes after launch. - The alleged missing hyphen' was really a missing
bar'. - (period instead of comma in FORTRAN DO-Loop)
31- ATT long distance service fails for nine
hours(Wrong BREAK statement in C-Code, 1990) - January 15, 1990
- 70 million of 138 million long distance customers
in the US lost long distance service. - Cost to ATT was between 75 Million and 100
Million (plus the loss of good will).
32- E-mail buffer overflow (1998)
- Several E-mail systems suffer from a "buffer
overflow error", when extremely long e-mail
addresses are received. The internal buffers
receiving the addresses do not check for length
and allow their buffers to overflow causing the
applications to crash. Hostile hackers use this
fault to trick the computer into running a
malicious program in its place.
33Everything has bugs
34Summary
- Programming is hard
- Have to thoroughly understand the task
- Have to anticipate all possibilities
- Code is written at a fairly primitive level
- Is impossible to anticipate what users might do
- Programming languages allow the user to use tools
to build things - The cost of a bug can be very large
- There is no Moores Law for software.
35Where are we
- Weve built a computer
- Weve looked at operating systems
- Weve looked at the network
- Weve built programs
- And looked under the hood
36Whats next
- One more piece of networking
- Sharing files, sharing cycles, distributed
computing - Algorithms
- Ideas of how to design processes
- Complexity theory
- Undecidable problems
- Unsolvable (in practice) problems
- Applications of hard problems
- Social impacts
- Digital rights management
- Artificial intelligence