toy-language
A small, dependency-free Rust interpreter for a deliberately compact language. It includes a lexer, recursive-descent/Pratt parser, AST, and tree-walking evaluator. Errors identify their source line and column.
Run
mise run install
mise run run # runs examples/hello.toy
mise run run -- examples/hello.toy
cargo run --locked -- path/to/file.toy
The executable accepts one optional source-file path. With no path it runs the sample program. Interpreter output goes to stdout; diagnostics go to stderr.
Syntax
// Comments run to the end of a line.
let answer = 6 * 7;
print answer;
if (answer == 42) {
print true;
} else {
print false;
}
The language has signed 64-bit integer and boolean literals (true, false),
immutable let bindings, print, expression statements, and if/else
blocks. Identifiers use ASCII letters, digits, and underscores, and cannot
start with a digit. Blocks create local scopes. Statements end in semicolons
except block statements. There are no implicit conversions. Assignment, loops,
functions, strings, and collections are outside this MVP.
Operators, from highest to lowest precedence: unary ! and -; *, /,
%; +, -; <, <=, >, >=; ==, !=; &&; ||. Parentheses group
expressions. Arithmetic is checked: overflow and division/remainder by zero
are runtime errors. && and || short-circuit. Equality compares values of
the same type; ordering and arithmetic require integers; conditions require
booleans. Integer literals must fit in the positive i64 range; consequently,
the minimum signed value cannot currently be written as a literal.
Development
Rust 1.98.1 is pinned in mise.toml; the crate has no external dependencies.
mise run check runs tests and Clippy across all targets with all and
pedantic warnings denied. Cargo.lock is committed and Cargo commands use
--locked.