expr_parser

Crates.ioexpr_parser
lib.rsexpr_parser
version0.0.1
sourcesrc
created_at2019-04-26 21:55:00.158162
updated_at2019-04-26 21:55:00.158162
descriptionA lexer and parser of simple arithmetic expressions.
homepage
repositoryhttps://github.com/DanielSchuette/expr_parser
max_upload_size
id130376
size31,494
Daniel Schuette (DanielSchuette)

documentation

README

Expression Parser in Rust

Overview

A simple program that takes expressions like 5 + 8 * (7-1) and parses them into a syntax tree. GRAMMAR.md explains the process in greater detail. A few things will be implemented like executing the syntax tree that lexer and parser create. This is really just an experiment to see how a context-free grammar-based parser might be implemented in Rust.

Run the Code

A Makefile makes running the code in this repository easy:

make
make test # runs the binary with appropriate parameters (especially `-e <expr>')
make err1 # demonstrates an error; `err2' and `err3' exist, too

But cargo can be used, too. E.g., install the binary from crates.io with:

cargo install expr_parser
expr_parser --help # validates a successful installation

Create an AST Graph

graphviz must be installed on your system. If you make and make test, .gv and .pdf files will be created in the project root. Refer to the Makefile or run make help for available parameters.

To-Do:

  1. execute AST via the vm's evaluate function
  2. add additional ops to the grammar, e.g. [], log2, log10
  3. test parser using QuickCheck or something similar
  4. allow for dynamic user input
  5. allow for variable assignment and re-use of those variables ($var syntax), using a stack machine

License

The code in this repository is MIT-licensed (see LICENSE.md).

Commit count: 23

cargo fmt