Parser: parsing formulas in template files

First, I will talk about the problem, and then about what I am currently viewing, from the point of view of libraries.

In my application, we have a set of variables that are always available. For example: TOTAL_ITEMS, PRICE, CONTRACTS, ETC (we have about 15 of them). Application clients would like certain calculations to be performed and displayed using these variables. So far, I have been constantly adding these calculations to the application. This is a pain in the butt, and I would like to make it more general by creating a template where the user can specify a set of formulas that the application will analyze and calculate.

Here is one case:

total_cost = CONTRACTS*PRICE*TOTAL_ITEMS

So you want to do something like this so that the user can define in the template file:

total_cost = CONTRACTS*PRICE*TOTAL_ITEMSand some metadata, such as a screen, to display it. Therefore, they will determine the formula using the screen. And the file will contain many formulas of this kind.

I am currently considering two versions: Spirit and matheval

Someone will give recommendations what is better for this task, as well as links, examples, links?

Please let me know if the question is not clear and I will try to clarify it.

Thanks,

Sasha

+3
source share
3 answers

If you have a fixed number of variables, this might be a little redundant to invoke the parser. Although Spirit is cool, and I wanted to use it in the project.

, , , ( , ints):

map<const char*,int*> vars;
vars["CONTRACTS"] = &contracts;
...

postfix .

Edit:

MathEval, , , , ; . , . - , MathEval ?

0

, , yacc bison .

0

matheval, boost:: spirit : . .

, Boost:: Proto, , .

0
source

Source: https://habr.com/ru/post/1703962/


All Articles