Scoping and Type Checking

Outline

The Compiler Front-End

Beyond Syntax Errors

foo(int a, char *s){...}

int bar() {
  int f[3];
  int i, j, k;
  char q, *p;
  float k;
  foo(f[6], 10, j);
  break;
  i->val = 42;
  j = m + k;
  printf("%s,%s.\n",p,q);
  goto label42;
}

Beyond Syntax Errors (continued)

Why Have a Separate Semantic Analysis Phase?

What Does Semantic Analysis Do?

Scope

Static vs. Dynamic Scope

Static Scoping Example

Static vs. Dynamic Scope

Scope in Cool

Scope of Identifiers

Implementing the Most Closely Nested Rule

Implementing the Most Closely Nested Rule

Symbol Tables

Symbol Tables

Scope in Cool

Scope in Cool (Continued)

Scope in Cool (Continued)

Class Definitions

Types

Types and Operations

Type Systems

What Can Types do For Us?

Type Checking Overview

The Type Wars

Cool Types

Type Checking and Type Inference

Rules of Inference

Why Rules of Inference?

From English to an Inference Rule

Notation for Inference Rules

Example Rules

Example: 1 + 2

\[\frac{ \begin{array}{l} \vdash 1 : Int\\ \vdash 2 : Int \end{array}} {\vdash 1 + 2 : int}\text{[Add]}\]

Summary