A simple mathematical expression parser written in C++ with no external dependencies whatsoever.
yig/miniparser
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
master
Could not load branches
Nothing to show
Could not load tags
Nothing to show
{{ refName }}
default
Code
-
Clone
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more.
- Open with GitHub Desktop
- Download ZIP
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Author: Yotam Gingold <yotam (strudel) yotamgingold.com> License: Public Domain. (I, Yotam Gingold, the author, release this code into the public domain.) Homepage: http://yotamgingold.com/code/ GitHub: https://github.com/yig/miniparser MiniParser: A simple C++ expression parser with no external dependencies whatsoever that can - generate a parse tree from an expression - parentheses - constants - symbolic variables - binary operators: - add: + - subtract: - - multiply: * - divide: / - modulus: % - exponent: ^, ** - unary operators: - negate: - - functions: - sin() - cos() - log() (base 10) - ln() (base e) - exp() - sqrt() - constants (override any variable with the same name): - PI = 3.14... NOTE: Order-of-operations is entirely left-associative. There is no operator precedence. Use parentheses everywhere! TODO: Operator precedence can be added easily with several lines of find/replace in the function "Node* Parse( const std::string& str );" See http://en.wikipedia.org/wiki/Operator-precedence_parser#Alternatives_to_Dijkstra.27s_Algorithm example: An example command line application that demonstrates a class with a predefined expression evaluated via operator() as well as an expression with an arbitrary number of variables. Can be called with two values (x,y) or with an expression followed by an arbitrary number of values assigned to the letters of the alphabet (a, b, c, ...). Version History: - 2006-04-08: initial release - 2006-12-09: added math functions (sin, cos, log, ln, exp, sqrt) and constants (PI) improved error handling (removed an infinite loop) - 2007-04-23: made the grammar left associative to match natural arithmetic and C - 2007-09-20: added the modulus operator %. attempted to add order-of-operations, but was foiled by unary minus (e.g. -a).
About
A simple mathematical expression parser written in C++ with no external dependencies whatsoever.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published