skx / sysbox

sysadmin/scripting utilities, distributed as a single binary
GNU General Public License v2.0
218 stars 19 forks source link

Calculator should allow variables #5

Closed skx closed 4 years ago

skx commented 4 years ago

The calculator currently allows either:

The latter case should allow variables. Something like:

rent = 710
rent * 6  / 12

This does mean dropping the current go-based scanner/lexer/evaluator. But writing a calculator is a trivial thing, even with precedence and variables.

skx commented 4 years ago

I've hacked up a simple calculator which supports variables, albeit with a let x = prefix.

It handles +, -, *, /, with floating point, and appropriate precedence.

TODO: