Grammar rules are applied left-to-right. Each step replaces the leftmost nonterminal with one of its production rules, until only terminals remain.
Start from <program>. Always replace the leftmost nonterminal first. Keep applying rules until the string contains only terminals. This is exactly what a parser does when it validates your code against a grammar.
<X> โ something. It says:
"nonterminal X can become this." Multiple alternatives are separated by | (OR).A โ B as "A
becomes B in one step." Read A โ* B as "A eventually becomes B in
zero or more steps."
| Symbol | Read as | Meaning |
|---|---|---|
| โ | "can be replaced by" | Production rule. <A> โ xyz means nonterminal A can become xyz. |
| โ | "directly derives" | One derivation step. ฮฑ โ ฮฒ means ฮฒ is obtained from ฮฑ by applying one production. |
| โ* | "derives (in 0+ steps)" | Zero or more derivation steps. Used to say "this sentence is in the language." |
| | | "or" | Separates alternatives. <A> โ x | y means A can become x OR y. |
| <name> | "nonterminal name" | Angle brackets signal a nonterminal โ a placeholder not yet resolved to real code. |
| word | "terminal / token" | A literal symbol in the final program. Cannot be expanded. Leaf of the parse tree. |
BNF defines a language's syntax. Click any rule to see what it means and example sentences it generates.
Select any production rule on the left to see its explanation, alternatives, and example strings it can generate.
<name> = nonterminalword = terminalโ = "can be replaced by"
| = OR (alternative)<stmt> โ <var> = <exp>
A statement can be: a variable, then =, then an expression.
<stmt_list> โ <stmt> ; <stmt_list> | <stmt>
Rules can refer to themselves โ this is how grammar generates infinite sentences.
A parse tree shows the hierarchical structure of a derived sentence. Step forward to watch it grow.
Click any paradigm to see its characteristics and a code example.
See how different type systems handle the same operations. Click "Run" to check what happens.
Type known at compile time. Errors caught early.
Type known at runtime. More flexible, errors at runtime.
Illegal conversions cause an error. No implicit coercion.
Types are coerced silently. Can lead to surprising behavior.
Each card will show a code snippet and explain what happens.
Which kind of error is each snippet?
Watch memory regions fill and empty as functions are called. Click each cell for details.
new, malloc)Based on your course material and exam questions. Click an answer to reveal explanation.