Converting inserted string to a compilable expression

后端 未结 5 1927
醉梦人生
醉梦人生 2021-01-23 07:45

I\'m somehow new to Java so my question can seem trivial, however i cannot find an answer to it anywhere in my books.

I want to initiatie a dialog with a user in which h

5条回答
  •  渐次进展
    2021-01-23 08:01

    You have to write an expression parser to accomplish this kind of behaviour. There are a number of ways to accomplish this:

    1. Write your own expression parser using e.g. ANTLR.
    2. Include a scripting language (Jython, Beanshell, JavaScript...) and use that to parse and evaluate the expressions. The Java Scripting API can show you how to do this.

提交回复
热议问题