Jump to content

yaci

From Hugo's wiki

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 <math.h>
>> 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.

Building

Install readline and libffi development packages, then:

$ make
$ make test

It is also available through the pm user repository.

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