Docsity

Machine Transforms - Computability - Lecture Slide, Slides of Computer Science

Partial preview of the text

Download Machine Transforms - Computability - Lecture Slide and more Slides Computer Science in PDF only on Docsity!

Grammar and Machine

Transforms

Agenda

Grammar Transforms

 Right-linear grammars and regular languages  Chomsky normal form (CNF)  CFG  PDA  Generalized PDA’s

Context Sensitive Grammars

PDA Transforms

 Acceptance by Empty Stack  Pure Push and Pop machines (PPP)  PDA  CFG

Model Robustness

The class of Context free languages is also

robust, as can use either PDA’s or CFG’s to

describe the languages in the class. However,

it is less robust when it comes to slight

perturbations of the model:

Many perturbations are okay (e.g. CNF, or

acceptance by empty stack in PDA’s)

Some perturbations result in different class

 Smaller classes  Right-linear grammars  Deterministic PDA’s  Larger classes  Context Sensitive Grammars

Regular Languages

The DFA above can be simulated by the

grammar

x  0 x | 1y y  0 x | 1z z  0 x | 1z | e

x y z

Regular Languages

x  1 y

x y z x  0 x | 1y y  0 x | 1z z  0 x | 1z | e

Regular Languages

x  1 y  10 x

x y z x  0 x | 1y y  0 x | 1z z  0 x | 1z | e

Regular Languages

x  1 y  10 x  100 x  1001 y

x y z x  0 x | 1y y  0 x | 1z z  0 x | 1z | e

Regular Languages

x  1 y  10 x  100 x  1001 y

 10011 z

x y z x  0 x | 1y y  0 x | 1z z  0 x | 1z | e

Regular Languages

The grammar

x  0 x | 1y y  0 x | 1z z  0 x | 1z | e

Is an example of a right-linear grammar.

DEF: A right-linear grammar is a CFG such that every production is of the form A  uB, or A  u where u is a terminal string, and A,B are variables.

Regular Languages

THM: If N = M = (Q, S, d, q 0 , F ) is an NFA then there is a right-linear grammar G (N ) which generates the same language as N. Proof.

 Variables are the states: V = Q

 Start symbol is start state: S = q

0

 Same alphabet of terminals S

 A transition q

1

 a  q

2 becomes the production

q

1

 aq

2

 Accept states q  F define the e-productions q  e

Accepted paths give rise to terminating

derivations and vice versa. •

Regular Languages

A: Since DFA’s define unique accept paths, each

accepted string must have a unique left

derivation. Therefore, the generated grammar is

unambiguous:

THM: The class of regular languages is equal to

the class of unambiguous right-linear Context

Free languages.

Proof. Above shows that all regular languages are

unambiguous right-linear.

HOME EXERCISE: Show the converse. In

particular, given a right-linear grammar construct

an accepting GNFA for the grammar. •

Regular Languages

Q: Can every CFG be converted into a

right-linear grammar?

Chomsky Normal Form

Even though we can’t get every grammar

into right-linear form, or in general even

get rid of ambiguity, there is an

especially simple form that general

CFG’s can be converted into:

Chomsky Normal Form

Noam Chomsky came up with an especially

simple type of context free grammars which

is able to capture all context free languages.

Chomsky's grammatical form is particularly

useful when one wants to prove certain facts

about context free languages. This is because

assuming a much more restrictive kind of

grammar can often make it easier to prove

that the generated language has whatever

property you are interested in.