tinyexpr-rs
A safe, idiomatic Rust port of the original TinyExpr mathematical expression parser and evaluator.
Built as part of Code Resurrection 2026, this project preserves the grammar and behavior of the original C implementation while redesigning the internals to leverage Rust's ownership model, type system, and modern error handling.
Overview
TinyExpr is a lightweight recursive-descent parser capable of parsing and evaluating mathematical expressions such as
2 + 3 * 4
sqrt(16)
pow(2, 10)
sin(pi / 2)
fac(5)
ncr(5,2)
This project reimplements TinyExpr in Rust while preserving the original parser grammar and evaluation semantics wherever practical.
Unlike a direct line-by-line translation, the implementation embraces idiomatic Rust design using enums, pattern matching, ownership, and Result-based error handling.
Features
- Recursive-descent parser
- Expression evaluation
- Constant folding optimization
- Built-in mathematical functions
- Variables
- Built-in constants (
pi,e) - Comprehensive unit and integration tests
- Smoke test suite based on the original TinyExpr tests
- …