2: Context-free languages and pushdown automata Flashcards
What is a stack?
A linear data structure following a last in, first out (LIFO) ordering. You push items (here, letters) onto the top of the stack before popping them off.
What is a PDA?
A pushdown automaton is a mechanical device that uses a stack data structure to model context-free grammars in theoretical Maths and Computer Science.
How do you define a PDA?
A tuple of 6 items, P = (Q, Σ, Γ, δ, q0, T), where:
Q is a finite set of states
Σ is a finite set compromising the input alphabet; the input to the PDA P must be a word ∈ Σ*
Γ is a finite set compromising the stack alphabet; the word on the stack at any point ∈ Γ*
δ is a nondeterministic transition function following:
δ: Q x ΣЄ x ΓЄ →P(Q x ΓЄ)
q0 is the start state; q0 ∈ Q
T is the set of accept states, so it a subset of Q: T ⊆ Q
When does a PDA accept an input word?
A PDA accepts when each letter in the input word is in the input alphabet or the empty word, the input symbols cause a set of state transitions such that the final state of the PDA is an accepting state (in the set of accepting states, T), and the PDA transitions properly according to its transition function, δ.
If P is a PDA what is the language L(P)?
The language L(P) is the set of all words in Σ* that P accepts; Σ = input alphabet, so Σ* = words that can be made from the input alphabet.
True/false: PDAs recognise all regular languages
True
True/false: PDAs can’t recognise any non-regular languages
False. PDAs can recognise some non-regular languages
How do you use the pumping lemma for context-free languages?
??
True/false: not all finite languages are regular
False; every finite language is regular.
How does a PDA work?
Stack initialised with a symbol to mark end of stack (i.e. empty), usually $. You then iteratively read each symbol in the input word and use the transition function to know which letters (if any) to pop from the stack and push to it, and then which state is transitioned to. If the PDA reaches an invalid branch or computation or halts in a state not in the accept states then it rejects. Otherwise, it can enter an infinite loop or accept, if it terminates in an accept state.
What is a CFG?
Context-free grammars are formal sets of rules defining how to build strings in a language, and thereby the languages themselves. All languages defined by CFGs are accepted by PDAs.
How do CFGs differ from regular expressions?
Rather than being static patterns that allow you to tell whether a word is in a language, CFGs describe how to build up valid words in the language.
How do you define CFGs?
As a tuple of 4 items, (N, Σ, R, S)
N = a finite set of variables
Σ = finite set of terminals; N ∩ Σ = ∅, i.e. no items in both N and Σ
R = finite set of production rules A→w, where A ∈ N and w ∈ (N ∪ Σ)*; A is a variable in N, and w is a variable or terminal in either N or Σ (via the union of the two)
A is the start variable; S ∈ N.
What is a context-free language?
A language (set of possible words generated from an alphabet of symbols) for which there is a CFG equivalent to it.
True/false: a language is context-free if and only if a pushdown automaton recognises it.
True