Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Fixed a bug in the parser that caused incorrect parsing when the mult…
Browse files Browse the repository at this point in the history
…iply operator was missing
  • Loading branch information
Tim Rach authored and Tim Rach committed Oct 20, 2015
1 parent a84cb43 commit 3b492c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.js
Expand Up @@ -167,7 +167,7 @@ Parser.prototype.parseTermRest = function(factor) {
if (mulfactor2 === undefined) {
return factor;
} else {
return this.parseTermRest(factor.multiply(mulfactor2));
return factor.multiply(this.parseTermRest(mulfactor2));
}
}
};
Expand Down
10 changes: 10 additions & 0 deletions test/parser-spec.js
Expand Up @@ -3,6 +3,7 @@
var Parser = require("../src/parser.js"),
algebra = require("../algebra.js"),
Expression = algebra.Expression,
Fraction = algebra.Fraction,
Equation = algebra.Equation;

describe("Input validity", function() {
Expand Down Expand Up @@ -180,4 +181,13 @@ describe("Order of operations", function() {

expect(algebra.parse(input).toString()).toEqual(exp.toString());
});

it("power has a higher operator precedence than multiplication when the multiply operator is missing", function() {
var input = "(3/2)x^2";
var exp = new Expression("x").pow(2).multiply(new Fraction(3,2));

expect(algebra.parse(input).toString()).toEqual(exp.toString());
});


});

0 comments on commit 3b492c3

Please sign in to comment.