












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!













A^
2 : int ⊥
A^
3 : int ⊥
A^
b : bool ⊥ A^
!b : bool ⊥
A^
2 + 3 : int ⊥
A^
x : int ⊥
b : bool, x : int
⊥if (!b) 2 + 3 else x : int
id : T
(variable-assign)
id = E : T ⊥ A
E2 : int A^
⊥ E1 : array[T] A^
(array-assign)
Show the inference rule for a while statement, while (E) S
2.^
Show the inference rule for a variable declaration with initializer, Type id = E
3.^
Show the inference rule for a question mark/colon operator, E1? S1 : S
⊥ ⊥(S2; .... ; Sn) : Tn
(sequence)
⊥(S1; S2; .... ; Sn) : Tn
» E(E1, ..., En)
E : T1 x T2 x ... Tn
Tr
Ei : Ti
(i^ ∈
1 ... n)
(function-call)
⊥E(E1, ..., En) : Tr
y^ Tr fun (T1 a1, ..., Tn an) {return E;}
y^ f: int
Æ^
int, g: int
Æ^
int
y^ when checking both f and g
» Scan top level of AST picking up all function signaturesand creating an environment binding all global identifiers » Type-check each function individually using this globalenvironment
Add a special entry {return_fun : T} when westart checking the function “fun”, look up thisentry when we hit a return statement Y To check Tr fun (T1 a1, ... , Tn an) { S } inenvironment A, need to check:^ A, a1 : T1, ..., an : Tn, return_fun : Tr
⊥A : Tr
A^
E : T
return_fun : T
∈^ A
A^
return E : unit
⊥
(return)
are always encosed by a while (or for) stmt » Java: must verify that a break X statement isenclosed by a for loop with label X » Goto labels exist in the proper function » Can easily check control-flow errors byrecursively traversing the AST
regular expressions
Lexical Analysis
token stream
grammars
Syntax Analysis
abstract syntax
tree
static semantics
Semantic Analysis
abstract syntax^ tree + symbol^ tables, types
Intermediate Code Gen Intermediate code