summaryrefslogtreecommitdiff
path: root/src/parser/grammar.pegjs
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-02-13 20:00:02 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-02-13 20:00:02 -0700
commit0c476e92e1807928ffb30864126076ef4c6a0821 (patch)
treea4992161ce4b6203edffb5d78533e9c73e61e6f1 /src/parser/grammar.pegjs
parent512c245466fad78106a046c1ea6233acdcc3e4de (diff)
downloadcompiling-the-lambda-calculus-0c476e92e1807928ffb30864126076ef4c6a0821.tar.gz
compiling-the-lambda-calculus-0c476e92e1807928ffb30864126076ef4c6a0821.zip
add all the stuffHEADmain
Diffstat (limited to 'src/parser/grammar.pegjs')
-rw-r--r--src/parser/grammar.pegjs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/parser/grammar.pegjs b/src/parser/grammar.pegjs
new file mode 100644
index 0000000..48a7564
--- /dev/null
+++ b/src/parser/grammar.pegjs
@@ -0,0 +1,27 @@
+LambdaTerm
+ = Abstraction
+ / Application
+ / Variable
+
+Application
+ = LPAREN _? left:LambdaTerm _? right:LambdaTerm _? RPAREN {
+ return { left, right };
+ }
+
+Abstraction
+ = LPAREN _? LAMBDA _? param:Variable _? DOT _? body:LambdaTerm _? RPAREN {
+ return { param, body };
+ }
+
+Variable
+ = name:([a-zA-Z][A-Z0-9a-z]*) { return { name: name[0] + name[1].join('') }; }
+
+LAMBDA = "λ"
+
+DOT = "."
+
+LPAREN = "("
+
+RPAREN = ")"
+
+_ = (" " / "\n" / "\t" / "\t\n")+ \ No newline at end of file