Loading the code workspace…
Implement a type checker for your C subset.
Define a type system:
Type enum: TYPE_INT, TYPE_CHAR, TYPE_VOID, TYPE_FLOAT, TYPE_ERRORImplement type checking functions:
check_expression(ASTNode*): Returns the type of an expressioncheck_statement(ASTNode*): Verifies statement type correctnesscheck_function(ASTNode*): Verifies function type correctnessType rules to enforce:
Error reporting:
TYPE_ERROR for invalid expressionsint x = "hello"; (type mismatch)int foo(int x) { return "bad"; }int x = 5; float y = x; (implicit promotion)The type checker is the compiler phase users argue with daily: TypeScript's entire value proposition and Rust's borrow checker both sit on this foundation. Clang's Sema is its largest component — bigger than codegen — because sound type checking against a real language is where most compiler engineering effort goes.