

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















Æ^ Please send Simon/I mail with names y^ Persons can work individually if really want to » No extensions on deadline due to Exam, so getstarted!
Catching Semantic Errors int x; void f(int m) {^ float x, y;^ ...^ {int i, j; x=1; }^ {int x; l:
i=2 ; } } int g(int n) {^ char t;^ x=3; }
x^ var^ int f^ func^ int^ Æ^ void g^ func^ int^ Æ^ int
m^ arg^ int x^ var^ float y^ var^ float
n^ arg^ int t^ var^ char
i^ var^ int j^ var^
x int var
int l^ label Global symtab
Error! undefinedvariable
Symbol Table Operations^ ^ Two operations:^ » To build symbol tables, we need to insert new
Back to Type Checking^ ^ What are types?^ » They describe the values computed during the
How to Ensure Type-Safety^ ^ Bind (assign) types, then check types^ ^ Type binding: defines type of constructs inthe program (e.g., variables, functions)^ » Can be either explicit (int x) or implicit (x=1)^ » Type consistency (safety) = correctness with
4 Concepts Related to Types/Languages^ 1.^ Static vs dynamic checking^ »^
Static vs Dynamic Checking^ ^ Static type checking^ » Perform at compile time^ ^ Dynamic type checking^ » Perform at run time (as the program executes)^ ^ Examples of dynamic checking^ » Array bounds checking^ » Null pointer dereferences
Strong vs Weak Typing^ ^ Refer to how much type consistency isenforced^ ^ Strongly typed languages^ » Guarantee accepted programs are type-safe^ ^ Weakly typed languages^ » Allow programs which contain type errors^ ^ These concepts refer to run-time^ » Can achieve strong typing using either static
Soundness^ ^ Sound type systems: can statically ensurethat the program is type-safe^ ^ Soundness implies strong typing^ ^ Static type safety requires a conservativeapproximation of the values that may occurduring all possible executions^ » May reject type-safe programs^ » Need to be expressive: reject as few type-safe
Why Static Checking?^ ^ Efficient code^ » Dynamic checks slow down the program^ ^ Guarantees that all executions will be safe^ » Dynamic checking gives safety guarantees
Type Systems^ ^ What are types?^ » They describe the values computed during the
Type Comparison^ ^ Option 1: Implement a method T1.Equals(T2)^ » Must compare type trees of T1 and T2^ » For object-oriented languages: also need sub-typing,
Creating Type Objects^ ^ Build types while parsing – use a syntax-directed definitionnon terminal Type typetype : INTEGER^ ^ Type objects = AST nodes for typeexpressions
{$$ = new IntType(id); }| ARRAY LBRACKET type RBRACKET{$$ = new ArrayType($3); } ;