Skip to content

Instantly share code, notes, and snippets.

@raydiak
Created October 3, 2014 02:51
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 raydiak/70f73bc4f65f35f20553 to your computer and use it in GitHub Desktop.
Save raydiak/70f73bc4f65f35f20553 to your computer and use it in GitHub Desktop.
cyclical rule problem
#!/usr/bin/env perl6
use v6;
grammar Problem {
token TOP { <expression> }
rule expression { <operation> | <value> }
rule operation {<expression> <operator> <expression>}
token operator { \+ | \- | \* | \/ }
token value { \d+ }
}
grammar NoProblem is Problem {
# the only difference here is that the rules have been changed to tokens
token expression { <operation> | <value> }
token operation {<expression> <operator> <expression>}
}
NoProblem.parse("1").perl.say; # expected result
Problem.parse("1").perl.say; # infinite loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment