Skip to content

Instantly share code, notes, and snippets.

@samebchase
Created November 28, 2020 12:26
Show Gist options
  • Save samebchase/fad8108cb6daeaf8043d92a40eb29276 to your computer and use it in GitHub Desktop.
Save samebchase/fad8108cb6daeaf8043d92a40eb29276 to your computer and use it in GitHub Desktop.
balanced-parens.raku
#!/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