9. Context-Free Grammars
02/03/23
Chomsky type 3 = regular language - DFA, NFA, RE
Chomsky type 2 = Content-free language(CFL) - Context-free grammars (CFGs), Push-down automata (PDA)
2∗(x+3)
Expressions E
Terms (part of +) T
Factor (part of *) F
Σ={a,∗,+,(,)}
E→T
E→E+T
T→F
T→T∗F
F→a
F→(E)
Can be shorthanded using or (|
) statements
E=>T=>I∗F=>F∗F=>a∗F=>a∗(E)=>a∗(E+T)=>a∗(I+T)=>a∗(F+T)=>a∗(a+T)=>a∗(a+F)=>a∗(a+a)
CFGs are a formalism to define languages that is more general than regular expressions; there are more languages definable by CFGs than by regular expressions and finite automata.
G=(N,Σ,P,S)
N a finite state f non-terminal symbols
Σ (or T) a finite set of symbols (or terminal symbols) N∩Σ=∅
P⊆finN×(N∪˙Σ)∗ - finite set of productions
S:N the start symbol
+∪ = not fresh
=>⊆(N+∪Σ)∗×(N+∪Σ)∗
???
L(G)={w:Σ∗∣S=>∗w}
A CFL is a language given by CFG, L=L(G)
L={anbn∣n:N}
Theorem - Every REG is also a CFL
REG ⊆ CFL