All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nfunk.jepexamples.Console Maven / Gradle / Ivy

Go to download

JEP is a Java library for parsing and evaluating mathematical expressions.

The newest version!
/*****************************************************************************

 JEP 2.4.1, Extensions 1.1.1
      April 30 2007
      (c) Copyright 2007, Nathan Funk and Richard Morris
      See LICENSE-*.txt for license information.

*****************************************************************************/

/**
 * Console - JEP Example Applet
 * Copyright (c) 2000 Nathan Funk
 *
 * @author Nathan Funk 
 */

package org.nfunk.jepexamples;

import java.io.*;
import org.nfunk.jep.JEP;
//import org.nfunk.sovler.*;

/**
* This class implements a simple command line utility for evaluating
* mathematical expressions.
*
*   Usage: java org.nfunk.jepexamples.Console [expression]
*
* If an argument is passed, it is interpreted as an expression
* and evaluated. Otherwise, a prompt is printed, and the user can enter
* expressions to be evaluated. To exit from the command prompt a 'q' must
* be entered.
*/
class Console {
	
	/** The prompt string */
	private String prompt;
	
	/** The input reader */
	private BufferedReader br;
	
	/** Constructor */
	public Console() {
		prompt = "JEP > ";
		br = new BufferedReader(new InputStreamReader(System.in));

	}

	/** Creates a new Console object and calls run() */
	public static void main(String args[]) throws IOException {
		Console c = new Console();
		c.run(args);
	}
	
	/** The input loop */
	public void run(String args[]) throws IOException {
		String command="";
		JEP j = new JEP();
		j.addStandardConstants();
		j.addStandardFunctions();
		j.addComplex();
		//j.setTraverse(true);

		if (args.length>0) {
			// evaluate the expression passed as arguments
			String temp = args[0];
			for (int i=1; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy