080_Semantic_Analysis

080_Semantic_Analysi - Semantic Analysis Announcements Programming Project 2 due Wednesday at 11:59PM Ask on Piazzza Office hours every day until

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

View Full Document Right Arrow Icon
Semantic Analysis
Background image of page 1

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

View Full DocumentRight 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!
Background image of page 2
Where We Are Syntax Analysis Lexical Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Source Code Machine Code
Background image of page 3

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

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

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

View Full DocumentRight Arrow Icon
Not Symantec Analysis
Background 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 ?
Background image of page 7

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

View Full DocumentRight 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); } }
Background 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
Background image of page 9

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

View Full DocumentRight 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.
Background image of page 10
Challenges in Semantic Analysis Reject the largest number of incorrect programs. Accept the largest number of correct programs.
Background image of page 11

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

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

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

View Full DocumentRight 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)); }
Background 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;”
Background image of page 15

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

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

This document was uploaded on 07/18/2011.

Page1 / 212

080_Semantic_Analysi - Semantic Analysis Announcements Programming Project 2 due Wednesday at 11:59PM Ask on Piazzza Office hours every day until

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online