M
M
Maxim Bredikhin2016-02-07 00:17:49
Java
Maxim Bredikhin, 2016-02-07 00:17:49

How to translate a string into a formula in Java?

Hello, I want to make a program that reads a line (formula), what needs to be done to translate this line into "computer language"?))
For example, there is such a line: "y=ln(x)+2.5*7^x" it is necessary to these actions were performed in the program. I read that this can be done using regular expressions, but did not understand how.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Евгений, 2016-02-07
@zolt85

Ну Вы конечно насоветовали человеку ...
Если нужно запилить парсер нет ничего лучше, чем ANTLR
сами описываете грамматику, он Вам генерит код, который эту грамматику понимает. Примеров грамматик для математики вагон и маленькая тележка.

R
Rsa97, 2016-02-07
@Rsa97

If you want to fully understand the issue - see the theory of compilers, for example, the book of the red dragon .

Y
YV, 2016-02-07
@targetjump

ScriptEngine + eval

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question