Resrap

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

Loading Resrap engine...

What is Resrap?

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:

Typing practice with realistic-looking snippets
Stress-testing parsers, syntax highlighters, or linters
Fun exploration of procedural code generation

Resrap now also supports probabilistic and infinitely repeatable grammars via the ABNF (Awesome BNF) format — see full reference.

How?

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.

Why Resrap?

Generate unlimited, realistic code snippets
Avoid copyright issues from using real code
Provide a fun, deterministic, and probabilistic code generator
Give programmers a playground for syntax, speed, and randomness

"Just a parser… in reverse."

ABNF – Awesome BNF

ABNF (Awesome BNF) is a lightweight, custom grammar format designed for the Resrap code generation tool. It extends standard EBNF/BNF with probabilities, infinite generation, and readable word lists.

Quick Revision: EBNF and Grammar

ABNF inherits the basics of EBNF:

function : rules ;

ABNF Operators

+ 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

Probabilities (<...>)

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>;

Word Lists (@words)

Random character classes produce random-looking identifiers. A word list lets a rule emit readable words instead of expanding its grammar:

@words identifier = count, total, index, value, result
@words type       = int, long, double

program: type ' ' identifier ';\n';

Every reference to identifier now emits one of those words. Word-only rules do not need a separate grammar definition, and @keywords is accepted as an alias for @words.

Words can also be attached at runtime with Resrap.AddWords. This is useful when keywords come from another source or need to change per job.

Comments and escapes

Comments

Start a line comment with # or //. Both run to the end of the line.

Escapes

Single-quoted terminals support \n, \t, \r, \\, \', and \".

Character classes support ranges such as [a-z0-9_] plus the common escapes.

Try it yourself

Test Resrap's power directly in your browser

Browse the full language templates →
Loading engine...