Solving a Variable Equation defined by the User

前端 未结 3 522
无人及你
无人及你 2021-02-04 14:28

Answers in C, Python, C++ or Javascript would be very much appreciated. I\'ve read a few books, done all the examples. Now I\'d like to write a simple program. But, I already ra

3条回答
  •  难免孤独
    2021-02-04 15:09

    In compiled languages like C, C++, or Java there is no easy way to do this--you basically have to rewrite a whole compiler (or use an external library with an interpreter). This is only trivial in "scripting" languages like Python and Javascript, which have a function (often called "eval()") that evaluates expressions at runtime. This function is often dangerous, because it can also do things like call functions with side effects.

提交回复
热议问题