Backus-Naur Form (BNF) Notation

Q: What does BNF stand for?
A: Backus-Naur Form.

Q: What is BNF used for in computer science?
A: BNF is used to define the grammar and syntax of programming languages.

Q: What are the two main types of symbols in BNF?
A: Terminal symbols and non-terminal symbols.

Q: What is a terminal symbol in BNF?
A: A terminal symbol represents the actual characters or tokens used in the language, like "+", "*", or "5".

Q: What is a non-terminal symbol in BNF?
A: A non-terminal symbol represents a category or structure, like <expression>, that can be further expanded.


🔵 BNF Rules and Structure

Q: How are BNF production rules written?
A: Using ::= to define how a non-terminal can be constructed.
Example:

<expression> ::= <term> | <term> "+" <expression>

Q: What does the vertical bar (|) mean in BNF?
A: It represents an OR option, meaning either one option or another can be chosen.

Q: How would you define a number in BNF?
A:

<number> ::= <digit> | <digit> <number> <digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"


🟣 Syntax Diagrams

Q: What is a syntax diagram?
A: A graphical representation of grammar rules, also called a railroad diagram.

Q: How do syntax diagrams start and end?
A: They have a clear start and end point, with paths showing how symbols are combined.

Q: Why are syntax diagrams useful?
A: They make it easier to visualize complex grammar structures.