diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-02-13 20:00:02 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-02-13 20:00:02 -0700 |
commit | 0c476e92e1807928ffb30864126076ef4c6a0821 (patch) | |
tree | a4992161ce4b6203edffb5d78533e9c73e61e6f1 /src/parser/grammar.pegjs | |
parent | 512c245466fad78106a046c1ea6233acdcc3e4de (diff) | |
download | compiling-the-lambda-calculus-main.tar.gz compiling-the-lambda-calculus-main.zip |
Diffstat (limited to 'src/parser/grammar.pegjs')
-rw-r--r-- | src/parser/grammar.pegjs | 27 |
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 |