ch06 - Programming Languages 2nd edition Tucker and Noonan...

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

View Full Document Right Arrow Icon
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Types I was eventually persuaded of the need to design  programming notations so as to maximize the  number of errors which cannot be made, or if  made, can be reliably detected at compile time. C.A.R. Hoare
Background image of page 1

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

View Full DocumentRight Arrow Icon
Type Systems – Review Type Checking : the detection of type errors, either at compile time or at run time. Type error: attempt to perform an operation on a value from a data type for which it is not defined Type System : a precise definition of the bindings between a variable’s type, its values, and the possible operations on the values Describes how new types are defined and how to tell when a type is used correctly Recall that a language is strongly typed if its type system makes it possible to detect type errors either at compile time or run time. Type safety is similar to strong typing: use of a type system prevents some/most/all type errors.
Background image of page 2
Implementing a Type System Cannot be defined in BNF or EBNF notation Cannot represent context-sensitive constraints, e.g. uniqueness of an identifier within a given scope Other possible approaches: Write boolean functions to define each type rule Express the rules in English and give an algorithm to implement the rules
Background image of page 3

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

View Full DocumentRight Arrow Icon
Type System for Clite A set of validity functions define the various rules, such as “variables have unique names”. Each function returns a boolean value to tell whether a part of the program’s abstract syntax tree is type valid. The type checking system uses a type map: a function that binds a variable name to its type.
Background image of page 4
Type System for CLite Single function: main Single scope: no nesting, no globals Name resolution errors detected at compile time Static binding Each declared variable must have a unique identifier Identifier must not be a keyword (syntactically enforced) Each variable referenced must be declared Etc. Type rules test validity of different abstract
Background image of page 5

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

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

This note was uploaded on 04/21/2010 for the course CS 424 taught by Professor Weisskopf during the Spring '10 term at University of Alabama - Huntsville.

Page1 / 22

ch06 - Programming Languages 2nd edition Tucker and Noonan...

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

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