Attribution Non-Commercial (BY-NC)

3 views

Attribution Non-Commercial (BY-NC)

- Theory Of Computation
- Artificial Intelligence
- Cse384 Compiler Design Laboratory Lab Manual
- Question Paper 3 – 2010 Class –
- MCSE-003
- Awesome Combinatorics
- 10.1007@978-3-642-25664-634
- Thuật toán NLP
- Alg. II-9 Notes March 19
- 2018 - Semester 1 - Book 1
- Context Free
- Ast
- XII Maths DPP (27) - Prev Chaps - Area Under Curves - LPP - Differential Equation
- Использование библиотеки анализа кода OpenC++: модификация, улучшение, исправление ошибок
- Temario de Aylf Curso en Iupui
- Model Question Paper
- Discrete Mathematics - Exercises
- Lecture 1
- Obol: Integrating Language and Meaning in Bio-Ontologies
- overview.pdf

You are on page 1of 5

Some of the things we can do are:

1. Get rid of useless symbols | those that do

not participate in any derivation of a terminal

string.

2. Get rid of -productions | those of the form

variable ! .

✦ Well sort of; you lose the ability to

generate as a string in the language.

3. Get rid of unit productions | those of the

form variable ! variable.

4. Chomsky normal form | only production

forms are variable ! two variables and

variable ! terminal.

Useless Symbols

In order for a symbol X to be useful, it must:

1. Derive some terminal string (possibly X is a

terminal).

2. Be reachable from the start symbol; i.e., S )*

X.

Note that X wouldn't really be useful if or

included a symbol that didn't satisfy (1),

so it is important that (1) be tested rst, and

symbols that don't derive terminal strings be

eliminated before testing (2).

Finding Symbols That Don't Derive Any

Terminal String

Recursive construction:

Basis : A terminal surely derives a terminal string.

Induction : If A is the head of a production whose

body is X1 X2 Xk , and each Xi is known to

derive a terminal string, then surely A derives a

terminal string.

Keep going until no more symbols that derive

terminal strings are discovered.

Example

S ! AB j C; A ! 0B j C; B ! 1 j A0; C !

AC j C1.

Round 1: 0 and 1 are \in."

Round 2: B ! 1 says B is in.

1

Round 3: A ! 0B says A is in.

Round 4: S ! AB says S is in.

Round 5: Nothing more can be added.

Thus, C can be eliminated, along with any

production that mentions it, leaving S ! AB;

A ! 0B; B ! 1 j A0.

Finding Symbols That Cannot Be Derived

From the Start Symbol

Another recursive algorithm:

Basis : S is \in."

Induction : If variable A is in, then so is every

symbol in the production bodies for A.

Keep going until no more symbols derivable

from S can be found.

Example

S ! AB; A ! 0B; B ! 1 j A0.

Round 1: S is in.

Round 2: A and B are in.

Round 3: 0 and 1 are in.

Round 4: Nothing can be added.

In this case, all symbols are derivable from S,

so no change to grammar.

Reader has an example where not only are

there symbols not derivable from S, but you

must eliminate rst the symbols that don't

derive terminal strings, or you get the wrong

grammar.

Eliminating -Productions

A variable A is nullable if A )

*

. Find them by a

recursive algorithm:

Basis : If A ! is a production, then A is

nullable.

Induction : If A is the head of a production

whose body consists of only nullable symbols, then

A is nullable.

Once we have the nullable symbols, we can

add additional productions and then throw

away the productions of the form A ! for

any A.

2

If A ! X1 X2 Xk is a production, add all

productions that can be formed by eliminating

some or all of those Xi 's that are nullable.

✦ But, don't eliminate all k if they are all

nullable.

Example

If A ! BC is a production, and both B and C are

nullable, add A ! B j C.

Eliminating Unit Productions

1. Eliminate useless symbols and -productions.

2. Discover those pairs of variables (A; B) such

that A )*

B.

✦ Because there are no -productions, this

derivation can only use unit productions.

✦ Thus, we can nd the pairs by computing

