EBNF Derivation
About this app
Does a word belong to the language? Three grammars from the slides (x⟨X⟩y, addition expressions such as 231+91, Mini-Python): the app derives the word step by step as a leftmost derivation while the derivation tree grows, and its leaves are the word. If the derivation fails, it shows where and what was expected, e.g. character 3 for 5++34, while Python computes 39. Shorthand notations [ ], { }, { }⁺ can be resolved into rules; check your own words.
With explain mode: an AI tutor walks you through the app, points out what matters in the scene and answers your questions.
Deriving means replacing
A grammar in Extended Backus–Naur Form (EBNF) describes which words are well formed. Terminals are the characters of the word; nonterminals such as ⟨Zahl⟩ are replaced according to the rules until only terminals are left. A word belongs to the language if such a derivation exists. The derivation tree shows which rule produced which part: read from left to right, its leaves are exactly the word. For context-free languages it can be decided in finite time whether a word belongs.
What the app shows
On the left are the rules as on the slides, terminals underlined, and below them the leftmost derivation, one sentential form per line. On the right are the word with numbered characters, the verdict and the derivation tree, which grows with every step. If a word does not belong, the app reports the furthest position up to which a derivation fits and what was expected there, for example “character 3: expected ⟨Ziffer⟩, found +”. For every example it also shows what Python does with the text.
Try it yourself
Three grammars are available: ⟨X⟩ ::= x⟨X⟩y for xⁿyⁿ, a grammar for addition expressions such as 231+91, and the expressions of Mini-Python with numbers, identifiers, function calls and conditional expressions. You can enter words of your own. The switch Resolve shorthand notations writes [ ], { } and { }⁺ out as rules of their own; the derivation gets longer, the word stays the same.
Frequently asked questions
- What do { } and { }⁺ mean in EBNF?
- { B } means B may occur zero or more times, resolved ⟨A⟩ ::= ⟨A⟩⟨B⟩ | ⟨ε⟩. { B }⁺ requires at least one B, resolved ⟨A⟩ ::= ⟨A⟩⟨B⟩ | ⟨B⟩. [ B ] stands for an optional B.
- Does ⟨X⟩ ::= x⟨X⟩y produce any sequence of x and y?
- No. Every application of the rule puts an x on the left and a y on the right, so the language is xⁿyⁿ. xxyy belongs, xxy and xyxy do not.
- Is everything Python understands also correct according to the grammar?
- No. Python computes 5++34 as 39 because it reads the second + as a sign; under a grammar without signs 5++34 is not a sum. Conversely the grammar allows 007+1, while Python rejects leading zeros.
- Which grammars can I check in the app EBNF Derivation?
- x⟨X⟩y from the slide EBNF Beispiel, addition expressions such as 231+91, and expressions in Mini-Python. For every word the app shows the verdict, the leftmost derivation, the derivation tree and, where relevant, the error position.
Subject: Computer science
More from Computer science
- Ackermann function
- Call Tree
- Elevator simulator
- Binary workshop
- Binary versus linear search
- The Collatz problem
- Inside a CPU
- Swap the inside
A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps