Open In App

What is Handle Pruning?

The handle is the substring that matches the body of a production whose reduction represents one step along with the reverse of a Rightmost derivation.

The handle of the right sequential form Y is the production of Y where the string S may be found and replaced by A to produce the previous right sequential form in RMD(Right Most Derivation) of Y.



Sentential form: S => a here, ‘a’ is called sentential form, ‘a’ can be a mix of terminals and nonterminals.

Example:



Consider Grammar : S -> aSa | bSb | ε
Derivation:              S => aSa => abSba => abbSbba => abbbba

Left Sentential and Right Sentential Form:

Handle contains two things:

Example:  

S -> aABe
A -> Abc | b
B -> d

Steps:

abbcde : γ = abbcde , A->b; Handle = b
aAbcde : γ = RHS = aAbcde , A->Abc; Handle = Abc
aAde : γ = aAde , B->d; Handle = d
aABe : γ = aABe, S-> aABe; Handle = aABe

Note- Handles are underlined in the right-sentential forms.

Is the leftmost substring always handled?

No, choosing the leftmost substring as the handle always, may not give correct SR(Shift-Reduce) Parsing.

Handle Pruning:

Removing the children of the left-hand side non-terminal from the parse tree is called Handle Pruning

A rightmost derivation in reverse can be obtained by handle pruning.

Steps to Follow:

Example 1:

Right Sequential Form Handle Reducing Production
id + id * id id E ⇒ id
E + id * id id E ⇒ id
E + E * id id E ⇒ id
E + E * E E + E E ⇒ E + E
E * E E * E E ⇒ E * E
E (Root)    

Example 2:

Right Sequential Form Handle Production
id + id + id id E ⇒ id
E + id + id id E ⇒ id
E + E + id id E ⇒ id
E + E + E E + E E ⇒ E + E
E + E E + E E ⇒ E + E
E (Root)    
Article Tags :