Thread: [Mathlib-commitlog] SF.net SVN: mathlib:[446] JMathLib/trunk/src/jmathlib/core/tokens/ UnaryOperato
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2008-11-17 20:20:52
|
Revision: 446
http://mathlib.svn.sourceforge.net/mathlib/?rev=446&view=rev
Author: st_mueller
Date: 2008-11-17 20:20:44 +0000 (Mon, 17 Nov 2008)
Log Message:
-----------
added support for 5++ and 3--
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2008-11-16 18:24:28 UTC (rev 445)
+++ JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2008-11-17 20:20:44 UTC (rev 446)
@@ -48,20 +48,27 @@
// -- operator
// check if operand is a variable (e.g. a--, bar--)
- if(!(operand instanceof VariableToken))
+ if(operand instanceof VariableToken)
+ {
+ // first: evaluate and return original value variable
+ result = operand.evaluate(null);
+
+ // second: decrease variable
+ OperandToken op = result.subtract(new DoubleNumberToken(1));
+
+ // save new variable value
+ String variable = ((VariableToken)operand).getName();
+ //getVariables().getVariable(variable).assign(op);
+ getVariable(variable).assign(op);
+ }
+ else if(operand instanceof NumberToken)
+ {
+ // 4--
+ result = operand.subtract(new DoubleNumberToken(1));
+ }
+ else
Errors.throwMathLibException("UnaryOperatorToken --");
-
- // first: evaluate and return original value variable
- result = operand.evaluate(null);
-
- // second: decrease variable
- OperandToken op = result.subtract(new DoubleNumberToken(1));
- // save new variable value
- String variable = ((VariableToken)operand).getName();
- //getVariables().getVariable(variable).assign(op);
- getVariable(variable).assign(op);
-
break;
}
case '+':
@@ -69,20 +76,27 @@
// ++ operator
// check if operand is a variable (e.g. a++, bar++)
- if(!(operand instanceof VariableToken))
+ if(operand instanceof VariableToken)
+ {
+ // first: evaluate and return original value variable
+ result = operand.evaluate(null);
+
+ // second: increase variable
+ OperandToken op = result.add(new DoubleNumberToken(1));
+
+ // save new variable value
+ String variable = ((VariableToken)operand).getName();
+ //getVariables().getVariable(variable).assign(op);
+ getVariable(variable).assign(op);
+ }
+ else if(operand instanceof NumberToken)
+ {
+ // 5++
+ result = operand.add(new DoubleNumberToken(1));
+ }
+ else
Errors.throwMathLibException("UnaryOperatorToken ++");
-
- // first: evaluate and return original value variable
- result = operand.evaluate(null);
-
- // second: increase variable
- OperandToken op = result.add(new DoubleNumberToken(1));
- // save new variable value
- String variable = ((VariableToken)operand).getName();
- //getVariables().getVariable(variable).assign(op);
- getVariable(variable).assign(op);
-
break;
}
default:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-24 20:23:00
|
Revision: 765
http://mathlib.svn.sourceforge.net/mathlib/?rev=765&view=rev
Author: st_mueller
Date: 2009-01-24 20:22:57 +0000 (Sat, 24 Jan 2009)
Log Message:
-----------
changed signature of evaluate(Token[] operands)
to
evaluate(Token[] operands, GlobalValues globals)
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2009-01-24 20:21:39 UTC (rev 764)
+++ JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2009-01-24 20:22:57 UTC (rev 765)
@@ -8,7 +8,8 @@
public class UnaryOperatorToken extends OperatorToken
{
/**Constructor taking the operator and priority
- @param _operator = the operator being constructed */
+ * @param _operator = the operator being constructed
+ */
public UnaryOperatorToken(char _operator)
{
/**call the super constructor, type defaults to ttoperator and operands to 1*/
@@ -19,7 +20,7 @@
/**evaluate the operator
@param operands = the operator operands
@return the result as an OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
OperandToken result = null;
@@ -51,7 +52,7 @@
if(operand instanceof VariableToken)
{
// first: evaluate and return original value variable
- result = operand.evaluate(null);
+ result = operand.evaluate(null, globals);
// second: decrease variable
OperandToken op = result.subtract(new DoubleNumberToken(1));
@@ -59,7 +60,7 @@
// save new variable value
String variable = ((VariableToken)operand).getName();
//getVariables().getVariable(variable).assign(op);
- getVariable(variable).assign(op);
+ globals.getVariable(variable).assign(op);
}
else if(operand instanceof NumberToken)
{
@@ -79,7 +80,7 @@
if(operand instanceof VariableToken)
{
// first: evaluate and return original value variable
- result = operand.evaluate(null);
+ result = operand.evaluate(null, globals);
// second: increase variable
OperandToken op = result.add(new DoubleNumberToken(1));
@@ -87,7 +88,7 @@
// save new variable value
String variable = ((VariableToken)operand).getName();
//getVariables().getVariable(variable).assign(op);
- getVariable(variable).assign(op);
+ globals.getVariable(variable).assign(op);
}
else if(operand instanceof NumberToken)
{
@@ -113,7 +114,9 @@
return result;
}
- /**@return the operator as a string*/
+ /**
+ * @return the operator as a string
+ */
public String toString()
{
if (value=='-')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-02-03 22:15:56
|
Revision: 829
http://mathlib.svn.sourceforge.net/mathlib/?rev=829&view=rev
Author: st_mueller
Date: 2009-02-03 22:15:48 +0000 (Tue, 03 Feb 2009)
Log Message:
-----------
bugfix for a++ and a--
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
Modified: JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2009-02-03 22:15:28 UTC (rev 828)
+++ JMathLib/trunk/src/jmathlib/core/tokens/UnaryOperatorToken.java 2009-02-03 22:15:48 UTC (rev 829)
@@ -61,6 +61,8 @@
String variable = ((VariableToken)operand).getName();
//getVariables().getVariable(variable).assign(op);
globals.getVariable(variable).assign(op);
+
+ return op;
}
else if(operand instanceof NumberToken)
{
@@ -89,6 +91,8 @@
String variable = ((VariableToken)operand).getName();
//getVariables().getVariable(variable).assign(op);
globals.getVariable(variable).assign(op);
+
+ return op;
}
else if(operand instanceof NumberToken)
{
@@ -106,12 +110,7 @@
}
}
- //if(result == null)
- //{
- // //return origional expression
- // result = new Expression(this, operand);
- //}
- return result;
+ return result;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|