+ All Categories
Home > Documents > Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Date post: 22-Dec-2015
Category:
View: 218 times
Download: 3 times
Share this document with a friend
36
Administrivia First pieces of assignment 5 • Comments about assignment 5 • Assignment 6 • Labs 5 and 6
Transcript
Page 1: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Administrivia

• First pieces of assignment 5

• Comments about assignment 5

• Assignment 6

• Labs 5 and 6

Page 2: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Some 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

Page 3: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Object oriented programming

• Figure out characteristics of your data– objects

• Figure out operations you will want to perform – Methods

• Modern idea in programming.

Page 4: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Objects

• 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 needn’t be the same

– Neighboring Lights• May affect change as much as sensors

Page 5: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Methods

• Method of querying color of light

• Method of changing color of light

• Method of scheduling a color change later

• …

Page 6: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

What 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

Page 7: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

What 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

Page 8: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Steps 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

Page 9: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Lexical 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)

Page 10: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Simple 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

Page 11: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Simplified 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

Page 12: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Code fragment (lex’ed)

Dim low As Integer, high As IntegerDim fahrenheit As Double, celsius As DoubleFor fahrenheit = low to high

celsius = 5 / 9 * (fahrenheit - 32) print fahrenheit , celsius Next fahrenheit

End

Keywords, variables, constants, operators, functions, separators

Page 13: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Code fragment (cont.)

Dim <tag1> As Integer, <tag2> As IntegerDim <tag3> As Double, <tag4> As DoubleFor <tag3> = <tag1> to <tag2>

<tag4> = 5 / 9 * (<tag3> - 32) print <tag3> , <tag4> Next <tag3>

End

Replace variables by tags these are really locations in RAM

How things are defined determines how much RAM they needhow operations on them work

Page 14: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Code fragment (cont.)

For <tag3> = <tag1> to <tag2> <tag4> = 5 / 9 * (<tag3> - 32) print <tag3> , <tag4> Next <tag3>

The instructions in the loop must be unwound<tag3> = <tag1><tag4> = 5 / 9 * (<tag3> - 32) print <tag3> , <tag4> <tag3> = <tag3> + 1If <tag3> > <tag2> go back

Page 15: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

<tag3> = <tag1><tag4> = 5 / 9 * (<tag3> -

32) print <tag3> , <tag4> <tag3> = <tag3> + 1If <tag3> > <tag2> go back

The unwound loop can be translated into machine language

Store 32 in R3Store 5/9 in R4Store 1 in R5Load <tag1> into R1***Store R1 into <tag3>Load <tag3> into R2Subtract R3 from R2 and store in R2Multiply R4 by R2 and store in R2

Store R2 in <tag4>Print R1,R2Add R5 to R1 and store in R1Store R5 in <tag3>Load <tag2> into R6Subtract R6 from R5 and store in R5Go back to *** if R6 > 0

Page 16: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Parsing

• Language is defined by a grammar

• Grammar is defined by production rules

• Parsing is done by unwinding

Page 17: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

How do we specify a grammar?

• 2 aspects to a language– Symbols– Rewriting rules

• Simple language for generating numbers– Symbols

• Non-terminals– <number>, <digits>, <sign>, <digit>

• Terminals– + - . 1 2 3 4 5 6 7 8 9

Page 18: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Simple rewriting rules

• <number> <sign> <digit><digits> . <digits>• <sign> + | -• <digits> <digit><digits> | <digit> | • digit

Page 19: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

An example

• <number> <sign> <digit><digits> . <digits>• <sign> + | -• <digits> <digit><digits> | <digit> | • digit

<number> <sign><digit><digits>.<digits> <sign><digit><digit><digits>.<digits> <sign><digit><digit>.<digits> <sign><digit><digit>.<digit><digit> …+98.65

Page 20: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Simplifying the rules

• <number> <sign> <digit><digits> . <digits>• <sign> + | -• <digits> <digit><digits> | <digit> | • digit

• <number> <sign><digits>.<digits>| <sign><digits>

• <sign> +|-

• <digits> <digit><digits> | <digit>

• <digit> 0|1|2|3|4|5|6|7|8|9

Page 21: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Parsing

• <number> <sign><digits>.<digits>| <sign><digits>

• <sign> +|-

• <digits> <digit><digits> | <digit>

• <digit> 0|1|2|3|4|5|6|7|8|9

What rules were applied to get 123.45?

Page 22: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

What 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

Page 23: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Programming 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?

Page 24: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

History 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

Page 25: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

History 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,

Page 26: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

History 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

Page 27: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

What 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

Page 28: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Big 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.

Page 29: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Pentium 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

Page 30: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

• 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)

Page 31: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

• AT&T 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).

Page 32: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

• 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.

Page 34: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Summary

• 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 Moore’s Law for software.

Page 35: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

Where are we

• We’ve built a computer

• We’ve looked at operating systems

• We’ve looked at the network

• We’ve built programs– And looked under the hood

Page 36: Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.

What’s 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


Recommended