What is a context-free language?
A context-free language is a set of strings and symbols that follow the rules of a context-free grammar.
What is a context-free grammar (CFG)?
A CFG describes which strings are possible or not possible in a language by defining a set of production rules.
What is a production rule in a CFG? Give examples.
A production rule specifies how one symbol can be replaced by another. Examples:
a → ab (a is replaced by ab)
a → aa (a is replaced by aa)
b → a (b is replaced by a)
What is Backus-Naur Form (BNF)?
BNF is a way of notating context-free languages using statements where the left-hand side is defined by the right-hand side.
What are non-terminals in BNF?
Non-terminals are syntactic variables placed inside angle brackets (e.g. <expr>). They can be broken down further into terminals, other non-terminals, or both.</expr>
What are terminals in BNF?
Terminals are literal symbols (without brackets) that cannot be broken down further and must be taken as written values.
What does the pipe (|) symbol represent in BNF?
It represents the OR operator, allowing alternatives in production rules.
How does recursion work in BNF?
A non-terminal can be defined in terms of itself, allowing recursive definitions. This enables BNF to represent some strings that regular expressions cannot, because regex does not support recursion.
Why is recursion important in BNF?
It allows representation of nested or repeating structures (e.g. balanced parentheses, nested expressions) which cannot be represented by regular expressions.
What is a syntax diagram?
A syntax diagram is a visual representation of a regular language.
Non-terminals are shown as rectangles.
Terminals are shown as ellipses.
Arrows connect shapes to show how strings can be formed.
How is each non-terminal represented in a syntax diagram?
Each non-terminal has its own separate diagram that defines its production rules visually.