~mna/snow unlisted

snow/doc/compiler.md -rw-r--r-- 1.6 KiB
424066c5Martin Angers doc: v0.0.5 1 year, 4 months ago


The current compiler is written in Go and found in the pkg folder. Source files are compiled in a sequence of stages, each helping get to the backend form (currently, only Go source code) that can be built to machine code and executed.


The various stages are:

  • Scanner, which generates a stream of tokens (pkg/scanner and pkg/token)
  • Parser, which generates an abstract syntax tree (AST, pkg/parser and pkg/ast)
  • Type checking, name resolution and other semantic checks, which generates a richer, annotated syntax tree (pkg/typecheck)
  • Code generation for the backend target (currently, only Go, pkg/codegen)

For testing and debugging purposes, the pkg/printer package supports pretty- printing of the AST. The grammar is documented in EBNF form in pkg/grammar.

Once the backend code is generated, the final build step is offloaded to the backend-specific compiler or assembler (currently, the go compiler).

Useful references:

And the online playgrounds for quick checks:


The snowc command supports commands that mirror the stages listed above. The command can be built by executing scripts/release.sh; the resulting binary will be in bin.

See snowc --help for usage details.