blob: 18e0b205591719e29e95720c55b64449d17d5ac8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#!/usr/bin/env perl6
use v6;
grammar BAL {
regex TOP { <expr>* }
regex expr { '(' <expr>* ')' }
}
given @*ARGS[0] {
when /^\d+$/ {
say "Random string of parens: ", my $s=<( )>.roll(@*ARGS[0].Int).join;
say "Balanced: ", BAL.parse($s).Bool
}
when /^<[()]>*$/ {
say "Balanced: ", BAL.parse(@*ARGS[0]).Bool
}
}
# run as <script> <number of parentheses> or
# <script> <single-quoted string of parens>
|