Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lxsmnsyc/arithmeticparserdemo

An Arithmetic Parser Demo using Recursive Descent in Lua
https://github.com/lxsmnsyc/arithmeticparserdemo

arithmetic arithmetic-computation arithmetic-expression arithmetic-expression-evaluator parser parsing recursive-descent recursive-descent-parser

Last synced: 15 days ago
JSON representation

An Arithmetic Parser Demo using Recursive Descent in Lua

Awesome Lists containing this project

README

        

# ArithmeticParserDemo
An Arithmetic Parser Demo using Recursive Descent in Lua

## Features
* Right-associative addition, subtraction, multiplication and addition.
* Left-associative exponentiation
* 'e' notation e.g 1e10
* Unary
* Parser error reporting (prints the position of the character error)

## Grammar
This is in ANTLR4 format:
```antlr
expr
: sum
;

sum
: prod (('+' | '-')? prod)*
;

prod
: pow (('*' | '/')? pow)*
;

pow
: value ('^' pow)*
;

value:
: digits
| ('(' expr ')')?
;

digits
: ('-')? [0-9]* (('.')? [0-9]*)? (('e' | 'E')? [0-9]*)?
;
```