BNF Flashcards

(12 cards)

1
Q

What is a context-free language?

A

A context-free language is a set of strings and symbols that follow the rules of a context-free grammar.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a context-free grammar (CFG)?

A

A CFG describes which strings are possible or not possible in a language by defining a set of production rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a production rule in a CFG? Give examples.

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Backus-Naur Form (BNF)?

A

BNF is a way of notating context-free languages using statements where the left-hand side is defined by the right-hand side.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are non-terminals in BNF?

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are terminals in BNF?

A

Terminals are literal symbols (without brackets) that cannot be broken down further and must be taken as written values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the pipe (|) symbol represent in BNF?

A

It represents the OR operator, allowing alternatives in production rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does recursion work in BNF?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is recursion important in BNF?

A

It allows representation of nested or repeating structures (e.g. balanced parentheses, nested expressions) which cannot be represented by regular expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a syntax diagram?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How is each non-terminal represented in a syntax diagram?

A

Each non-terminal has its own separate diagram that defines its production rules visually.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly