[antlr-interest] Antlr grammar for regular expressions

Randall R Schulz rschulz at sonic.net
Tue Jul 31 08:02:58 PDT 2007


On Tuesday 31 July 2007 07:32, srđan bejaković wrote:
> I'm trying to write an engine that goes the other way, meaning it
> generates strings that conform to a regular expression (for
> populating data files for testing).

I've done this once, long ago. In C.

You'll want to be sure to only allow finite DFAs. Any with unbounded 
closures will generate a (countably) infinite number of strings, of 
course.

If for some reason you need to do this, then you'll need to create an 
API that allows the client to pull successively synthesized strings 
rather than precompute them into a collection. A stream-oriented 
interface might work, if it's based on a flow-controlled model.


Randall Schulz


More information about the antlr-interest mailing list