reachablity in a graph where nodes =

variables, and arcs = unit productions.

3. Replace each combination where A ) *

B)

and is other than a single variable by A !

.

✦ I.e., \short circuit" sequences of unit

productions, which must eventually

be followed by some other kind of

production.

Remove all unit productions.

Chomsky Normal Form

0. Get rid of useless symbols, -productions, and

unit productions (already done).

1. Get rid of productions whose bodies are mixes

of terminals and variables, or consist of more

than one terminal.

2. Break up production bodies longer than 2.

Result: All productions are of the form A !

BC or A ! a.

No Mixed Bodies

1. For each terminal a, introduce a new variable

Aa , with one production Aa ! a.

2. Replace a in any body where it is not the

entire body by Aa .

✦ Now, every body is either a single

terminal or it consists only of variables.

3

Example

A ! 0B1 becomes A0 ! 0; A1 ! 1; A ! A0 BA1 .

Making Bodies Short

If we have a production like A ! BCDE, we

can introduce some new variables that allow the

variables of the body to be introduced one at a

time.

A body of length k requires k , 2 new

variables.

Example: Introduce F and G; replace A !

BCDE by A ! BF ; F ! CG; G ! DE.

Summary Theorem

If L is any CFL, there is a grammar G that

generates L , fg, for which each production is

of the form A ! BC or A ! a, and there are no

useless symbols.

CFL Pumping Lemma

Similar to regular-language PL, but you have to

pump two strings in the middle of the string, in

tandem (i.e., the same number of copies of each).

Formally:

8 CFL L

9 integer n

8 z in L, with jz j n

9 uvwxy = z such that jvwxj n and jvxj > 0

8 i 0, uvi wxiy is in L.

Outline of Proof of PL

Let there be a Chomsky-normal-form CFG for

L with m variables. Pick n = 2m .

Because CNF grammars have bodies of no

more than 2 symbols, a string z of length

n must have some path with at least m + 1

variables.

Thus, some variable must appear twice on the

path.

✦ Compare with the DFA argument about a

path longer than the number of states.

4

Focus on some path that is as long as any

path in the tree. In this path, we can nd

a duplication of some variable A among the

bottom m + 1 variables on the path.

✦ Let the lower A derive w and the upper A

derive vwx.

CNF guarantees us that jvwxj n and vx 6=

.

By repeatedly replacing the lower A's tree by

the upper A's tree, we see uvi wxi y has a parse

tree for all i > 1.

✦ And replacing the upper by the lower

shows the case i = 0; i.e., uwy is in L.

Example

L = f0k2 j k is any integerg is not a CFL.

Suppose it were. Then let n be the PL

constant for L.

Consider z = 0n2 . We can write z = uvwxy,

with jvwxj n and jvxj > 0.

Then uvvwxxy is in L. But n2 <

juvvwxxyj n2 + n < (n + 1)2 , so there is

no perfect square that juvvwxxyj could be.

By \proof by contradiction," L is not a CFL.

