1 / 26

Lecture 15 Semantic Analysis

Lecture 15 Semantic Analysis. KU | Fall 2019 | Drew Davidson. Announcements Lecture 15. P3 Code Out Tonight Lab 7 H6 posted a bit late Quiz 2 Review Session Review Session Sunday 5:00 – 7:00 Learned 1131 Pizza at 6:00. Live Assignments. H6. P3. Last Time Lecture 14 – Scope.

dmargie
Download Presentation

Lecture 15 Semantic Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 15 Semantic Analysis KU | Fall 2019 | Drew Davidson

  2. AnnouncementsLecture 15 P3 Code Out Tonight Lab 7 H6 posted a bit late Quiz 2 Review Session • Review Session Sunday • 5:00 – 7:00 • Learned 1131 • Pizza at 6:00 Live Assignments H6 P3

  3. Last TimeLecture 14 – Scope Semantics • Program meaning Scope • Name analysis Semantics

  4. Today’s OutlineLecture 15 – Semantic Analysis Error Checking • What counts as a bad program? • How do we detect bad programs? Limits of Analysis • The halting problem Semantics

  5. Error Checking Semantic Analysis Goal: save programmers from themselves • It’s not enough to compile the programmer’s code • Need to figure out what programmer meant to code

  6. Compiler As Mind ReaderSemantic Analysis

  7. A Compiler: Artist’s RenditionSemantic Analysis A grumpy old man that yells at you for breaking the rules

  8. Quick Audience PollLecture 15 – Semantic Analysis Does this C program compile? Should this C code compile? int a = 0; int main(){ if (false){ b = 6; } return a;}

  9. A Compiler’s Error-Checking ObligationLecture 15 – Semantic Analysis Understandability / Consistency

  10. The Compiler Before the CompilerSemantic Analysis

  11. Bug HuntingSemantic Analysis How do we prevent nonsense code from executing? • We’ll consider two ways of analysis: • Static • Dynamic Putting guardrails on computation

  12. Compiler PerspectiveStatic vs Dynamic Analysis Static • Code analysis without execution Dynamic • Code analysis through execution Checks done at compile time Analysis part of the compiler itself Checks done at run time Analysis embedded into the program

  13. Compiler Focus: Static AnalysisStatic vs Dynamic Analysis Doesn’t slow the program down • Ok to take longer • Ok to apply more heavyweight analysis Has a “holistic” view of the program • Has access to source code • Knowledge of non-executed program paths

  14. Limits of Error CheckingStatic Analysis We’d LOVE to ensure bug-free programs • Observe and report bugs before they are encountered Usually we can’t do this • Limits of static analysis

  15. Limits of Static AnalysisStatic Analysis Theoretical argument Practical argument

  16. The Halting ProblemStatic Analysis Does a computation ever terminate?

  17. Let’s Do Some VocabStatic Analysis Effective method: a procedure that is always yields a correct result on any input

  18. No Effective Method for HaltingStatic Analysis assume white_magic(Function p) returns true if p halts, false if p does not function black_magic(): if white_magic(black_magic): while true { }

  19. Ok, but that’s just Halting, right?Static Analysis

  20. Rice’s TheoremStatic Analysis - Limits of Error Checking “All non-trivial semantic properties of programs are undecidable”

  21. Rice’s Theorem - ImplicationsDetour – Limits of Error Checking • We’d like to perfectly capture all bugs • We can’t be right all of the time • We can choose HOW we are wrong

  22. Limits of Static AnalysisStatic Analysis Theoretical argument Practical argument

  23. Let’s do some Sciency-Sounding StuffEvaluation

  24. Evaluating a Bug DetectorEvaluation False True Positive Negative

  25. Soundness and CompletenessDetour – Limits of Error Checking All Programs All Programs Reported bugs Buggy Programs Buggy Programs Reported bugs Complete bug detection Sound bug detection

  26. Partial CorrectnessLimits of Error Checking • Make best-effort procedures that are neither sound nor complete • We can analyze the result of a statement under certain assumptions • Assume that the statement is executed • Assume that the statement actually completes

More Related