Answer the question
In order to leave comments, you need to log in
How to design calculators that count expressions like 2+4*(4-3)?
I would like to know if there is any literature about such algorithms, or manuals that allow you to understand how to do things like such calculators. Any language.
Answer the question
In order to leave comments, you need to log in
I'm surprised by the comments! How is it not met with literature, if there are fundamental works on this topic. In addition, there are a lot of topics on Habré (I give the first three, you can promote all the rest by tags):
habrahabr.ru/post/140058
habrahabr.ru/post/108062
habrahabr.ru/post/133780
But there are books with algorithms, rules for their construction, something like that?
You can use a parser generator to create an AST tree and then iterate over it, evaluating the expression.
Here is an example of such a generator in JS.
Here is an example calculator.
And here is a working port of the generator in PHP with a complex example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question