administrivia n.
Skip this Video
Loading SlideShow in 5 Seconds..
Administrivia PowerPoint Presentation
Download Presentation
Administrivia

play fullscreen
1 / 36
Download Presentation

Administrivia - PowerPoint PPT Presentation

glenda
74 Views
Download Presentation

Administrivia

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

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

  2. 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 Some bytes

  3. Object oriented programming • Figure out characteristics of your data • objects • Figure out operations you will want to perform • Methods • Modern idea in programming.

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

  5. Methods • Method of querying color of light • Method of changing color of light • Method of scheduling a color change later • …

  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

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

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

  9. 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)

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

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

  12. Code fragment (lex’ed) DimlowAsInteger, highAsInteger DimfahrenheitAsDouble, celsiusAsDouble Forfahrenheit = lowtohigh celsius = 5 / 9 * (fahrenheit - 32) print fahrenheit , celsius Nextfahrenheit End Keywords, variables, constants, operators, functions, separators

  13. Code fragment (cont.) Dim<tag1>AsInteger, <tag2>AsInteger Dim<tag3>AsDouble, <tag4>AsDouble For<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 need how operations on them work

  14. 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> + 1 If <tag3> > <tag2> go back

  15. The unwound loop can be translated into machine language Store 32 in R3 Store 5/9 in R4 Store 1 in R5 Load <tag1> into R1 ***Store R1 into <tag3> Load <tag3> into R2 Subtract R3 from R2 and store in R2 Multiply R4 by R2 and store in R2 Store R2 in <tag4> Print R1,R2 Add R5 to R1 and store in R1 Store R5 in <tag3> Load <tag2> into R6 Subtract R6 from R5 and store in R5 Go back to *** if R6 > 0 <tag3> = <tag1> <tag4> = 5 / 9 * (<tag3> - 32) print <tag3> , <tag4> <tag3> = <tag3> + 1 If <tag3> > <tag2> go back

  16. Parsing • Language is defined by a grammar • Grammar is defined by production rules • Parsing is done by unwinding

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

  18. Simple rewriting rules • <number>  <sign> <digit><digits> . <digits> • <sign>  + | - • <digits>  <digit><digits> | <digit> | e • <digit>  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

  19. An example • <number>  <sign> <digit><digits> . <digits> • <sign>  + | - • <digits>  <digit><digits> | <digit> | e • <digit>  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <number>  <sign><digit><digits>.<digits>  <sign><digit><digit><digits>.<digits>  <sign><digit><digit>.<digits>  <sign><digit><digit>.<digit><digit>  … +98.65

  20. Simplifying the rules • <number>  <sign> <digit><digits> . <digits> • <sign>  + | - • <digits>  <digit><digits> | <digit> | e • <digit>  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 • <number>  <sign><digits>.<digits>| <sign><digits> • <sign>  +|- • <digits>  <digit><digits> | <digit> • <digit>  0|1|2|3|4|5|6|7|8|9

  21. 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?

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

  23. 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?

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

  25. 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,

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

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

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

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

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

  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.

  33. Everything has bugs • Bug lists

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

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

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