String Evaluate in C++
String Evaluate
Use C++ to evaluate a string. Support complex numbers, function names and variables.
GitHub Repo
https://github.com/Teddy-van-Jerry/String_Evaluate
Do not forget to STAR and FORK!
Clone Command:
git clone https://github.com/Teddy-van-Jerry/String_Evaluate.git
Call the evaluation function
string msg;
// eval with variables 'x' and 'y'
cout << eval("log(-2) * i + 2 $x ^ ($y - 1)", { "x", "y" }, { { 1, 2 }, { 3, 4 } }, &msg) << endl;
cout << eval("$x + $y", { "x", "y" }, { { 1, 2 }, { 2, 3 } }) << endl;
cout << eval("-arcsin(2 - i)") << endl;
// Mismatch of brackets error example
cout << eval("3 * ( 2 + 3 ]") << endl;
- Variable Names are started with the symbol
$
. +
,-
,*
,/
,^
and normal maths function names are supported.- Imaginary unit can be
i
,I
,j
orJ
. - Brackets can be
()
,[]
or{}
.
Tips: If you have expressions continuously only with difference in variable values, i.e.
num_list
, you can first callto_postorder
and store the postorderstd::vector
. Each time, callingeval_postorder
only can be more efficient.
Project Background
This project is the basis of the development of Fractal Designer 6 and is already used in Fractal Designer 5.6. This project is the core of syntax analysis in Fractal Designer project.
The picture above use eval
function to define the colour information in Fractal Designer. (Image Source: TVJ Group 20210707 Dev)
Licence
Copyright (c) 2021 Teddy van Jerry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Just wish to say your article is as surprising. The clearness in your post is just excellent and i can assume you’re an expert on this subject.
Well with your permission let me to grab your RSS feed to keep updated with forthcoming post.
Thanks a million and please keep up the enjoyable work.
For the reason that the admin of this web page is working, no doubt
very quickly it will be famous, due to its quality contents.
For hottest news you have to visit world-wide-web and on web I
found this site as a finest website for latest updates.
Greetіngs from Calіfornia! I’m borfed to death at ԝork so I decided to cһeck out your site on my iphone during
lunch break. I enjoy the information you ρresent here and
can’t wait to take a loоk when I geet home. I’m shocked at how quhick your
blog loaded on my mobile .. I’m not even usіng WIFI, just
3G .. Anyhow, awesomе blog!
Here is mmy web site :: [hellokitty coloring book](http://www.lefeverbasteyns.be/index.php?title=Coloring_Guide_Crayons_And_Markers “hellokitty coloring book”)
I’m really enjoying the design and layout of your site.
It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire
out a designer to create your theme? Exceptional work!
It’s very easy to find out any topic on net as compared to books, as
I found this post at this web site.
Do you have any video of that? I’d like to find out some additional
information.
Hi, I do think this is a great site. I stumbledupon it 😉 I am going to come back yet again since i have book-marked it.
Money and freedom is the greatest way to change, may you be rich and
continue to guide other people.
Your method of telling everything in this article
is genuinely pleasant, all be able to simply understand it, Thanks a lot.
Thanks for your personal marvelous posting! I definitely enjoyed reading it, you will be a great author.I will make
sure to bookmark your blog and definitely will come back someday.
I want to encourage one to continue your great work, have a nice morning!