1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
<html><!-- #BeginTemplate "/Templates/maintemplate.dwt" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- #BeginEditable "doctitle" -->
<title>JEP - Java Math Expression Parser</title>
<!-- #EndEditable -->
<link rel="stylesheet" type="text/css" href="main.css" title="style1">
</head>
<body>
<!-- NAVIGATION ---------------------------------------------------- -->
<div id="navcontainer">
<ul>
<li><a href="../javadoc/index.html" target="_blank">JavaDoc <img src="img/new-window-icon.gif" width="15" height="11"></a></li>
</ul>
<h1>JEP</h1>
<ul>
<li><a href="index.html">Basic Usage</a></li>
<li><a href="variables.html">Variables</a></li>
<li><a href="types.html">Data types</a></li>
<li><a href="operators.html">Operators</a></li>
<li><a href="functions.html">Functions</a></li>
<li><a href="advanced.html">Advanced Features</a></li>
<li><a href="grammar.html">Grammar</a></li>
<li><a href="faq.html">FAQ</a></li>
<li><a href="version.html">Version History</a></li>
</ul>
<h1>Extensions</h1>
<ul>
<li><a href="extensions/index.html">Overview</a></li>
<li><a href="extensions/xjep.html">XJep</a></li>
<li><a href="extensions/djep.html">Differentiation</a></li>
<li><a href="extensions/vectorjep.html">Vectors and Matrices</a></li>
<li><a href="extensions/groupjep.html">Groups</a></li>
<li><a href="extensions/version.html">Version History</a></li>
</ul>
</div>
<div id="centercontent">
<!-- CENTER CONTENT -------------------------------------------------- -->
<!-- #BeginEditable "Text" -->
<h1><a name="top"></a>Operators</h1>
<h2>Built in operators</h2>
<p>All common arithmetic operators are supported. Boolean operators are also
fully supported. Boolean expressions are evaluated to be either 1 or 0 (true
or false respectively).</p>
<p>An <img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check">
indicates that the operator can be used with the specific type of variable.
Refer to the <a href="grammar.html">grammar</a> for detailed information about
operator precedence.</p>
<table border="0" cellspacing="1" cellpadding="2" width="100%" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF">
<td width="225"> </td>
<td width="91"> </td>
<td width="76"><b>Double</b></td>
<td width="81"><b>Complex</b></td>
<td width="91"><b>String</b></td>
<td width="91"><b>Vector</b></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Power</td>
<td width="91">^</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="91" align="center"> </td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Boolean Not</td>
<td width="91">!</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"> </td>
<td width="91" align="center"> </td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Unary Plus, Unary Minus</td>
<td width="91">+x, -x</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="91" align="center"> </td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Modulus</td>
<td width="91">%</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"> </td>
<td width="91" align="center"> </td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Division</td>
<td width="91">/</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="91" align="center"> </td>
<td width="91" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Multiplication</td>
<td width="91">*</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="91" align="center"> </td>
<td width="91" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Addition, Subtraction</td>
<td width="91">+, -</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="91" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check">
(only +)</td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Less or Equal, More or Equal</td>
<td width="91" bordercolor="#CCCCCC"><=, >=</td>
<td width="76" bordercolor="#CCCCCC" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" bordercolor="#CCCCCC" align="center"> </td>
<td width="91" bordercolor="#CCCCCC" align="center"> </td>
<td width="91" bordercolor="#CCCCCC" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Less Than, Greater Than</td>
<td width="91"><, ></td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"> </td>
<td width="91" align="center"> </td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Not Equal, Equal</td>
<td width="91">!=, ==</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="91" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Boolean And</td>
<td width="91">&&</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"> </td>
<td width="91" align="center"> </td>
<td width="91" align="center"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="225">Boolean Or</td>
<td width="91">||</td>
<td width="76" align="center"><img src="img/checkmark.gif" width="10" height="10" border="0" alt="Check"></td>
<td width="81" align="center"> </td>
<td width="91" align="center"> </td>
<td width="91" align="center"> </td>
</tr>
</table>
<!-- #BeginLibraryItem "/Library/top bar.lbi" -->
<div class="topbar"><a href="#top"><img src="img/top.gif" width="38" height="15" name="top"></a></div>
<!-- #EndLibraryItem -->
<h2>Adding operators</h2>
<p>Adding operators is currently only possible by modifying the JEP source code.
To add an operator to the parser several steps are needed:
<ul>
<li>Create a new <i>token</i> with the descriptive name AT, say, and a string
representing the operator. </li>
<li>Modify the grammer rules to include a rule for the new operator </li>
<li>Create a new object implementing org.nfunk.jep.function.PostfixMathCommandI
to provide methods for evaluating the operator. </li>
<li>Modify or sub class org.nfunk.jep.OperatorSet to bind the operator in
the parser to PostfixMathCommand </li>
</ul>
Before atempting to add an operator you should be familiar with adding a <a href="functions.html#custom">custom
function</a> to JEP.
<h3>JavaCC The parser generator</h3>
<p> Rather than writing the parser by hand in java the parser is created using
the <a href="https://javacc.dev.java.net/">JavaCC</a> parser/scanner generator.
This reads a file Parser.jjt which is written in a special language which
defines the grammer and creates Parser.java and some other java files which
implement the parser.</p>
<p>You should read some of the documentation on <a href="https://javacc.dev.java.net/doc/docindex.html/">JavaCC</a>
and <a href="https://javacc.dev.java.net/doc/JJTree.html">JJTree</a> before
attempting to modify the parser.</p>
<p>There is a three step process used to generate the parser. </p>
<ol>
<li>JJTree is run. This reads the file Parser.jjt and creates a file Parser.jj.
The purpose of this step is to add code needed to handle Abstract Systax
Trees which are tree structures used represent a mathematical expression.
As well as creating parser.jj it also creates some other java files: Node.java
which represents the basic node in the parser; ASTConstant.java a node representing
a constant value "0" or "1", ASTVarNode.java a node representing a variable,
ASTFunNode.java a node representing a function or operator.
<li>javacc is run. This reads Parser.jj and creates Parser.java the actual
code for implementing the Parser. Parser.java is a very complicated file
with nearly 2000 lines of code.
<li>Normal java comilation step which compiles Parser.java.
</ol>
<p> This process should automatically be caried out when the project is built
using the ANT build.xml file. It is not sufficient to simple recompile all
the java files.</p>
<p>Only the Parser.jjt file should be modified, Parser.jj, Parser.java should
not be modified as they will be overwritten during the build process. Furthermore
ASTConstant.java, ASTFunNode.java, ASTStart.java, ASTVarNode.java, JavaCharStream.java,
JJTParserState.java, Node.java, SimpleNode.java, ParseException.java, ParserConstants.java,
ParserTokenManager.java, ParseTreeConstants.java, Token.java, TokenMgrError.java
should not normally be modified as these are also automatically generated.</p>
<!-- #BeginLibraryItem "/Library/top bar.lbi" -->
<div class="topbar"><a href="#top"><img src="img/top.gif" width="38" height="15" name="top"></a></div>
<!-- #EndLibraryItem -->
<!-- #EndEditable -->
<!-- FOOTER ---------------------------------------------------------- -->
<div id="footer">
<a href="http://sourceforge.net/tracker/?func=add&group_id=24711&atid=382402">Report bugs / documentation errors</a><br/>
<br/>
© 2006 <a href="http://www.singularsys.com" target="_blank">Singular Systems</a>
</div>
</div> <!-- centercontent -->
</body>
<!-- #EndTemplate --></html>
|