Discovering Handles, Stack - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Discovering Handles, Shift Reduce, Stack, Left string, Parse tree, Uppr Frontier, New Tree Node are basic concepts discussed of course.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekavia
ekavia 🇮🇳

4.3

(58)

241 documents

1 / 29

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Compiler
Construction
Lecture 21
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download Discovering Handles, Stack - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 21

2

Shift-Reduce: The Stack

 Left string can implemented as a stack  Top of the stack is the ►  Shift pushes a terminal on the stack

4

Shift-Reduce: The Stack

 Left string can implemented as a stack  Top of the stack is the ►  Shift pushes a terminal on the stack

5

►int + (int) + (int) $ shift int ► + (int) + (int) $ reduce E → int E ► + (int) + (int) $ shift 3 times E + (int ►) + (int) $ reduce E → int

int

► E stack

(

7

►int + (int) + (int) $ shift int ► + (int) + (int) $ reduce E → int E ► + (int) + (int) $ shift 3 times E + (int ►) + (int) $ reduce E → int

int

E

stack

(

E

8

Discovering Handles

 A bottom-up parser builds the parse tree starting with its leaves and working toward its root

10

int + (int) + (int)

E + (int) + (int)

E + (E) + (int)

E + (int)

E + (E)

int + ( int ) + ( int )

E E^ E

E

11

Discovering Handles

 At each step, the parser looks for a section of the upper frontier that matches right-hand side of some production.

13

Discovering Handles

 The critical step is developing an efficient mechanism that finds matches along the tree’s current frontier.

14

Discovering Handles

Formally, the parser must find some substring β, of the upper frontier where

  1. β is the right-hand side of some production A → β, and
  2. A → β is one step in right-most derivation of input stream

16

Discovering Handles

Formally, the parser must find some substring β, of the upper frontier where

  1. β is the right-hand side of some production A → β, and
  2. A → β is one step in right-most derivation of input stream

17

Discovering Handles

 We can represent each potential match as a pair 〈A→β, k 〉, where k is the position on the tree’s current frontier of the right- end of β.

19

Handle Pruning

A bottom-up parser operates by repeatedly locating handles on the frontier of the partial parse tree and performing reductions that they specify.

20

Handles

 The bottom-up parser uses a stack to hold the frontier.  The stack simplifies the parsing algorithm in two ways.