Types and Type Checking

Types and Type Checking - Semantic Analysis 1 Outline...

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

View Full Document Right Arrow Icon
1 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
2 Outline semantic analysis Type systems
Background image of page 2
3 What is the semantics of a program? Syntax  How a program looks like Textual representation or structure A precise mathematical definition is possible Semantics What is the meaning of a program Harder to give a mathematical definition
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Why do semantic checking? Make sure the program confirms to the programming  language definition Provide meaningful error messages to the user
Background image of page 4
5 Semantic Checking Static checks vs. Dynamic checks Static checks  Flow-of-control checks Uniqueness checks Type checks
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Flow of control checks Flow-control of the program is context sensitive  Examples: Declaration of a variable should be visible at use (in scope) Declaration of a variable should be before use Each exit path returns a value of the correct type 11
Background image of page 6
7 Uniqueness checks Use and misuse of identifiers Cannot represent in a CFG (same token) Examples: No identifier can be used for two different definitions in the  same scope 
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Type checks Most extensive semantic checks Examples: Number of arguments matches the number of formals and the corresponding  types are equivalent If called as an expression, should return a type Each access of a variable should match the declaration (arrays, structures  etc.) Identifiers in an expression should be “evaluatable” LHS of an assignment should be “assignable” In an expression all the types of variables, method return types and operators  should be “compatible” 15
Background image of page 8
9 Dynamic checks Array bounds check Null pointer dereference check 17
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Outline What is semantic analysis? Type systems
Background image of page 10
11 Type Systems A type system is used to for the type checking A type system incorporates syntactic constructs of the language notion of types rules for assigning types to language constructs
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/20/2010 for the course CS 101 taught by Professor Aga during the Spring '10 term at Jaypee University IT.

Page1 / 33

Types and Type Checking - Semantic Analysis 1 Outline...

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

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