slowli / arithmetic-parser

Versatile parser for arithmetic expressions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flexible Arithmetic Parser and Interpreter

Build Status License: MIT OR Apache-2.0

This repository contains a versatile parser for arithmetic expressions which allows customizing literal definitions, type annotations and several other aspects of parsing. The repository also contains several auxiliary crates (for example, a simple interpreter).

Contents

Why?

  • The parser is designed to be reusable and customizable for simple scripting use cases. For example, it's used to dynamically define and process complex-valued functions in a Julia set renderer. Customization specifically extends to literals; e.g., it is possible to have a single numeric literal / primitive type.
  • Interpreter and type inference are natural complementary tools for the parser that allow evaluating parsed ASTs and reasoning about their correctness. Again, it is possible to fully customize primitive types and their mapping from literals, as well as semantics of arithmetic ops and (in case of typing) constraints they put on operands.
  • Type inference is a challenging (and therefore interesting!) problem given the requirements (being able to work without any explicit type annotations).

Project status 🚧

Early-stage; quite a bit of functionality is lacking, especially in interpreter and typing. As an example, method resolution is a mess (methods are just syntax sugar for functions).

Alternatives / similar tools

  • Scripting languages like Rhai and Gluon are significantly more mature and have a sizable standard library, but are less customizable. E.g., there is a pre-determined set of primitive types with unchangeable semantics and type constraints. Rhai also does not have parser / interpreter separation or type inference support, and Gluon's syntax is a bit academic at times.

Contributing

All contributions are welcome! See the contributing guide to help you get involved.

License

All code in this repository is licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

Versatile parser for arithmetic expressions

License:Apache License 2.0


Languages

Language:Rust 99.9%Language:JavaScript 0.1%Language:RPC 0.0%