Recursive generation

One of the many advantages of recursive descent is that it may also be directly used for "recursive generation". Here, the side effects are sent to stdout rather than read in from stdin.

The idea is simple: your productions, instead of saying something like "I am looking for a statement that matches this" instead "I am generating a statement".

I have created a simple Perl program gg.perl which generates a simple list of activities that local business entities might engage in during a business day.

Here's a sample run:

$ perl ./gg.perl
Orders of the day:
==================
ORDER:  Grocer1 pick up apples
ORDER:  Market1 buy bread
ORDER:  Warehouse1 sell asparagus
ORDER:  Market1 buy lettuce
ORDER:  Market1 buy lettuce
ORDER:  Warehouse1 deliver rice
ORDER:  Market2 buy oranges
ORDER:  Market2 pick up asparagus
ORDER:  Grocer1 deliver oranges
ORDER:  Market2 buy oranges
ORDER:  Grocer1 deliver lettuce
ORDER:  Warehouse2 pick up oranges
ORDER:  Grocer1 pick up oranges
ORDER:  Grocer2 deliver rice
ORDER:  Market1 sell celery
ORDER:  Warehouse2 deliver lettuce
ORDER:  Market2 sell oranges
ORDER:  Warehouse1 sell asparagus
ORDER:  Market2 buy oranges
ORDER:  Market2 pick up lettuce
ORDER:  Market1 buy apples
ORDER:  Warehouse1 pick up apples
ORDER:  Warehouse2 sell asparagus
ORDER:  Market1 pick up apples
ORDER:  Grocer1 pick up asparagus
ORDER:  Market1 pick up rice
ORDER:  Warehouse2 sell apples
ORDER:  Grocer1 deliver oranges
ORDER:  Grocer2 buy bread
ORDER:  Grocer2 pick up apples
ORDER:  Market1 buy bread
ORDER:  Market2 buy rice
ORDER:  Warehouse2 sell apples
ORDER:  Warehouse1 buy rice
ORDER:  Warehouse2 buy celery
ORDER:  Warehouse2 buy lettuce
EPSILON

I would like you to rewrite this code in C++ and your choice of one other programming language.

The candidates for these other languages are

While this is a simple assignment in all of the above languages, it's probably simplest using the Scheme family (racket/guile/gauche). It's probably most challenging if you use assembly language (mostly because you are doing random numbers, and that's non-obvious in assembly; fortunately, many modern versions of x86_64 architecture include the RDRAND instruction.) Haskell probably has the most complex (and thorough) random infrastructure, as one might expect.

Please tar together your two programs and a small README.txt to explain how to invoke your code, and submit the tar file on Canvas by 11:59pm on Friday, November 19.

There is a resources page for this exercise.