Skip to main content

Section C.22 O1: Compiler Introduction (Syntax Analysis, Static Semantics)


  • Program is just a stream of characters

  • Lexer forms “words” (called tokens) from characters and can already detect lexical errors.

  • Parser checks if token stream adheres to concrete syntax. If yes, it builds the AST, if not, it reports errors.

  • However, not all syntactically correct programs are valid C programs.

  • They can violate static semantics: types don't match.

  • Analyzing static semantics (“semantic analysis”) can detect such errors and discard erroneous programs.

  • As a side effect, it elaborates types which we need later on for code generation.

  • Language is statically type-safe if well-typed programs don't get stuck.

  • Discuss examples of C programs that are well-typed but get stuck and discuss how Java solves these problems.

  • Introduce type system for C0 (Section 6.6): relation of a type environment, an expression, and its type.

  • Define typing rules inductively over the syntax.

Sections Covered.

Section 9.1, Section 6.6