2. What are Context Free
Grammars?
In FormalLanguageTheory, aContext freeGrammar(CFG)
isaformalgrammar in whicheveryproduction rule isofthe
form
V w
Where Visasinglenonterminal symbolandwisastring of
terminals and/or nonterminals (w canbe empty)
The languagesgenerated bycontext free grammars are
knowsasthe context freelanguages
3. What does CFG
do?
A CFGprovidesasimpleandmathematicallyprecise
mechanismfor describingthe methods bywhichphrasesin
somenatural languageare built from smallerblocks,
capturingthe “blockstructure” ofsentencesin anatural way.
Important features ofnatural languagesyntaxsuchas
agreement andreference isare not the part ofcontext free
grammar , but the basicrecursive structure ofsentences, the
wayin whichclausesnest inside other clauses,andthe wayin
whichlist ofadjectivesandadverbsare swallowed bynouns
andverbsisdescribed exactly.
4. Formal Definition of
CFG
A context-free grammar G is a 4-tuple (V, , R, S), where:
Visafinite set; eachelement v Viscalledanon-terminalcharacterora
variable.
isafinite set ofterminals,disjointfrom , whichmakeup the actual
content ofthe sentence.
R is a finite relation from V to (V U )* , where the asterisk
represents the Kleene star operation.
If (,) R, we write production
is called a sentential form
• S, the start symbol, usedto represent the wholesentence (or
program). It must be anelement of V.
5. Production rule notation
A production rule in Risformalized mathematicallyasapair
(,) , where isanon-terminal and isastring of
variablesandnonterminals; rather than usingordered pair
notation, production rules are usuallywritten usinganarrow
operator with asits left handsideand asits right hand
side: .
I t isallowedfor to be the empty string, andin this caseit is
customaryto denote it byε.Theform εiscalled anε-
production.
6. Context-Free
Languages
•Given a context-free grammar
G = (V,,R, S), the language generated or derived from
G is the set
L(G) = {w :S * w}
A language L is context-free if there is a context-free
grammar G = (V,, R, S), such that L is generated from G.