Try it yourself
Test Resrap's power directly in your browser
A parser...but in reverse
Generate infinitely long procedurally generated code with just a basic grammar, suitable for stress testing linters and parsers, generating realistic sample non copyrighted code for display, or just for playing around with grammar theory
Resrap is a seedable, grammar-based code snippet generator. Instead of parsing code, it generates code from formal grammars — producing endless, realistic-looking (or hilariously nonsensical) snippets.
It works with any language that can be described with a grammar (even English if you like!) and is perfect for:
Resrap now also supports probabilistic and infinitely repeatable grammars via the ABNF (Awesome BNF) format — see full reference.
Resrap reads a grammar and builds a graph of expansions. It then randomly traverses the graph (or deterministically with a seed) to produce snippets that follow the grammar's syntax rules.
"Just a parser… in reverse."
ABNF (Awesome BNF) is a lightweight, custom grammar format designed for the Resrap code generation tool. It extends standard EBNF/BNF with probabilities and infinite generation.
ABNF inherits the basics of EBNF:
function : rules ;
+ One or more repetitions
* Zero or more repetitions
? Optional element
() Grouping
^ Infinite generation - loops back infinitely
Example with infinite generation:
program : function^;
Generates functions endlessly until token limit is reached
ABNF allows specifying weighted probabilities for finer control:
char : a<0.2> | b<0.8>; a : 'A'; b : 'B';
a is chosen 20% of the time, b 80%. Probabilities are normalized automatically.
Probabilities work with all operators:
statement : loop+<0.3> | condition?<0.7>;
Test Resrap's power directly in your browser