Grammar Production Lab
Write one named production per line with ::=, quoted literal strings, rule references, | alternatives and explicit ε. The lab parses your test string, shows up to two distinct derivation trees and their leftmost steps, and explores short unique strings generated by the grammar. It rejects direct or indirect left recursion, unsupported PEG/EBNF operators and inputs beyond its stated limits instead of giving a misleading verdict.
Key features
- Edit up to 16 BNF-style rules and 48 alternatives with quoted literal terminals
- Parse a full test string and inspect rule/literal spans in two derivation trees
- Show a furthest failure offset and expected literal when parsing fails
- Detect direct, indirect and nullable-prefix left recursion before parsing
- Generate up to 20 unique short strings and try them against the parser
How to use
- Enter one Name ::= expression rule per line or load the right-recursive example.
- Add a test string and select a bounded rule-expansion depth.
- Run the parser and inspect acceptance, failure position or two ambiguity witnesses.
- Open a tree and follow the leftmost derivation from start rule to literals.
- Click a generated example to parse it or download the complete local JSON report.
Use cases
- Teach how right-recursive productions derive a sequence
- Compare two parse trees for an ambiguous input
- Find an indirect left-recursion cycle before implementing a top-down parser
Frequently asked questions
Is this a full BNF, EBNF or PEG implementation?
No. It is a documented BNF-style subset: quoted strings, rule names, | and explicit ε. Repetition operators, predicates, regular-expression tokens and PEG ordered choice are not accepted. | is unordered grammar alternation, not PEG priority.
What happens with left recursion?
The lab detects direct, indirect and nullable-prefix left-corner cycles and reports the cycle. This bounded top-down parser does not silently reinterpret or support such grammars; a parser generator such as Bison uses a different algorithm.
Does one tree prove the grammar is unambiguous?
No. The tool shows up to two derivations for this input within the selected depth. Two trees prove ambiguity for that input; one found tree does not prove that every input or all deeper derivations are unambiguous.
Are the generated examples a complete language listing?
No. They are unique examples from a bounded breadth-first expansion, with at most 20 results, 24 output characters and a step budget. A truncated indicator appears when a cap stops exploration.
Can an empty string be part of the grammar?
Yes. Write ε as an entire alternative, such as List ::= "a" List | ε. An empty quoted literal or blank alternative is rejected so the intent stays explicit.
Privacy
Grammar and test string stay in browser memory. No user code is evaluated or uploaded; the optional JSON download includes your source and input.
Comments & questions