lambda-calculus-interpreter/grammar.peggy
2024-02-13 19:57:27 -07:00

15 lines
436 B
Plaintext

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")*