Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
**Transform the Following Grammar to a Grammar Without Left-Recursive Rules**

Given Grammar:

1. \( S \to A \mid B \)
2. \( A \to AAA \mid a \mid B \)
3. \( B \to BBb \mid b \)

To convert the given grammar to a form without left recursion, the direct left recursion in the rules for \( A \) and \( B \) must be resolved by introducing new non-terminal symbols.

### Explanation of the Original Grammar

The original grammar consists of three production rules. 

- The start symbol is \( S \), which can be replaced with either \( A \) or \( B \).
- The non-terminal \( A \) includes a left-recursive rule \( A \to AAA \), as well as options to replace with \( a \) or \( B \).
- The non-terminal \( B \) contains another left-recursive rule \( B \to BBb \), and can also resolve to \( b \).

### Steps to Remove Left Recursion

For each non-terminal with left recursion, introduce a new non-terminal:

1. **Convert \( A \):**
   - Identify left-recursive and non-left-recursive parts:
     - Left-recursive: \( AAA \)
     - Non-left-recursive: \( a \), \( B \)
   - Introduce \( A' \) to handle left recursion:
     - Convert \( A \) to: \( A \to aA' \mid BA' \)
     - Define \( A' \) with recursive production: \( A' \to AA' \mid \epsilon \)

2. **Convert \( B \):**
   - Identify left-recursive and non-left-recursive parts:
     - Left-recursive: \( BBb \)
     - Non-left-recursive: \( b \)
   - Introduce \( B' \) for left recursion:
     - Convert \( B \) to: \( B \to bB' \)
     - Define \( B' \) with recursion: \( B' \to BbB' \mid \epsilon \)

The resulting grammar will have no left recursion:

1. \( S \to A \mid B \)
2. \( A \to aA' \mid BA' \)
3. \( A' \to AA' \mid \epsilon \)
4. \( B \to bB' \)
5. \(
expand button
Transcribed Image Text:**Transform the Following Grammar to a Grammar Without Left-Recursive Rules** Given Grammar: 1. \( S \to A \mid B \) 2. \( A \to AAA \mid a \mid B \) 3. \( B \to BBb \mid b \) To convert the given grammar to a form without left recursion, the direct left recursion in the rules for \( A \) and \( B \) must be resolved by introducing new non-terminal symbols. ### Explanation of the Original Grammar The original grammar consists of three production rules. - The start symbol is \( S \), which can be replaced with either \( A \) or \( B \). - The non-terminal \( A \) includes a left-recursive rule \( A \to AAA \), as well as options to replace with \( a \) or \( B \). - The non-terminal \( B \) contains another left-recursive rule \( B \to BBb \), and can also resolve to \( b \). ### Steps to Remove Left Recursion For each non-terminal with left recursion, introduce a new non-terminal: 1. **Convert \( A \):** - Identify left-recursive and non-left-recursive parts: - Left-recursive: \( AAA \) - Non-left-recursive: \( a \), \( B \) - Introduce \( A' \) to handle left recursion: - Convert \( A \) to: \( A \to aA' \mid BA' \) - Define \( A' \) with recursive production: \( A' \to AA' \mid \epsilon \) 2. **Convert \( B \):** - Identify left-recursive and non-left-recursive parts: - Left-recursive: \( BBb \) - Non-left-recursive: \( b \) - Introduce \( B' \) for left recursion: - Convert \( B \) to: \( B \to bB' \) - Define \( B' \) with recursion: \( B' \to BbB' \mid \epsilon \) The resulting grammar will have no left recursion: 1. \( S \to A \mid B \) 2. \( A \to aA' \mid BA' \) 3. \( A' \to AA' \mid \epsilon \) 4. \( B \to bB' \) 5. \(
Expert Solution
Check Mark
Step 1

Assume that the set of all A-productions has the form

 

A  $\displaystyle \longmapsto$  A$\displaystyle \alpha_{{1}}^{{}}$  |  A$\displaystyle \alpha_{{2}}^{{}}$  |   ....A$\displaystyle \alpha_{{m}}^{{}}$  |  $\displaystyle \beta_{{1}}^{{}}$  |  $\displaystyle \beta_{{2}}^{{}}$  |   ...  $\displaystyle \beta_{{n}}^{{}}$

 

where no $ \beta_{{i}}^{{}}$ begins with an A and where $ \alpha_{{i}}^{{}}$ $ \neq$ $ \varepsilon$ holds for every i = 1 ... m. Then we replace these A-productions by

 

A $\displaystyle \longmapsto$ $\displaystyle \beta_{{1}}^{{}}$A'  |  $\displaystyle \beta_{{2}}^{{}}$A'  |   ...  $\displaystyle \beta_{{n}}^{{}}$A'
A' $\displaystyle \longmapsto$ $\displaystyle \alpha_{{1}}^{{}}$A'  |  $\displaystyle \alpha_{{2}}^{{}}$A'  |   ...  $\displaystyle \alpha_{{m}}^{{}}$A'  |  $\displaystyle \varepsilon$
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY