你想要这个吗!
Description
JEP is a Java package for parsing and evaluating mathematical expressions. Now you can allow your users to enter an arbitrary formula, and they will instantly see the results! JEP supports user defined variables, constants, and functions. A number of common mathematical functions and constants are included.Features
Easy-to-use package for parsing mathematical expressions 
Supports boolean expressions (with !, &&, ||, <, >, !=, ==, >=, and <=) 
Variables can be part of the expression 
The values of the variables can be set externally 
The expression does not to be parsed again for each time the variables change 
All common functions (sin(), cos(), tan()...) included 
Extendable through user defined functions 
Predefined constants such as 'pi' and 'e' 
Support for complex numbers and strings 
Package is delivered with JavaCC grammar from which the main classes are generated 
Goals
Create an open-source package that can be used for educational purposes in the fields of Engineering, Mathematics and Computer Science 
Easy integration in programs that need expression evaluation 
Stable, comprehensive source code for people wanting to learn more about parsing 
Extendibility through good class structure 
License
This package is licensed under the GNU General Public License (GPL). The terms in this license apply to everyone, except for use in the game "Martello Tower" written exclusively for "The Matthew Holland School, Nottinghamshire".Plans
Change inner classes to handle Number objects instead of Double to simplify use of other real number classes such as BigDecimal 
Add more internal documentation 
Add type checking while parsing (e.g. "foo" + 41 should produce an error before evaluation) 
Think about incorporating MathML (output, or optional input form?) 
Add more functions for strings and arrays 
Comments / Bug Report
If you have found bugs in the package, errors on this Web site, or would like to add some comments, please post in the Discussion Forum.
My e-mail address is [email protected] (please write in English or German). I am also interested in starting to work together with someone who would like to add some of his or her own code to the projecthttp://jep.sourceforge.net/

解决方案 »

  1.   

    JAR Java Archive
    jep210.jar (Version 2.10)
    Follow the steps on documentation page for installationSource Code (including JavaCC grammar)
    jep210src.zip (Version 2.10)JavaCC grammar
    Parser.jjt (Version 2.10) If you successfully add JEP to an online project, a short email with a URL to your resource would be greatly appreciated ([email protected]). Let other users know how you have incorporated JEP into your project!
     
      

  2.   

    请直接把代码贴给我或mail给我吧,我想这不会太大的,谢谢!
    [email protected]
      

  3.   

    因为这个网 http://jep.sourceforge.net/ 上不去!to skyyoung(路人甲),请贴给我或mail给我吧,谢谢!
      

  4.   

    你自己不会downlaod吗,这么麻烦!
    发了
      

  5.   

    Usage
    Using the JEP package of classes in your project is simple. The following steps will get you started quickly.Download the JEP jar file from the download section 
    For the java compiler to be able to find the JEP classes when compiling your program, it needs to know their location. So you will need to add the location of the jar file to your CLASSPATH environment variable (read this if you don't know how). Your CLASSPATH variable should contain something like "C:\java\packages\JEP210.jar", depending on where you place the jar file. 
    In your program, create a new parser object with 
    org.nfunk.jep.JEP myParser = new org.nfunk.jep.JEP();
    Add the standard functions and constants if you want to be able to evaluate expressions with trigonometric functions and the constants pi and e. 
    myParser.addStandardFunctions();
    myParser.addStandardConstants();
    Add the variables that should be accepted in the expression. If a variable is not added before the expression is parsed, the parser will claim that the expression is invalid. To add the variable "x" for example, write 
    myParser.addVariable("x", 0);
    The variable is initialized with the value given as second parameter. 
    Parse the expression with 
    myParser.parseExpression(ExpressionString);
    Use the getValue() function to evaluate the expression 
    result = myParser.getValue();
    The values of variables can be changed with the addVariable(String, double) function. If a variable already exists, its value is set to the value of the second parameter.The code of the sample applet also provides a very good look at how the parser methods are used.
      

  6.   

    我把这个ZIP包解开后怎么办?
      

  7.   

    我是要实现:String s="2+9*2/(5-2)-3";要能算出 s包含的表达式的值.大家帮帮忙,或者谁用过 jep 包,告诉我怎么用这个包(怎么配这个包,是不是要编译...)!
      

  8.   

    http://jep.sourceforge.net/sampleapplet.htm这个sample里就有,还有源代码
    /**
     * Sample Applet for Expression Parser
     * @author Nathan Funk
     * @version 0.1
    */
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import org.netlib.math.complex.*;
    import org.nfunk.jep.*;
    /*
    <applet code="SampleApplet1" width=400 height=140>
    </applet>
    */
    public class SampleApplet1 extends Applet { JEP myParser; //Components
    Complex currentValue; TextField exprField, xField; //GUI
    // Button enterButton;
    String actionString;
    // -------------------------------------------------------
    // init
    //
    public void init() {
    //Init Textfield
    System.out.println("Initializing GUI"); Label exprFieldp = new Label("Expression ", Label.RIGHT);
    exprField = new TextField(27);
    Label xFieldp = new Label("X ", Label.RIGHT);
    xField = new TextField(4); add(exprFieldp);
    add(exprField);
    add(xFieldp);
    add(xField); xField.addTextListener(
    new java.awt.event.TextListener () {
    public void textValueChanged (java.awt.event.TextEvent evt) {
    xFieldTextValueChanged (evt);
    }
    }
    ); exprField.addTextListener(
    new java.awt.event.TextListener () {
    public void textValueChanged (java.awt.event.TextEvent evt) {
    exprFieldTextValueChanged (evt);
    }
    }
    ); setBackground(Color.white); //Init variables
    currentValue = new Complex(0,0);
    myParser = new JEP();
    myParser.addStandardFunctions();
    myParser.addStandardConstants();
    myParser.addComplex();
    myParser.setTraverse(true);
    myParser.addVariable("x", 0);
    }
    private void xFieldTextValueChanged(java.awt.event.TextEvent evt)
    {
    double xValue; //replace with double value later
    try
    {
    xValue = Double.valueOf(xField.getText()).doubleValue();
    }
    catch (NumberFormatException e)
    {
    System.out.println("Invalid format in xField");
    xValue = 0;
    } myParser.addVariable("x",  xValue); myParser.parseExpression(exprField.getText());
    currentValue = myParser.getComplexValue(); repaint();
    } private void exprFieldTextValueChanged(java.awt.event.TextEvent evt)
    {
    myParser.parseExpression(exprField.getText());
    currentValue = myParser.getComplexValue();
    repaint();
    }
    public void paint (Graphics g)
    {
        if (myParser.hasError())
      g.setColor(Color.red);
    else
      g.setColor(Color.black);
    g.drawString("Expression: " + exprField.getText(), 10, 40);
    g.setColor(Color.black);
    g.drawString("Status: " + myParser.getErrorInfo(), 10, 80);
    g.drawString("Value: " + currentValue, 10, 100);
    g.drawString("Actionstring: " + actionString, 10, 120);
    }
    }
      

  9.   

    to skyyoung(路人甲)
    我把你发给我的jep210src.zip 解压后用jar 将所有文件做成了jep.jar,放到c:\jdk13101\lib目录下,然后在classpath中加入;c:\jdk13101\lib\jep.jar但编译SampleApplet1.java时出错:c:\jdk13101\lib\jep.jar(org/nfunk/jep/JEP.java):43: class JEP is public, should
    be declared in a file named JEP.java
    (source unavailable)
    c:\jdk13101\lib\jep.jar(org/netlib/math/complex/Complex.java):129: class Complex
     is public, should be declared in a file named Complex.java
    (source unavailable)
    c:\jdk13101\lib\jep.jar(org/nfunk/jep/SymbolTable.java):30: class SymbolTable is
     public, should be declared in a file named SymbolTable.java
    (source unavailable)
    以下还有好多错误,原因是什么?该怎么做?