Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/drkwitht/expreval

Parse and evaluate arithmetic expressions.
https://github.com/drkwitht/expreval

cpp math-expression-evaluator recursive-descent-parser

Last synced: 5 days ago
JSON representation

Parse and evaluate arithmetic expressions.

Awesome Lists containing this project

README

        

# README: Math Expr Evaluator

### Brief:
An arithmetic expression evaluator written in C++. It uses a recursive descent parser & AST approach for basic syntax checking and later support for additional syntax if needed.

### Grammar:
```bnf
; Some tokens!
whitespace ::= (SP | TAB | CR | LF)+
number ::= (DIGIT | ".")+
operators ::= "+" | "-" | "*" | "/"

; Note: Start parsing from lower precedence and descend to tighter binding precedence rule if needed!
expr ::= term
term ::= factor (("+" | "-") factor)*
factor ::= power (("*" | "/") power)*
power ::= unary ("^" unary)*
unary ::= ?("-") number | "(" expr ")"
```

### Some extras:
- ~~I must add parenthesis support soon.~~ **DONE**
- ~~Add a REPL for expressions?~~ **DONE**
- Make error messages more detailed?