education-2022/articles/compilers.md

3.0 KiB

Compilers: How To Make a Programming Language

Other compiler-related topics out of scope:

  • What are programs anyway (Forth, LISP)
  • Computation: Turing machines, lambda calculus
  • Compiler optimization
  • GC (motivated by LISP)

aesthetics:

  • stay motivated; stick close to a c-like, imperative, procedural model because that's what people are used to

motivation / goals / what questions are we trying to answer:

  • I want to be able to make a toy procedural language.
    • like C, Algol, JS, Lua, etc.
    • possible user motivations:
      • I want to make a game scripting language
      • I want to make a DSL for my job (and I want syntax highlighting!)
  • I want to do simple static analysis of my projects

ok what do we want to cover

  • classical compiler structure (lexer -> parser -> codegen)
  • semantic analysis / type checking
  • modern compiler structures (IR / SSA, optimization)
  • interpreters vs. JITs vs. AOTs vs. "transpilers"
  • executables and linkers
  • regular expressions?
  • regular languages / grammars / language structure / automata

the c compilation process

  • translation units
  • preprocessing -> (the whole compilation process) -> object files -> linking
  • c compilation model is not in favor any more, don't like compiling all these files separately
  • ABIs and FFI
  • should maybe be in separate article

experts / consultants:

  • Bill
  • NeGate

The actual progression

  • Simple expression interpreter (parse and evaluate)
  • Classical compiler construction (lex -> parse -> output), semantic analysis / type checking
    • motivation: complex structures! recursion! etc.
    • many of these resources exist and cover different aspects of the process in different ways
  • Grammars and language structure
  • Types of output (interpreter vs. AOT vs. JIT, etc.)
    • We can probably find resources on specific ones of these
  • Modern phases (IR / SSA)
    • Mention WASM?
  • The terrors of the real world
    • Executables, linkers, and debug info
    • The C ABI and FFI
    • Register allocation
  • C is not the only language
    • LISP
    • Forth
    • This could be a whole topic maybe