m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lexer.js2
-rw-r--r--src/parser.js8
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',