diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 23:34:55 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-14 23:34:55 -0400 |
commit | c5b9b7d03a37b807b212c29a9bdf7afc837c5423 (patch) | |
tree | 010ff6b701a22204cdec8fd277e7a8129ae988e2 /src | |
parent | d3132a5463908bcabd0578ad48a457b2bec30a9a (diff) |
Lex and parse parentheses
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer.js | 2 | ||||
-rw-r--r-- | src/parser.js | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/lexer.js b/src/lexer.js index fd347c6..f559816 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -22,6 +22,8 @@ newValueLexeme('constant', '\\d+', Number) newLexemeType('d', 'd') newLexemeType('+', '\\+') newLexemeType('-', '-') +newLexemeType('(', '\\(') +newLexemeType(')', '\\)') newSkippableLexeme('whitespace', '\\s+') const lex = (expressionString) => { diff --git a/src/parser.js b/src/parser.js index 6c39c77..9f2c6ac 100644 --- a/src/parser.js +++ b/src/parser.js @@ -16,6 +16,14 @@ newSymbol('constant', function() { return { type: 'constant', value: this.value } }) +newSymbol('(', function(parser) { + const value = parser.expression(1) + parser.match(')') + return value +}) + +newSymbol(')') + newSymbol('d', null, 30, (left, parser) => { return { type: 'd', |