String Evaluate in C++

Print Friendly, PDF & Email

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 or J.
  • Brackets can be (), [] or {}.

Tips: If you have expressions continuously only with difference in variable values, i.e. num_list, you can first call to_postorder and store the postorder std::vector. Each time, calling eval_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.

FRD 5.6
The picture above use eval function to define the colour information in Fractal Designer. (Image Source: TVJ Group 20210707 Dev)

Licence

MIT 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.

11 Responses

  1. Tom says:

    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.

  2. 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.

  3. For hottest news you have to visit world-wide-web and on web I
    found this site as a finest website for latest updates.

  4. 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”)

  5. 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!

  6. Ulrich says:

    It’s very easy to find out any topic on net as compared to books, as
    I found this post at this web site.

  7. Do you have any video of that? I’d like to find out some additional
    information.

  8. 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.

  9. Anton says:

    Your method of telling everything in this article
    is genuinely pleasant, all be able to simply understand it, Thanks a lot.

  10. 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!

  1. 9 July 2021

    […] not very much. I finished the improvement work of String_Evaluate, which has also been posted on my blog website, come and hit the like […]

Leave a Reply

Your email address will not be published.