A super simple language grammar parsing example with ANTLR4 rust target.
It can be used to kicksart a rust based parsing project using ANTLR4.
- A simple arithmetic grammar written in ANTLR4.
- Building it's ANTLR entites in rust by using antlr-rust.
- Using the generated code to obtain parse tree.
- Visitor implementation to create a basic AST.
> Write something like '(3+4)*2' to see the generated AST. ^C to exit:
> 23 * (22 + -3)
Prog(
[
Stat(
BinaryExpr(
"*",
NumberLiteral(23.0),
ParenthesizedExpr(
BinaryExpr(
"+",
NumberLiteral(22.0),
Negative(
NumberLiteral(3.0)
),
),
)
),
)
],
),
Go to the project directory:
cd antlr_rust_arithmetic
Download the latest custom ANTLR4 build for rust:
curl -OL https://github.com/rrevenantt/antlr4rust/releases/download/antlr4-4.8-2-Rust0.3.0-beta/antlr4-4.8-2-SNAPSHOT-complete.jar
Build and run the application:
cargo run
- Custom ANTLR4 build must to be used until the antlr-rust merge to the main antlr repo.