Last active
September 30, 2016 15:10
-
-
Save grondilu/2042abc2d847bcd480f6f9caaf513fac to your computer and use it in GitHub Desktop.
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
=begin comment | |
In this grammar, <expression> loops endlessly when tried with an empty string. | |
It first fails at <variable>, which is fine, it then fails at <function> which is also fine, | |
but then it keeps trying <application> recursively, even if <application> contains | |
at least the characters '(' and ')'. | |
Shouldn't Perl 6 be smart enough to understand that <application> will never match with an empty string? | |
=end comment | |
say grammar { | |
rule TOP { ^^ <expression> $$ } | |
rule expression { <variable> | <function> | <application> } | |
rule function { sub [ '(' <variable>? ')' ]? '{' <expression>? '}' } | |
rule application { <expression> '(' <expression>? ')' } | |
token variable { '$'<ident>+ } | |
}.parse: q{ sub {} }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment