Crates.io | scicalc-rs |
lib.rs | scicalc-rs |
version | 0.2.0 |
source | src |
created_at | 2021-01-08 02:24:30.158041 |
updated_at | 2021-05-15 21:30:09.083882 |
description | Crate for parsing and doing calculations with measurements, typically used in scientific contexts. |
homepage | |
repository | https://github.com/vini-fda/scicalc-rs |
max_upload_size | |
id | 334107 |
size | 42,845 |
Rust crate for parsing and doing calculations with measurements, typically used in scientific contexts.
Transform a string(i.e. the input as a sequence of characters) into a sequence of tokens, which can then be fed into the parser.
Read a sequence of tokens — which has a linear structure — and transform it into a tree structure.
Read the tree structure of the expression and fold it, reducing it into it's final value.
don't panic!
Instead of panic!
ing, it'd better if the evaluator and the parser returned a Result<...>
Parse and perform basic operations with measurements (DONE)
(23.0 ± 0.1) + (1.5 ± 0.5)
Add support for:
Exponentiation
Logarithms
Add support for squareroots, n-th roots and many other functions
(23.0E+7 ± 1.0E6)
, (2.00 ± 0.01)E-10
and 2.00*10^9
Add support for numeric constants with no uncertainty, such as 42
, e
, π
, etc
e
π
Add support for the plus-minus digraph('+-' for ±
)
Expression ::= Value | UnaryExpression | BinaryExpression | Grouping
Grouping ::= "(" Expression ")"
Value ::= Constant | Number | Measurement
Measurement ::= Number "±" PosNumber
Number ::= PosNumber | UnaryMinus PosNumber
PosNumber ::= (\d+)(\.\d+)?|(\.\d+)
Constant ::= "e" | "π"
BinaryExpression ::= Expression BinaryOperator Expression
UnaryExpression ::= UnaryOperator Expression
BinaryOperator ::= "+" | "-" | "*" | "/" | "^"
UnaryOperator ::= UnaryMinus
UnaryMinus ::= "-"
Note: As observed by Pratt's paper on "Top Down Operator Precedence", a Backus-Naur Form(for which BNF is a shorthand) is very inept at capturing the precedence of infix operators. Even then, I still think that specifying a grammar with BNF is useful for providing a quick-and-easy guide, with which you can see the recursive structure of the language at a glance.
These are some resources that I used to learn about programming language theory, algorithms and their implementations:
Brief introduction to recursive descent parsing, by Ryan Flannery
Crafting Interpreters, by Bob Nystrom
Pratt parsing and precedence climbing are the same algorithm, by Oilshell
Programming Language Theory, a huge list of resources about PLT maintained by Steven Shaw
Simple but powerful Pratt parsing, by Aleksey Kladov(matklad)