From 36834bb8f64de5e6e4d16553172ef7c75fc5fc4c Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Tue, 13 Feb 2024 19:57:27 -0700 Subject: interpreter --- grammar.peggy | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 grammar.peggy (limited to 'grammar.peggy') diff --git a/grammar.peggy b/grammar.peggy new file mode 100644 index 0000000..c2dd580 --- /dev/null +++ b/grammar.peggy @@ -0,0 +1,14 @@ +LambdaTerm = Application / Abstraction / Variable + +Application = LPAREN _ left:LambdaTerm _ right:LambdaTerm RPAREN { return { application: { left, right } }; } + +Abstraction = LPAREN _ LAMBDA _ param:Variable _ DOT _ body:LambdaTerm RPAREN { return { abstraction: { param, body } }; } + +Variable = param:[a-zA-Z0-9]+ { return param.join(""); } + +LPAREN = "(" +RPAREN = ")" +DOT = "." +LAMBDA = "λ" / "\\" + +_ = ("\n" / " " / "\t" / "\r\n")* -- cgit v1.2.3-70-g09d2