Crates.io | maschen |
lib.rs | maschen |
version | 0.2.1 |
source | src |
created_at | 2024-10-05 14:33:17.641434 |
updated_at | 2024-10-05 15:38:17.659479 |
description | A no-std compatible shunting yard implementation |
homepage | https://github.com/Eekle/maschen |
repository | https://github.com/Eekle/maschen |
max_upload_size | |
id | 1397787 |
size | 14,367 |
A shunting-yard implementation for transforming infix expressions to postfix. This crate only implements the algorithm, and does not evaluate expressions.
It is generic over the token type, so you can convert streams of whatever kinds of token you need.
It is also generic over the backing storage, so it is appropriate for use in no-alloc environments.
An embedded system may want to evaluate mathematical expressions provided at run-time by a user. For the user's convenience, you want to let them write infix expressions. However for computational convenience, you want to convert those to postfix to be run.
Once you have converted the input into tokens, maschen
can be used to do this conversion.
Then you will have an easily evaluated postfix token stream.
Since maschen
leaves the evaluation of the expression to the caller and doesn't care what the tokens actually are, they can be complex values such as handles to variables in your scripting language.
Implement maschen::Token
for your Token type. Then instantiate an instance of maschen::ShuntingYard
, and process()
each token in turn. Finally call finish()
to retrieve the output.
If you disable the std
feature, the ShuntingYard::new
method will be unavailable, and you will have to implement maschen::Stack
on some type to use it as the backing storage for the yard.
In an embedded environment, this will presumably be a static or stack-allocated array.