tags:

views:

49

answers:

0

I recently finished a project in which I was generating lists of strings, and I was wondering about the best way to do this.

The string generation was context sensitive to determine if it was acceptable(it was a sequence of plays in a game, so you had to know what the last play was)

The way I did it was with a function that was passed the context parameter and the term, and if it was acceptable it recursively continued, if it wasn't it terminated(since no further string could be acceptable.) The function also received a "length" parameter to make sure it terminated eventually

basically this is generating every possible string accepted by a language(of a certain length).

Now, I got this to work, even fairly well and cleanly, but I was wondering if there were a better way to do this. Specifically, would a "state machine" monad work well in generating a context sensitive grammar? or something similar at least? The problem seems to simple to want to fire up something like parsec, are there other structures that are effective in manipulating languages?

Any thoughts would be appreciated.