diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-30 17:46:07 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-30 17:46:07 -0400 |
commit | 5087cde4825d91112cad565c68d81296359cf4d8 (patch) | |
tree | ad9dd27b079b1f41aa07c66f4f401c645241e25c /src | |
parent | 94bbae437d98c103d1dae09be9949bcf26e8bcf9 (diff) |
Implement multiplication
Diffstat (limited to 'src')
-rw-r--r-- | src/dice.js | 7 | ||||
-rw-r--r-- | src/lexer.js | 1 | ||||
-rw-r--r-- | src/parser.js | 1 |
3 files changed, 9 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js index 828a772..abe3c4b 100644 --- a/src/dice.js +++ b/src/dice.js @@ -44,6 +44,12 @@ const subtract = (die1, die2) => { } } +const multiply = (die1, die2) => { + return () => { + return [() => roll(die1) * roll(die2)] + } +} + const bonusAdd = (die1, die2) => { return () => { return die1().map(die => { @@ -187,6 +193,7 @@ exports.constant = constant exports.d = d exports.add = add exports.subtract = subtract +exports.multiply = multiply exports.bonusAdd = bonusAdd exports.bonusSubtract = bonusSubtract exports.negative = negative diff --git a/src/lexer.js b/src/lexer.js index ba3d3a5..c3eec8a 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -18,6 +18,7 @@ newValueLexeme('constant', '\\d+', Number) newLexemeType('d', 'd') newLexemeType('bigPlus', ' \\+ ' ) newLexemeType('bigMinus', ' - ') +newLexemeType('bigTimes', ' \\* ') newLexemeType('plus', '\\+') newLexemeType('minus', '-') newLexemeType('(', '\\(') diff --git a/src/parser.js b/src/parser.js index adb4b9b..1a1e5d4 100644 --- a/src/parser.js +++ b/src/parser.js @@ -71,6 +71,7 @@ newDieOperation('t') newInfix('bigPlus', 20, { type: 'add' }) newInfix('bigMinus', 20, { type: 'subtract' }) +newInfix('bigTimes', 23, { type: 'multiply' }) newInfix('plus', 25, { type: 'bonusAdd' }) newInfix('minus', 25, { type: 'bonusSubtract' }) newSymbol('minus', (parser) => { |