[antlr-interest] Random code generator

The Researcher researcher0x00 at gmail.com
Tue May 31 17:50:54 PDT 2011


Hi Arturo,

If you are referening to generating test phrases for input to your parser,
then

Ter did a quick take on this.
http://www.antlr.org/wiki/display/ANTLR3/Random+phrase+generation+using+an+ANTLR+grammar

which will lead you to the RandomPhrase.java in the distribution with the
following note.

NOTE: this does not work well for large grammars...it tends to recurse too
much and build really long strings.

 I did a quick search on the Internet with the requirements that it be open
source, free, documented and produced valid code for a compiler; I found
nothing. That doesn' t mean it doesn't exist, I just didn't find it..

I am currently writing my own, but it is not based on any random seed or
statistics. It is designed to generate fully valid phrases for the grammar.
As a specific example, if I want to test method phrases in a class, the
methods will be wrapped in a class and be capable of being compiled, it
won't be a list of methods that need special code to test. One big caveat
with my program is that the grammar must be converted to BNF, which means
only two operators  ab  or  a | b, no ?, + or *.

Eric


More information about the antlr-interest mailing list