Saltar al contenido ForoHackers

Compilers: start here

Compiladores
#531 · Ophuscado · · Denunciar

A compiler translates a program from one language into another, usually from source code into machine code or an intermediate form. It checks the program on the way and rewrites it to run faster. Knowing how one works explains error messages, optimisation, linking and why the same code can behave differently across tools.

Key concepts

  • Front end: lexing turns text into tokens, parsing builds a syntax tree, and semantic analysis resolves names and checks types.
  • Intermediate representation: a simpler form of the program, such as SSA, on which analyses and optimisations run.
  • Optimisation: constant folding, inlining, dead-code elimination, loop transformations, each safe only if it preserves meaning.
  • Back end: instruction selection, register allocation and scheduling for a target machine.
  • Linking and loading: object files, symbols and relocation join pieces into one program.

Vocabulary

  • AST: abstract syntax tree, the program as a tree without the punctuation.
  • SSA: static single assignment, where each variable is assigned exactly once.
  • Parser generator: a tool that builds a parser from a grammar; recursive descent is the hand-written alternative.
  • Cross-compiler: a compiler that runs on one machine and produces code for another.

What to study, in order

  1. Write a lexer and a recursive-descent parser for arithmetic expressions.
  2. Add variables, functions and a type checker; report errors with line and column.
  3. Generate code for a stack machine, then for real assembly of one architecture.
  4. Add an intermediate representation and two optimisations; check that outputs stay equal.
  5. Read the output of a production compiler at several optimisation levels, and study the open source ones through their documentation.

Related tags

#interpreters #language-design #assembly #toolchains

Inicia sesión o únete para responder.