- Theory Of ComputationUploaded byHameed Lebbai
- Artificial IntelligenceUploaded byKarishma Gautam
- Cse384 Compiler Design Laboratory Lab ManualUploaded byM_Computer
- Question Paper 3 – 2010 Class –Uploaded bySaumil S. Sharma
- MCSE-003Uploaded byAvdesh Maurya
- Awesome CombinatoricsUploaded byklausfuchs
- 10.1007@978-3-642-25664-634Uploaded byLuis Carlos Gonzales Rengifo
- Thuật toán NLPUploaded byAnonymous rsGzBBiqk
- Alg. II-9 Notes March 19Uploaded byrobin smith ccs
- 2018 - Semester 1 - Book 1Uploaded byPeter Bolocelli
- Context FreeUploaded byJohn Le Tourneux
- AstUploaded byYoung Kids Taplin
- XII Maths DPP (27) - Prev Chaps - Area Under Curves - LPP - Differential EquationUploaded byNibha Pandey
- Использование библиотеки анализа кода OpenC++: модификация, улучшение, исправление ошибокUploaded byTanyaZaxarova
- Temario de Aylf Curso en IupuiUploaded byherr_jack
- Model Question PaperUploaded byNaveen Chaubey
- Discrete Mathematics - ExercisesUploaded byfadlallah
- Lecture 1Uploaded byMaria Estrada
- Obol: Integrating Language and Meaning in Bio-OntologiesUploaded byAmrutraj Benahal
- overview.pdfUploaded bytheresa.painter
- 0 Background 1 Standard ModelUploaded bygodwsky
- 0C803967d01Uploaded byAmit K Awasthi
- 10 Maths Ncert Exemplar Exercise 1 4 Question 5Uploaded byAntriksh Gupta
- 2011 MAV Exam 1 SolutionsUploaded byl
- ExempleUploaded bySorin Rotaru
- Section8_1Uploaded bysonti11
- GATE Mathematics Paper-2007Uploaded byRajkumar
- Mdof Examples PresentationUploaded byamadeus135
- handout_2_assignment_1.pdfUploaded byBaNcHo
- Sup and InfUploaded bymauropenagos

- fafl Slides 1Uploaded byatul
- Slides 16Uploaded byashutoshfriends
- Slides 15Uploaded byatul
- Slides 14Uploaded byatul
- Slides 13Uploaded byashutoshfriends
- filelanguage and automata 12Uploaded byashutoshfriends
- filelanguage and automata 11Uploaded byashutoshfriends
- filelanguage and automata10Uploaded byashutoshfriends
- filelanguage and automata 8Uploaded byashutoshfriends
- filelanguage and automata 7Uploaded byashutoshfriends
- filelanguage and automata 6Uploaded byashutoshfriends
- filelanguage and automata 5Uploaded byashutoshfriends
- filelanguage and automata 4Uploaded byashutoshfriends
- filelanguage and automata 3Uploaded byashutoshfriends
- filelanguage and automataUploaded byashutoshfriends
- Pumping CflUploaded byashutoshfriends

- Ebonics DebateUploaded byGisela Ortega
- Miskonsepsi NyeriUploaded byMaulynda Arifah R
- Paula LatestUploaded bymarleiman
- specific learning disability research paperUploaded byapi-259980544
- Experiment 1 - Scientifc InquiryUploaded bycndc
- 4th sp math contractUploaded byapi-262281498
- antonym lpUploaded byapi-252410182
- math_anxiety_material.pdfUploaded byChristian Calma
- Marked Loss in Qur'an TranslationUploaded byMohammed Fahad Mohammed Firoz
- Covert and Overt ApproachUploaded byWanfadzleen Wannoryuhaidi
- Weisbord HandoutUploaded byzv0183
- classroom observation checklist.docxUploaded byAbe Joy S Isaran
- final 4 class roomsUploaded byapi-302785155
- Andy Basoka Iskandar TE. 090308Uploaded byAbi Sabil
- Kurki, 2006Uploaded byClara Costa
- Exclamative Clauses in EnglishUploaded byiibanez
- Fordham, Jung and the SelfUploaded bygrizcc
- Grendel Explications.docxUploaded byM0nster5
- Valuing Internal Communication; Management and Employee PerspectivesUploaded byKevin Ruck
- organization developmentUploaded byAde Indah Febriani Akmayulinari
- Hyland, Drew - Questioning Platonism [Continental Interpretations of Plato]Uploaded byEdy G. Silva
- Nursing ProcessUploaded byRobelita Negradas Varona
- Developmental Reading StagesUploaded byArisPet Angeli Aranzado Suarez
- Improving Phrase-based Myan to EngUploaded byAnonymous xOqiXnW9
- SpellingUploaded bycassquast
- Simondon MEOT Part 1Uploaded byDiego Matias Asenjo Muñoz
- outcome 6Uploaded byapi-280658167
- ep ipr9 strong voice precise praise participant guide finalUploaded byapi-326266271
- teaching practice 3 iere lesson planUploaded byapi-298948027
- Grow ModelUploaded byOana Mihaela