Thread: [Mathlib-commitlog] SF.net SVN: mathlib:[509] JMathLib/trunk/src/jmathlib/core/interpreter/ Parser.
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2008-11-30 16:24:20
|
Revision: 509
http://mathlib.svn.sourceforge.net/mathlib/?rev=509&view=rev
Author: st_mueller
Date: 2008-11-30 16:24:14 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2008-11-30 16:21:29 UTC (rev 508)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2008-11-30 16:24:14 UTC (rev 509)
@@ -334,9 +334,8 @@
(pToken instanceof PowerOperatorToken) )
Errors.throwParserException("multiple operators ^");
-
+ ErrorLogger.debugLine("PARSER op+op: "+nextToken);
ErrorLogger.debugLine("PARSER op+op: "+pToken);
- ErrorLogger.debugLine("PARSER op+op: "+nextToken);
if(nextToken instanceof AssignmentOperatorToken)
{
@@ -353,6 +352,15 @@
ErrorLogger.debugLine("Parser: dot-operator");
retToken = parseDotOperator(operandStack, deliTyp);
}
+ else if((nextToken instanceof AddSubOperatorToken) &&
+ (pToken instanceof AssignmentOperatorToken))
+ {
+ // += or -=
+ ErrorLogger.debugLine("Parser: += or -=");
+ nextToken = getNextToken(deliTyp);
+ retToken = parseAssignmentOperator(nextToken, operandStack);
+
+ }
else if( (nextToken instanceof AddSubOperatorToken)
|| (nextToken instanceof MulDivOperatorToken)
|| (nextToken instanceof PowerOperatorToken)
@@ -591,7 +599,7 @@
/* @return expression of assignment (e.g. a=3) */
private OperandToken parseAssignmentOperator(Token currentToken, Stack operandStack)
{
- // operator (this should be a "=")
+ // operator (this should be a "=" or ("+" for +=) or ("-" for -=))
OperatorToken operator = (OperatorToken)currentToken;
//parse right parameter
@@ -601,7 +609,19 @@
OperandToken leftSide = (OperandToken)operandStack.pop();
/* create new expression */
- Expression tree = new Expression(operator, leftSide, rightSide);
+ Expression tree = null;
+ if (currentToken instanceof AssignmentOperatorToken)
+ {
+ // e.g. a=8
+ tree = new Expression(operator, leftSide, rightSide);
+ }
+ else if (currentToken instanceof AddSubOperatorToken)
+ {
+ // e.g. a+=8
+ tree = new Expression(operator, rightSide, new DoubleNumberToken(1.0));
+ tree = new Expression(new AssignmentOperatorToken(), leftSide, tree);
+ // ???????
+ }
return tree;
} // end parseAssignmentOperator
@@ -1445,14 +1465,15 @@
boolean numberIndicatorB = false; //
boolean singleIndicatorB = false; //
boolean imagIndicatorB = false; //
-
+ System.out.println("*+*");
// remove spaces between "[" and first element (e.g. [ 2,3] -> [2,3]
while (isExpectedDelimiter(peekNextToken(MATRIX), ' '))
getNextToken();
-
+ System.out.println("*++*");
// parse code of matrices (e.g. [1,2,3;4,5,6] or [1 sin(2) 3; 4 5+1 a]
while(!endMatrix)
{
+ System.out.println("**");
// get next parameter (whitespaces are treated as delimiter, too)
OperandToken nextParameter = parseArithExpression(MATRIX);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2008-12-07 19:12:39
|
Revision: 545
http://mathlib.svn.sourceforge.net/mathlib/?rev=545&view=rev
Author: st_mueller
Date: 2008-12-07 19:12:37 +0000 (Sun, 07 Dec 2008)
Log Message:
-----------
bugfix for (8-4)! factorial =4!
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2008-12-07 19:02:17 UTC (rev 544)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2008-12-07 19:12:37 UTC (rev 545)
@@ -827,14 +827,14 @@
Expression tree = null;
- if ((leftSide instanceof DoubleNumberToken) ||
+ /* if ((leftSide instanceof DoubleNumberToken) ||
(leftSide instanceof MatrixToken) ||
(leftSide instanceof VariableToken) ||
(leftSide instanceof FunctionToken) )
- {
+ {*/
// (e.g. 3! a! a++ a--)
tree = new Expression((UnaryOperatorToken)nextToken, leftSide);
- }
+ /*}
else if (leftSide instanceof Expression)
{
Expression leftExpr = (Expression)leftSide;
@@ -848,7 +848,7 @@
}
else
Errors.throwParserException(" Unary operator");
-
+ */
return tree;
} // end parseBinaryOperator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-26 19:47:31
|
Revision: 782
http://mathlib.svn.sourceforge.net/mathlib/?rev=782&view=rev
Author: st_mueller
Date: 2009-01-26 19:47:27 +0000 (Mon, 26 Jan 2009)
Log Message:
-----------
removed debug output
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-01-25 22:23:40 UTC (rev 781)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-01-26 19:47:27 UTC (rev 782)
@@ -1506,15 +1506,14 @@
boolean numberIndicatorB = false; //
boolean singleIndicatorB = false; //
boolean imagIndicatorB = false; //
- System.out.println("*+*");
+
// remove spaces between "[" and first element (e.g. [ 2,3] -> [2,3]
while (isExpectedDelimiter(peekNextToken(MATRIX), ' '))
getNextToken();
- System.out.println("*++*");
+
// parse code of matrices (e.g. [1,2,3;4,5,6] or [1 sin(2) 3; 4 5+1 a]
while(!endMatrix)
{
- System.out.println("**");
// get next parameter (whitespaces are treated as delimiter, too)
OperandToken nextParameter = parseArithExpression(MATRIX);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-02-04 18:36:07
|
Revision: 830
http://mathlib.svn.sourceforge.net/mathlib/?rev=830&view=rev
Author: st_mueller
Date: 2009-02-04 18:35:59 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
bugfix for a++ and a--
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-02-03 22:15:48 UTC (rev 829)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-02-04 18:35:59 UTC (rev 830)
@@ -398,10 +398,19 @@
{
// += or -=
ErrorLogger.debugLine("Parser: += or -=");
- nextToken = getNextToken(deliTyp);
- retToken = parseAssignmentOperator(nextToken, operandStack);
+ getNextToken(deliTyp);
+ retToken = parseAssignmentOperator(nextToken, operandStack);
}
+ else if((nextToken instanceof MulDivOperatorToken) &&
+ (pToken instanceof AssignmentOperatorToken))
+ {
+ // *= or /=
+ ErrorLogger.debugLine("Parser: *= or /=");
+ getNextToken(deliTyp);
+ retToken = parseAssignmentOperator(nextToken, operandStack);
+
+ }
else if( (nextToken instanceof AddSubOperatorToken)
|| (nextToken instanceof MulDivOperatorToken)
|| (nextToken instanceof PowerOperatorToken)
@@ -641,6 +650,7 @@
private OperandToken parseAssignmentOperator(Token currentToken, Stack operandStack)
{
// operator (this should be a "=" or ("+" for +=) or ("-" for -=))
+ // or "*" for *= or "/" for /=
OperatorToken operator = (OperatorToken)currentToken;
//parse right parameter
@@ -658,11 +668,20 @@
}
else if (currentToken instanceof AddSubOperatorToken)
{
- // e.g. a+=8
- tree = new Expression(operator, rightSide, new DoubleNumberToken(1.0));
+ // e.g. a+=8 -> a=a+8
+ // e.g. a-=7 -> a=a-7
+ ErrorLogger.debugLine("Parser: += or -=");
+ tree = new Expression(operator, leftSide, rightSide);
tree = new Expression(new AssignmentOperatorToken(), leftSide, tree);
- // ???????
}
+ else if (currentToken instanceof MulDivOperatorToken)
+ {
+ // e.g. a*=8 -> a=a*8
+ // e.g. a/=9 -> a=a/9
+ ErrorLogger.debugLine("Parser: *= or /=");
+ tree = new Expression(operator, leftSide, rightSide);
+ tree = new Expression(new AssignmentOperatorToken(), leftSide, tree);
+ }
return tree;
} // end parseAssignmentOperator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|