Write a context free grammar for every rular language.
Every state is nothing but a rule. If δ(a,qi) = qj
then Ri → aRj
Rj → ϵ if qj ∈ F
And the Context free grammar is
- V = {Rj}
- Σ = Σ
- R given as above
- S is R0
Contd.
Parse to check if Expr.
- Initialise a Stack with $
- Push S to a Stack
- Branch and make stacks every possible rule
- If left most element
Push Down automaton
Defn: It is a Tuple P = (Q, Σ, Γ, δ, q0, F)
- Q is a finite set of “states”
- Σ is a finite set called the alphabet
- Γ is a finite set called the stack alphabet
- q0 ∈ Q is start state
- F⊆Q
- δ: Q × (Σ∪{ϵ}) × (Γ∪{ϵ}) → 𝒫(Q × (Γ ∪ {ϵ})
Example
0N1N
Informal-
- If read a zero, push to stack
- If read a one, pop from stack
- Accept if stack is empty
Formal
Build P = (Q, Σ, Γ, q0, F, δ)