Last active
December 21, 2015 19:09
-
-
Save grondilu/6352516 to your computer and use it in GitHub Desktop.
Perl 6 grammar for Lambda-calculus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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