Skip to content

Instantly share code, notes, and snippets.

View thibault-cne's full-sized avatar
🦀
Focusing

Thibault C. thibault-cne

🦀
Focusing
View GitHub Profile
@thibault-cne
thibault-cne / reverse_polish_notation.rs
Last active March 19, 2024 23:39
introduction_to_rust_declarative_macros
macro_rules! rpn {
{ @inner_op stack [$r:expr, $l:expr $(, $stack:expr)*]; $op:tt $($tt:tt)* } => {
rpn! { @inner stack [$l $op $r $(, $stack)*]; $($tt)* }
};
{ @inner stack [$res:expr]; } => { $res };
{ @inner stack $stack:tt; + $($tt:tt)* } => {
rpn!{ @inner_op stack $stack; + $($tt)* }
};
{ @inner stack $stack:tt; - $($tt:tt)* } => {
rpn!{ @inner_op stack $stack; - $($tt)* }