Docsity

16 cfg, Exams of Theory of Automata

Partial preview of the text

Download 16 cfg and more Exams Theory of Automata in PDF only on Docsity!

Context-Free Languages

Regular Languages

n n

a b

R

ww

Context-Free Languages

Context-Free Grammars

Example

A context-free grammar :

S

S aSb

SaSbaaSbbaabb

G

A derivation:

S

S aSb

L ( G ) 

{ a b : n  0 }

n n

S

S bSb

S aSa

SaSaabSbaabba

A context-free grammar G :

A derivation:

Example

S

S bSb

S aSa

L ( G ) 

{ ww : w { a , b }*}

R

S

S SS

S aSb

SSSaSbSabSab

A context-free grammar G :

A derivation:

Example

S

S SS

S aSb

in any prefix }

and ( ) ( )

v

n v n v

w n w n w

a b

a b

L ( G ) 

Definition: Context-Free Grammars

Grammar

Productions of the form:

A 

 is string of variables and terminals

G  ( V , T , S , P )

Variables Terminal

symbols

Start

variables

Notation: Context-Free Grammars

  • Lower case letters near beginning of alphabet

(e.g. a, b, c, …) are terminal symbols

  • Upper case letters near beginning of alphabet

(e.g. A, B, C, …) are variables

  • Lower case letters near end of alphabet

(e.g. w, x, …) are strings of terminals

  • Upper case letters near end of alphabet

(e.g. X, Y, …) are either terminals or strings

  • Lower case Greek letters

(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

L

G

L  L ( G )

context-free grammar :

L(G )  {a b : n  0 }

n n

n n

S a b

G

Example:

Since, there is derivation

for any n  0

S  aSb |

since context-free grammar :

L  {a b : n  0 }

n n

G

Example:

is a context-free language

generates L( G )  L

S  aSb |