/plushcap/analysis/cloudflare/writing-complex-macros-in-rust-reverse-polish-notation

Writing complex macros in Rust: Reverse Polish Notation

What's this blog post about?

This text discusses the implementation of a macro in Rust for evaluating Reverse Polish Notation (RPN) expressions at compile-time. The author explains how to use recursive macros, token types, and various branches to handle different cases such as operators, numbers, and stack manipulation. Additionally, error handling is covered with the help of built-in Rust macros like `compile_error!`, `concat!`, and `stringify!`. The final macro can evaluate any RPN expression and provides meaningful error messages for common mistakes.

Company
Cloudflare

Date published
Jan. 31, 2018

Author(s)
Ingvar Stepanyan

Word count
2765

Language
English

Hacker News points
99


By Matt Makai. 2021-2024.