for example I want to let the user write in the console cos(log(x))+tan(x^2+6) and then he'll enter some integer A and evaluate f(A) , I did a code in C but it's so limited , it provide just c+s+r and there is no coefficient (it's 600 lines so i couldn't show it) , and if there is a language which can I write this code much easier I'd like to know it.
Asked
Active
Viewed 54 times
1 Answers
2
In C++ you can enlist the help of higher level parser libraries such as Boost Spirit.
"eval" languages such as JavaScript let you do this even more simply, but at the cost of some security and robustness issues. Namely, you can directly evaluate a string entered by the user. as JavaScript (or whatever the language is) code. However, that string may contain anything, so it's mostly just a tool for strictly personal use.

Cheers and hth. - Alf
- 142,714
- 15
- 209
- 331
-
-
@Elias: No, not directly. However, Java has [a `ScriptEngine` class](http://stackoverflow.com/questions/2605032/is-there-an-eval-function-in-java) that can be used to do JavaScript evaluation. :) Without that you could (I believe) use Java's *introspection* facilities to do this in a way somewhat intermediate between C++ and JavaScript: easier than C++, but still complex, and safer than JavaScript, but still a bit suspect code. – Cheers and hth. - Alf Aug 18 '15 at 10:09