Context free grammars Flashcards

1
Q

What is the formal model used to recognize context-free languages?

A

Pushdown Automata.

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

How does the hierarchy of languages progress from least to most expressive?

A

Regular ⊂ Context-Free ⊂ Semi-Decidable.

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

What is the purpose of context-free grammars (CFGs)?

A

To define languages with hierarchical or nested structures that regular languages can’t describe.

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

What is an example of a CFG rule set for simple English-like sentences?

A

S → P V P, P → D N, N → A N, D → a | the, V → holds | eats | observes, N → penguin | balloon, A → happy | little

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

Give an example sentence that a CFG might generate.

A

the happy penguin holds a balloon

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

What is the formal definition of a context-free grammar (CFG)?

A

A 4-tuple G = (Σ, V, R, S), where Σ is the terminal alphabet, V is a set of non-terminals, R is a set of production rules, and S is the start symbol.

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

What does the symbol Σ represent in a CFG?

A

The terminal alphabet (actual symbols in the language).

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

What does the set V represent in a CFG?

A

The non-terminal symbols used for generating structure.

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

What is the role of R in a CFG?

A

The set of production rules (e.g., A → α).

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

What does the symbol S represent in a CFG?

A

The start symbol (a non-terminal from which derivations begin).

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

What is meant by a one-step derivation in a CFG?

A

A string u derives v (u ⇒ v) by applying a single production rule.

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

What does u ⇒* v mean in CFGs?

A

v can be derived from u in zero or more steps.

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

What is L(G) in the context of CFGs?

A

The language generated by grammar G: all strings derivable from S using the rules in R.

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

What is a context-free language (CFL)?

A

A language for which there exists a CFG such that L = L(G).

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

Can regular languages be generated by CFGs?

A

Yes, every regular language is also context-free.

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

Can all context-free languages be recognized by finite automata?

A

No — some context-free languages are not regular.

17
Q

Give an example of a CFG that generates a regular language.

A

S → AB, A → aA | ε, B → bB | ε — generates aⁿbᵐ for n, m ≥ 0

18
Q

Give an example of a CFG that generates a non-regular language.

A

S → aSb | ε — generates aⁿbⁿ for n ≥ 0

19
Q

What kind of structure does the CFG S → aSb | ε capture?

A

Balanced a’s and b’s — matching counts in order.

20
Q

Give an example of a CFG that generates balanced brackets.

A

S → SS | (S) | ε

21
Q

What language does the grammar S → aSc | T | ε

A

T → Tb | ε generate?

22
Q

What kind of languages do CFGs excel at describing?

A

Languages with balanced, nested, or hierarchical patterns.

23
Q

Why can’t some languages like aⁿbⁿ be expressed using DFAs?

A

Because DFAs can’t remember how many a’s to match with b’s — they lack memory.