Java 1.5: mathematical formula parser

后端 未结 5 923
野趣味
野趣味 2021-01-20 00:39

Hello i often develop JTableModels in which some cells must contain the result of apliying a certain simple mathematical formula. This formulas can have:

  • Opera
相关标签:
5条回答
  • 2021-01-20 00:55

    There's a commercial tool called formula4j which may be useful to some.

    It has no direct help for cell references. You would have to handle those yourself, and translate the cell references into values.

    0 讨论(0)
  • 2021-01-20 00:57

    i released an expression evaluator based on Dijkstra's Shunting Yard algorithm, under the terms of the Apache License 2.0:

    http://projects.congrace.de/exp4j/index.html

    0 讨论(0)
  • 2021-01-20 00:58

    If you can't use Java 6 and its scripting support then have a look at the Apache Bean Scripting Framework (BSF). From that page:

    ... BSF 3.x will run on Java 1.4+, allowing access to JSR-223 scripting for Java 1.4 and Java 1.5.

    0 讨论(0)
  • 2021-01-20 01:00

    Try JEP.

    You can define new variables to the parser hence it can contain reference names like "INTEREST_RATE".But you have to define it before hand.

    As for cell references you will have to extract the number's and edit the expression accordingly or probably there might be some options which I'm not yet aware of.

    0 讨论(0)
  • 2021-01-20 01:11

    Have you thought about the benefits of JSR-223 ? in a few words, this spec allows Java developers to integrate with great ease dynamic languages and their parsers. Using such parser, your need for defining a parser transforms into the need for defining an internal DSL, which resolves into creating simply a good API, and letting your user choose wether they prefer Javascript/Groovy/Scala/WTF syntax they happen to prefer.

    0 讨论(0)
提交回复
热议问题