#scientific #calculator #parser #expression

nightly bin+lib rsc

A pure-Rust handwritten scientific calculator for solving math equations in strings

10 releases (4 stable)

✓ Uses Rust 2018 edition

1.2.0 Jan 1, 2019
1.1.1 Dec 11, 2018
1.0.0 Sep 9, 2018
0.1.7 Sep 8, 2018
0.1.5 Aug 28, 2018

#97 in Parsing tools

Download history 8/week @ 2018-10-22 1/week @ 2018-10-29 62/week @ 2018-11-05 28/week @ 2018-11-12 21/week @ 2018-11-19 14/week @ 2018-11-26 28/week @ 2018-12-03 15/week @ 2018-12-10 33/week @ 2018-12-17 22/week @ 2018-12-24 9/week @ 2018-12-31 16/week @ 2019-01-07 17/week @ 2019-01-14

104 downloads per month

MIT license

465 lines

RSC is a handwritten scientific calculator for turning an equation inside a string into a result. RSC is designed to be very lightweight and have as few dependencies as possible. It has the goal of just doing a single thing really well, and enabling anyone to extend it with more features.

RSC is also designed with the goal to not become bloated software. RSC will not receive frequent updates, but that does not mean it is old or unmaintained. That being said, RSC may still receive internal updates with relation to speed or resource usage.

Obtaining RSC

If you would like to install RSC as a program onto your computer, there is information here.


RSC is ~500 lines of Rust code.


RSC computes next to instantaneously, even with debug builds. The following output is the time (in nanoseconds) the different operations take to process sqrt((6.1--2.22)^2 + (-24-10.5)^2), where "bench_eval" is all of them at once. More info at lib.rs.

PS C:\Users\Luke\Documents\Projects\rsc> cargo bench
    Finished release [optimized] target(s) in 0.02s
     Running target\release\deps\rsc-74a7d2c06ab98eee.exe

running 4 tests
test tests::bench_compute  ... bench:         231 ns/iter (+/- 10)
test tests::bench_eval     ... bench:       6,272 ns/iter (+/- 504)
test tests::bench_parse    ... bench:       1,624 ns/iter (+/- 133)
test tests::bench_tokenize ... bench:       4,302 ns/iter (+/- 1,462)


RSC will not have any major changes to its syntax. It will remain to be consistent for a long time. It is up to forkers to make different tastes of RSC. It will also forever keep the same open-source permissions.


RSC is MIT licensed. RSC will always remain free to modify and use without attribution.



Using RSC as the actual program provides a simple interface for solving expressions. A right arrow shows where the user can input an expression, and upon pressing the Return key, the result of the entered expression is displayed on the next line.

PS C:\Users\Luke> rsc
>a = 2
Compute error: UnrecognizedIdentifier("b")
>(b = a^2) + 3
>sqrt((6.1--2.22)^2 + (-24-10.5)^2)
>abs -3


RSC is very painless to use. For simple, one-off expression solving:

extern crate rsc;

use rsc::eval;

fn main() {
    assert!(eval("5^2").unwrap() == 25.0);
    assert!(eval("x = 5").unwrap() == 5.0);
    assert!(eval("x").is_err()); // Previously assigned variables are discarded

In order to keep variables, you must create a Computer instance:

extern crate rsc;

use rsc::computer::Computer;

fn main() {
    let mut c = Computer::new();

    assert!(c.eval("x = 5").unwrap() == 5.0);
    assert!(c.eval("x^2").unwrap() == 25.0);


RSC can be run with the ast flag and show the internal expression that was created by the parser. This is most commonly used for entertainment purposes 😛.

PS C:\Users\Luke> rsc ast
>(a = 2)^3


PS C:\Users\lukew> rsc
Lexer error: InvalidIdentifier("oops")
Lexer error: InvalidNumber("3.3.1")
Parser error: ExpectedFactor(None)
Parser error: ExpectedClosingParenthesis
Parser error: UnexpectedNumber(Identifier("b"))
Compute error: UnrecognizedIdentifier("b")

Related Projects

  • rscplot: A graphing calculator dependent on RSC for solving expressions.

No runtime deps