




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























Regular Languages
n n
a b
R
ww
Context-Free Languages
Example
A context-free grammar :
S aSb
S aSb aaSbb aabb
A derivation:
S aSb
{ a b : n 0 }
n n
S bSb
S aSa
S aSa abSba abba
A context-free grammar G :
A derivation:
Example
S bSb
S aSa
{ ww : w { a , b }*}
R
S aSb
S SS aSbS abS ab
A context-free grammar G :
A derivation:
Example
S aSb
in any prefix }
and ( ) ( )
v
n v n v
w n w n w
a b
a b
Definition: Context-Free Grammars
Grammar
Productions of the form:
A
is string of variables and terminals
Variables Terminal
symbols
Start
variables
Notation: Context-Free Grammars
(e.g. a, b, c, …) are terminal symbols
(e.g. A, B, C, …) are variables
(e.g. w, x, …) are strings of terminals
(e.g. X, Y, …) are either terminals or strings
(e.g. α, β, γ, …) are strings of terminals and/or
variables
Definition: Context-Free Languages
A language is context-free
if and only if
there is a grammar with
context-free grammar :
L(G ) {a b : n 0 }
n n
n n
S a b
Example:
Since, there is derivation
for any n 0
S aSb |
since context-free grammar :
L {a b : n 0 }
n n
Example:
is a context-free language
generates L( G ) L
S aSb |