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