Loading in 5 sec....

Simplifications of Context-Free GrammarsPowerPoint Presentation

Simplifications of Context-Free Grammars

- By
**dacey** - Follow User

- 87 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' Simplifications of Context-Free Grammars' - dacey

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

### Simplifications of Context-Free Grammars

### Normal FormsforContext-free Grammars

Prof. Busch - LSU

Substitute

After we remove all the

all the nullable variables disappear

(except for the start variable)

Prof. Busch - LSU

Unit-Productions

Unit Production:

(a single variable in both sides)

Example:

Unit Productions

Prof. Busch - LSU

Prof. Busch - LSU

If there is a derivation

consists of

terminals

Then variable is useful

Otherwise, variable is useless

Prof. Busch - LSU

useless

Variables

useless

useless

useless

useless

useless

useless

A production is useless

if any of its variables is useless

Prof. Busch - LSU

find all variables that can produce

strings with only terminals or

(possible useful variables)

Round 1:

(the right hand side of production

that has only terminals)

Round 2:

(the right hand side of a production

has terminals and

variables of previous round)

This process can be generalized

Prof. Busch - LSU

Find all variables

reachable from

Use a Dependency Graph

where nodes are variables

unreachable

Prof. Busch - LSU

reachable from S

Final Grammar

Contains only

useful variables

Prof. Busch - LSU

Removing All

Step 1: Remove Nullable Variables

Step 2: Remove Unit-Productions

Step 3: Remove Useless Variables

This sequence guarantees that

unwanted variables and productions

are removed

Prof. Busch - LSU

Prof. Busch - LSU

Conversion to Chomsky Normal Form

Example:

Not Chomsky

Normal Form

We will convert it to Chomsky Normal Form

Prof. Busch - LSU

Introduce new variables for the terminals:

Prof. Busch - LSU

Introduce intermediate variable:

Prof. Busch - LSU

From any context-free grammar

(which doesn’t produce )

not in Chomsky Normal Form

we can obtain:

an equivalent grammar

in Chomsky Normal Form

Prof. Busch - LSU

- First remove:
- Nullable variables
- Unit productions

(Useless variables optional)

Prof. Busch - LSU

New variable:

Add production

In productions with length at least 2

replace with

Productions of form

do not need to change!

Prof. Busch - LSU

- Chomsky normal forms are good
- for parsing and proving theorems

- It is easy to find the Chomsky normal
- form for any context-free grammar
- (which doesn’t generate )

Prof. Busch - LSU

- Greinbach normal forms are very good
- for parsing strings (better than Chomsky Normal Forms)

- However, it is difficult to find the
- Greinbach normal of a grammar

Prof. Busch - LSU

Download Presentation

Connecting to Server..