Created
November 28, 2020 12:26
-
-
Save samebchase/fad8108cb6daeaf8043d92a40eb29276 to your computer and use it in GitHub Desktop.
balanced-parens.raku
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
#!/usr/bin/env raku | |
use v6.d; | |
use Grammar::Tracer; | |
grammar BalancedParens { | |
token TOP { <balanced-paren> } | |
token balanced-paren { <lparen> <balanced-paren>* <rparen> } | |
token lparen { '(' } | |
token rparen { ')' } | |
} | |
sub MAIN() { | |
# Uncomment whatever you wanna take a closer look at | |
#say BalancedParens.parse("()"); | |
#say BalancedParens.parse("(())"); | |
#say BalancedParens.parse("(()())"); | |
#say BalancedParens.parse("(((())()))"); | |
#say BalancedParens.parse("(()"); # Fails | |
#say BalancedParens.parse("(()()))"); # Fails | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment