A minimal C library for parsing, compiling, and evaluating mathematical expressions at runtime with no dependencies.
TinyExpr is a small, recursive descent parser and evaluation engine for mathematical expressions written in C. It allows developers to add runtime expression evaluation capabilities to their applications without introducing external dependencies or significant code bloat. The library handles standard operators, functions, and variable binding while maintaining a minimal footprint.
C developers who need to evaluate mathematical expressions dynamically in their applications, such as those building calculators, configuration systems, scripting interfaces, or scientific tools.
Developers choose TinyExpr for its extreme simplicity, zero dependencies, and ease of integration—it's just two files. It offers a balance of performance and flexibility, with thread safety and constant folding optimizations, making it ideal for embedded systems or lightweight projects where adding a full expression library is impractical.
tiny recursive descent expression parser, compiler, and evaluation engine for math expressions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Consists of only two C files (tinyexpr.c and tinyexpr.h), making integration trivial without external libraries or complex build systems.
Safe for concurrent use as long as malloc is thread-safe, enabling multi-threaded applications without additional locks.
Automatically prunes and pre-calculates constant subexpressions during compilation, improving runtime performance for expressions with fixed parts.
Exposes common C math functions like sin and sqrt, plus extras like factorial and combinations, covering most basic evaluation needs.
Benchmarks show significant slowdowns—up to 336% slower for basic arithmetic—compared to native C code, making it unsuitable for performance-critical loops.
Only provides parse error positions without detailed messages or recovery mechanisms, which can complicate debugging in complex expressions.
Cannot easily add new operators or modify precedence without editing the source code, limiting customization for advanced use cases.