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) formatsee 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 and infinite generation.

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

Try it yourself

Test Resrap's power directly in your browser

Loading engine...