100% found this document useful (1 vote)
155 views4 pages

Chapter 2 - Left Factoring

The document provides examples of left factoring context-free grammars. Left factoring involves identifying common prefixes in production rules and extracting them to the left side to eliminate duplication. Step-by-step solutions demonstrate left factoring grammars with 2-3 sentences of explanation each.

Uploaded by

Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
155 views4 pages

Chapter 2 - Left Factoring

The document provides examples of left factoring context-free grammars. Left factoring involves identifying common prefixes in production rules and extracting them to the left side to eliminate duplication. Step-by-step solutions demonstrate left factoring grammars with 2-3 sentences of explanation each.

Uploaded by

Abdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

S → iEtS / iEtSeS / a

E→b

Solution-

The left factored grammar is-


S → iEtSS’ / a
S’ → eS / ∈
E→b

Problem-02:

Do left factoring in the following grammar-


A → aAB / aBc / aAc
Do left factoring

A   | 

AX
X|

Solution-

Step-01:

A → aA’
A’ → AB / Bc / Ac
Again, this is a grammar with common prefixes.

Step-02:

A → aA’
A’ → AD / Bc
D→B/c
This is a left factored grammar.

Problem-03:

Do left factoring in the following grammar-


S → bSSaaS / bSSaSb / bSb / a

Solution-

Step-01:

S → bSS’ / a
S’ → SaaS / SaSb / b
Again, this is a grammar with common prefixes.

Step-02:

S → bSS’ / a
S’ → SaA / b
A → aS / Sb
This is a left factored grammar.

Problem-04:

Do left factoring in the following grammar-


S → aSSbS / aSaSb / abb / b

Solution-
Step-01:

S → aS’ / b
S’ → SSbS / SaSb / bb
Again, this is a grammar with common prefixes.

Step-02:

S → aS’ / b
S’ → SA / bb
A → SbS / aSb
This is a left factored grammar.

Problem-05:

Do left factoring in the following grammar-


S → a / ab / abc / abcd

Solution-

Step-01:

S → aS’
S’ → b / bc / bcd / ∈
Again, this is a grammar with common prefixes.

Step-02:

S → aS’
S’ → bA / ∈
A → c / cd / ∈
Again, this is a grammar with common prefixes.

Step-03:

S → aS’
S’ → bA / ∈
A → cB / ∈
B→d/∈
This is a left factored grammar.

Problem-06:

Do left factoring in the following grammar-


S → aAd / aB
A → a / ab
B → ccd / ddc

Solution-

The left factored grammar is-


S → aS’
S’ → Ad / B
A → aA’
A’ → b / ∈

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy