Chapter 4: Syntax Analysis

Bottom up parsing

. Construct a parse tree for an input string beginning at leaves and going towards root OR

. Reduce a string w of input to start symbol of grammar

Consider a grammar

S aABe

A Abc | b

B d

And reduction of a string

a b b c d e

a A b c d e

a A d e

a A B e

S

Right most derivation

S a A B e

a A d e

a A b c d e

a b b c d e

We will now study a general style of bottom up parsing, also known as shift-reduce parsing. Shift-reduce parsing attempts to construct a parse tree for an input string beginning at the leaves (the bottom) and working up towards the root (the top). We can think of the process as one of "reducing" a string w to the start symbol of a grammar. At each reduction step a particular substring matching the right side of a production is replaced by the symbol on the left of that production, and if the substring is chosen correctly at each step, a rightmost derivation is traced out in reverse. For example, consider the grammar

S aABe

A Abc | b

B d

The sentence a b b c d e can be reduced to S by the following steps:

a b b c d e

a A b c d e

a A d e

a A B e

S

These reductions trace out the following right-most derivation in reverse:

S a A B e

a A d e

a A b c d e

a b b c d e