Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 9 10 16 17 package org.nfunk.jepexamples; 18 19 import java.io.*; 20 import org.nfunk.jep.JEP; 21 23 34 class Console { 35 36 37 private String prompt; 38 39 40 private BufferedReader br; 41 42 43 public Console() { 44 prompt = "JEP > "; 45 br = new BufferedReader(new InputStreamReader(System.in)); 46 47 } 48 49 50 public static void main(String args[]) throws IOException { 51 Console c = new Console(); 52 c.run(args); 53 } 54 55 56 public void run(String args[]) throws IOException { 57 String command=""; 58 JEP j = new JEP(); 59 j.addStandardConstants(); 60 j.addStandardFunctions(); 61 j.addComplex(); 62 64 if (args.length>0) { 65 String temp = args[0]; 67 for (int i=1; i<args.length; i++) temp += " " + args[i]; 68 j.parseExpression(temp); 69 if (j.hasError()) 70 System.out.println(j.getErrorInfo()); 71 else 72 System.out.println(j.getValueAsObject()); 73 } else { 74 76 System.out.println("JEP - Enter q to quit"); 77 System.out.print(prompt); 78 79 while ((command = getCommand()) != null) { 80 j.parseExpression(command); 81 82 if (j.hasError()) { 83 System.out.println(j.getErrorInfo()); 84 } else { 85 Object value = j.getValueAsObject(); 87 88 if (j.hasError()) { 90 System.out.println(j.getErrorInfo()); 91 } else { 92 System.out.println(value); 93 } 94 95 103 } 104 105 System.out.print(prompt); 106 } 107 } 108 109 } 110 111 116 private String getCommand() throws IOException { 117 String s; 118 119 if (br == null) 120 return null; 121 122 if ( (s = br.readLine()) == null) 123 return null; 124 125 if (s.equals("q") 126 || s.equals("quit") 127 || s.equals("exit")) 128 return null; 129 130 return s; 131 } 132 } 133
| Popular Tags
|