m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/parser.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.js')
-rw-r--r--src/parser.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/parser.js b/src/parser.js
index 9479abc..5e9960a 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -6,6 +6,8 @@ let throwSyntaxError = () => {
throw new Error('Syntax error: unexpected token')
}
+const dieBindingPower = 30
+
let newSymbol = (type, nud, lbp, led) => {
symbols[type] = {
type,
@@ -33,6 +35,16 @@ newSymbol('(', function(parser) {
newSymbol(')')
+const newDieOperation = (symbol, nud = null) => {
+ newSymbol(symbol, nud, dieBindingPower, (left, parser) => {
+ return {
+ type: symbol,
+ left: left,
+ right: parser.expression(dieBindingPower - 1)
+ }
+ })
+}
+
newSymbol('d', (parser) => {
return {
type: 'd',
@@ -55,6 +67,8 @@ newSymbol('E', null, 30, (left, parser) => {
}
})
+newDieOperation('K')
+
newSymbol('+', null, 20, (left, parser) => {
return {
type: 'add',