{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

080_Semantic_Analysis

080_Semantic_Analysis - Semantic Analysis Announcements...

Info icon This preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
Semantic Analysis
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Announcements Programming Project 2 due Wednesday at 11:59PM. Office hours every day until then. Ask on Piazzza! Email the course staff! Friendly reminder: Midterm next Wednesday, July 20 . Here, 11:00AM – 1:00PM Please let us know if you have any conflicts!
Image of page 2
Where We Are Syntax Analysis Lexical Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Source Code Machine Code
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Where We Are Semantic Analysis IR Generation IR Optimization Code Generation Optimization Source Code Machine Code Syntax-tic! Syntax Analysis Lexical Analysis
Image of page 4
Where We Are Lexical Analysis Semantic Analysis Syntax Analysis IR Generation IR Optimization Code Generation Optimization Source Code Machine Code
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Not Symantec Analysis
Image of page 6
Where We Are Program is lexically well-formed: Identifiers have valid names. Strings are properly terminated. No stray characters. Program is syntactically well-formed: Class declarations have the correct structure. Expressions are syntactically valid. Does this mean that the program is legal ?
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
A Short Decaf Program class MyClass implements MyInterface { string myInteger; void doSomething() { int[] x = new string; x[5] = myInteger * y; } void doSomething() { } int fibonacci(int n) { return doSomething() + fibonacci(n – 1); } }
Image of page 8
A Short Decaf Program class MyClass implements MyInterface { string myInteger; void doSomething() { int[] x = new string ; x[5] = myInteger * y ; } void doSomething() { } int fibonacci(int n) { return doSomething() + fibonacci(n – 1); } } Interface not declared Wrong type Variable not declared Can't multiply strings Can't redefine functions Can't add void No main function
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Semantic Analysis Ensure that the program has a well-defined meaning . Verify properties of the program that aren't caught during the earlier phases: Variables are declared before they're used. Expressions have the right types. Arrays can only be instantiated with NewArray . Classes don't inherit from nonexistent base classes Once we finish semantic analysis, we know that the user's input program is legal.
Image of page 10
Challenges in Semantic Analysis Reject the largest number of incorrect programs. Accept the largest number of correct programs.
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Validity versus Correctness int main() { string x; if (false) { x = 137; } }
Image of page 12
Validity versus Correctness int main() { string x; if (false) { x = 137; } } Safe; can't happen
Image of page 13

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Validity versus Correctness int Fibonacci(int n) { if (n <= 1) return 0; return Fibonacci(n – 1) + Fibonacci(n – 2); } int main() { Print(Fibonacci(40)); }
Image of page 14
Validity versus Correctness int Fibonacci(int n) { if (n <= 1) return 0; return Fibonacci(n – 1) + Fibonacci(n – 2); } int main() { Print(Fibonacci(40)); } Incorrect, should be “return n;”
Image of page 15

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Challenges in Semantic Analysis Reject the largest number of incorrect programs.
Image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern