The PetitParser UI [1] has the capability to display random examples of a selected production. Unfortunately the UI (and the example generating code) is only available in Smalltalk and hasn't been ported to other host languages. However, you can look at the code here [2] and play with the tool by downloading the one-click distribution [3].
The example generating code is really short and simple (less than 30 lines, the rest is markup from the export). There are a few (hardcoded) heuristics to make it produce a short and readable example. Note that the code ignores logical predicates (! and & expressions). I am not sure, if it is even possible to make them work in a generic case? Either way, I found that ignoring the predicates isn't as bad as it sounds. Predicates are rarely used in practice and do have a big effect on the resulting output (as long as you are aware of it). To summarise, I find the examples quite useful while developing new grammars. It allows one to quickly spot errors or edge-cases that might get missed otherwise. Cheers, Lukas [1] http://scg.unibe.ch/archive/papers/Reng10cDynamicGrammars.pdf (Section 3.5) [2] http://www.lukas-renggli.ch/dropbox/petitparser/libraries/PetitParser-Example.st [3] http://source.lukas-renggli.ch/built/oneclick/PetitParser-OneClick.zip On 4 September 2014 19:54, mathew palsberg <matpalsb...@gmail.com> wrote: > Hello, > I recently built a small language with PEG. I now want to test my language > with random generated(not necessarily meaningful) programs. Does anybody > know a tool that given a PEG grammar, it generates random sequences that > satisfy the given grammar? > > Thanks; > > > _______________________________________________ > PEG mailing list > PEG@lists.csail.mit.edu > https://lists.csail.mit.edu/mailman/listinfo/peg > > -- Lukas Renggli www.lukas-renggli.ch
_______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg