--- title: yaci related: - "[flag.h](flag.h.md)" - "[lang](lang.md)" categories: - Tools and applications - Languages and compilers --- **yaci** (Yet Another Calculator Interpreter) is an interactive interpreter for mathematical and text expressions. It reads expressions, evaluates them and prints the result. It can also run script files and call functions from compiled C libraries through an FFI. ``` >> 2 + 3 =5 >> radio = 5 =5 >> pi * radio ^ 2 =78.5398 ``` ## Features - Numbers (doubles, `INF`, `NAN`), character literals (`'A'` is `65`), strings, lists (`{1, 2, 3}`) and booleans (`true`, `on`, `yes`...). - Built-in constants (`pi`, `e`, `sqrt2`, `ln2`...), variables and read-only constants (`const G = 9.8`). - `+ - * / ^`, with aliases like `plus`, `minus` and `let x be 5`. - Casts with `as`: `"12.5" as num`, `3.14 as str`, `42 as list`. - Assertions: `1 + 1 eq! 2` exits with an error if the values differ. - Silence output with `;`, `shh!` or `, but be quiet`. - **FFI:** load a shared library and call it: ``` >> open >> sqrt(2) >> strcspn("abc", "b") -> int >> InitWindow(800 as int, 450 as int, "title") ``` - A readline REPL with vi mode, history and completion; script files (`.yc`) and `load` at runtime, with circular-load detection. Built with flex, bison, GNU readline, libffi and [flag.h](flag.h.md). ## Building Install readline and libffi development packages, then: ``` $ make $ make test ``` It is also available through the [pm user repository](pm-user-repository.md). ## Usage ``` $ ./yaci # interactive REPL $ ./yaci script.yc # run a script, then enter the REPL $ ./yaci script.yc --norepl # run a script only $ ./yaci --verbose # hints on errors ``` ## See also - [Source code](https://github.com/hugoocoto/yaci) - [User manual](https://github.com/hugoocoto/yaci/blob/main/docs/yaci-es.pdf) (Spanish)