Skip to content

A super simple arithmetic grammar parsing example with ANTLR4 rust target

License

Notifications You must be signed in to change notification settings

yunusemredilber/antlr_rust_language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ANTLR Rust Language (Arithmetic)

A super simple language grammar parsing example with ANTLR4 rust target.

It can be used to kicksart a rust based parsing project using ANTLR4.

Features

  • 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.

Demo

> 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)
            ),
          ),
        )
      ),
    )
  ],
),

Run Locally

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

Acknowledgements

  • Custom ANTLR4 build must to be used until the antlr-rust merge to the main antlr repo.

Author

About

A super simple arithmetic grammar parsing example with ANTLR4 rust target

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published