Top-Down and Bottom-Up Parsing Techniques, Slides of Compiler Construction

The differences between top-down and bottom-up parsing techniques, including the use of production rules, input matching, and internal state encoding. It also covers the concept of left recursion and its elimination in top-down parsing. Predictive parsing and the use of first sets are also discussed.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekavia
ekavia 🇮🇳

4.3

(58)

241 documents

1 / 62

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Parsing
Techniques
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e

Partial preview of the text

Download Top-Down and Bottom-Up Parsing Techniques and more Slides Compiler Construction in PDF only on Docsity!

Parsing

Techniques

2

Parsing Techniques

Top-down parsers  Start at the root of the parse tree and grow towards leaves.  Pick a production and try to match the input

4

Parsing Techniques

Top-down parsers  Start at the root of the parse tree and grow towards leaves.  Pick a production and try to match the input

5

Parsing Techniques

Top-down parsers  Bad “pick” ⇒ may need to backtrack  Some grammars are backtrack-free.

7

Parsing Techniques

Bottom-up parsers  Start at the leaves and grow toward root  As input is consumed, encode possibilities in an internal state.

8

Parsing Techniques

Bottom-up parsers  Start at the leaves and grow toward root  As input is consumed, encode possibilities in an internal state.

11

Parsing Techniques

Bottom-up parsers  Start in a state valid for legal first tokens  Bottom-up parsers handle a large class of grammars

12

Parsing Techniques

Bottom-up parsers  Start in a state valid for legal first tokens  Bottom-up parsers handle a large class of grammars

14

Top-Down Parser

 A top-down parser starts with the root of the parse tree.  The root node is labeled with the goal symbol of the grammar

15

Top-Down Parsing Algorithm

 Construct the root node of the parse tree  Repeat until the fringe of the parse tree matches input string

17

Top-Down Parsing

 At a node labeled A , select a production with A on its lhs  for each symbol on its rhs, construct the appropriate child

18

Top-Down Parsing

 At a node labeled A , select a production with A on its lhs  for each symbol on its rhs, construct the appropriate child

20

Top-Down Parsing

 When a terminal symbol is added to the fringe and it does not match the fringe, backtrack  Find the next node to be expanded

21

Top-Down Parsing

 The key is picking right production in step 1.

 That choice should be guided by the input string