diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 18:14:14 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 18:14:14 -0400 |
commit | d3132a5463908bcabd0578ad48a457b2bec30a9a (patch) | |
tree | 4c752b28616663c418fa44b1f56219a3a4dd1e44 /src | |
parent | a15a2986c95131a13d3707ae50f8a215dcaac564 (diff) |
Lex and parse subtraction
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer.js | 1 | ||||
-rw-r--r-- | src/parser.js | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/lexer.js b/src/lexer.js index 97130d8..fd347c6 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -21,6 +21,7 @@ const newSkippableLexeme = (type, regex) => { newValueLexeme('constant', '\\d+', Number) newLexemeType('d', 'd') newLexemeType('+', '\\+') +newLexemeType('-', '-') newSkippableLexeme('whitespace', '\\s+') const lex = (expressionString) => { diff --git a/src/parser.js b/src/parser.js index c7d91c3..6c39c77 100644 --- a/src/parser.js +++ b/src/parser.js @@ -32,6 +32,14 @@ newSymbol('+', null, 20, (left, parser) => { } }) +newSymbol('-', null, 20, (left, parser) => { + return { + type: 'subtract', + left: left, + right: parser.expression(20) + } +}) + newSymbol('end', null, -1) const newParser = (tokens) => { |