parens.icn: Program to produce random balanced strings

March 26, 2002; Ralph E. Griswold
This file is in the public domain.
   This program produces parenthesis-balanced strings in which
the parentheses are randomly distributed.

Options: The following options are available:

     -b n Bound the length of the strings to n left and right
          parentheses each. The default is 10.

     -n n Produce n strings. The default is 10.

     -l s Use the string s for the left parenthesis. The default
          is ( .

     -r s Use the string s for the right parenthesis. The default
          is ) .

     -v   Randomly vary the length of the strings between 0 and
          the bound.  In the absence of this option, all strings
          are the exactly as long as the specified bound.

   For example, the output for

        parens -v -b 4 -l "begin " -r "end "

is

        begin end
        begin end begin end
        begin begin end end begin end
        begin end begin begin end end
        begin end
        begin begin end end
        begin begin begin end end end
        begin end begin begin end end
        begin end begin end
        begin begin end begin end begin end end


Comments: This program was motivated by the need for test data
for error repair schemes for block-structured programming lan-
guages. A useful extension to this program would be some
way of generating other text among the parentheses.  In addition
to the intended use of the program, it can produce a variety of
interesting patterns, depending on the strings specified by -l
and -r.

Source code | Program Library Page | Icon Home Page