Skip to content

Instantly share code, notes, and snippets.

@grondilu
Last active December 21, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/6352516 to your computer and use it in GitHub Desktop.
Save grondilu/6352516 to your computer and use it in GitHub Desktop.
Perl 6 grammar for Lambda-calculus
grammar Lambda {
=for description
I was trying to write a grammar for Lambda-calculus,
and I failed parsing a simple 'λx.x x' string.
rule TOP { ^ <expression> $ }
rule expression {
| \( ~ \) <expression>
| <abstraction>
| <application> # THIS WORKS
| <variable> #
#| <variable> # THIS DOES NOT
#| <application> # .. ???
}
token variable { <alpha> <digit>* }
token abstraction { 'λ' <variable>+ \. <expression> }
token application { <variable> ** 2..* % \s }
}
say Lambda.parse: 'λx.x x';
# vim: ft=perl6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment