So, given that YACC creates a C parser from a given grammar, I thought it would be cool to use the same grammar to generate a generator instead. This program is useful if you want to see examples of strings recognized by a YACC grammar. It can also be used to generate inputs for any program that uses textual input.

So, I wrote generator_generator!

generator_generator - generate a C++ string generator from a grammar Given YACC-like and LEX-like input files, generator_generator is a Perl program that generates a C++ program that generates all strings of a user-specified length. The YACC-like language grammar file provides the grammar productions for string generation, along with optional action blocks that can perform context-sensitive checks in order to limit the generated strings. The LEX-like terminal generator file provides specifications that instruct the program how to generate strings for terminals in the grammar.

If the programmer already has a YACC or Bison parser file, he or she only needs to add "unaction" blocks to allow the recursive generator to undo the side effects of the action blocks. If the programmer already has a LEX or FLEX lexer input file, he or she only needs to remove extraneous code and replace any regular expressions with one of the terminal generator specifications.

This is the first public release. I will soon be moving the development to SourceForge once I find a better name. For now you can find it here.

See the README for installation details. Use "perldoc generator_generator" and "perldoc generator_generator::Tutorial" for documentation.

I'm looking for feedback on the following:

If you happen to try it out, please let me know.
  • Comment on generator_generator: generate a C++ string generator from a grammar

Replies are listed 'Best First'.
•Re: generator_generator: generate a C++ string generator from a grammar
by merlyn (Sage) on Nov 07, 2004 at 14:13 UTC
      I hadn't. The most obvious difference is that I enumerate the strings rather than generate a random one. After taking a quick look, it's also not clear to me that your grammar language supports context-sensitive checks. (e.g. In an sentence grammar, have a check that ensures that the direct object of a sentence can't be the same as the noun if the verb is "distrusts"--i.e. disallow "David distrusts David")
Re: generator_generator: generate a C++ string generator from a grammar
by dimar (Curate) on Nov 07, 2004 at 15:56 UTC

    This is a fun and interesting text analysis project. On a side note, for those who want to expiriment with this type of project straight from perl, the functionality can also be implemented relatively well with array references and a function that chooses random elements therefrom.

    This is an alternative route for those who are unable to install a module like yours or Inline::Spew.

Re: generator_generator: generate a C++ string generator from a grammar
by gaal (Parson) on Nov 07, 2004 at 04:51 UTC
    I think you should call it Hamlet, because obviously it beats a pile of monkeys with typewriters. (Now all you need is an English grammar!)
Re: generator_generator: generate a C++ string generator from a grammar
by halley (Prior) on Nov 09, 2004 at 18:31 UTC
  • I really don't like the name. Anyone have a better one?
    • derivative of inspiration: YACC -> YAGG, or UNYACC, or Resrap
    • pun on inspiration: YACC -> BLABB or SLACC (and then work out a suitable backronym)
    • completely unrelated name: Gengen, Blabber, ...

    --
    [ e d @ h a l l e y . c c ]