Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/lxsmnsyc/arithmeticparserdemo
- Owner: lxsmnsyc
- License: mit
- Created: 2019-02-19T23:06:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-20T00:07:21.000Z (almost 6 years ago)
- Last Synced: 2024-11-11T17:14:03.860Z (2 months ago)
- Topics: arithmetic, arithmetic-computation, arithmetic-expression, arithmetic-expression-evaluator, parser, parsing, recursive-descent, recursive-descent-parser
- Language: Lua
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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]*)?
;
```