Expand description
The Kaon
compiler pipeline.
This module contains the entire compilation process, including lexing, parsing, name resolution, typechecking and compiling into bytecode.
§The Compiler Pipeline
The following is a high level overview of how the compiler works.
§Lexing
To begin with, user defined source code is transformed into a stream
of tokens. This is done through Lexer::tokenize
. Any unrecongized tokens
are reported as syntax errors.
§Parsing
The parser generates an AST
(abstract-syntax tree), from the token stream created
by the lexer. Parsing is done with a recursive decent (top-down) parser.
Any syntax errors are handled at this point.
§Name Resolution
Names are resolved during this pass. The AST
is transversed top-down and
any names it encounters (type names, variable name, etc.) are resolved.
Duplicate names, undeclared variables, and other errors are reported during this pass.
§Typechecking
During this pass, the typechecker performs type inference and typechecking on the AST
.
§Code Generation
This phase of the pipeline handles the actual process of coverting the high-level AST
into
low-level bytecode, which resembles simplified machine code.
Re-exports§
pub use ast::ASTNode;
pub use ast::BinExpr;
pub use ast::Class;
pub use ast::Expr;
pub use ast::FunAccess;
pub use ast::Ident;
pub use ast::Op;
pub use ast::ScriptFun;
pub use ast::Stmt;
pub use ast::AST;
pub use ast::Constructor;
pub use ast::TypePath;
pub use codegen::Compiler;
pub use lexer::Lexer;
pub use parser::Parser;
pub use pass::Pass;
pub use resolve::Resolver;
pub use resolve::Scope;
pub use resolve::ScopedMap;
pub use resolve::Symbol;
pub use token::Token;
pub use token::TokenType;
pub use typecheck::Type;
pub use typecheck::TypeChecker;