Chapter 4: Syntax Analysis

Example

Assume grammar is E E+E | E*E | id

Parse id*id+id

String
action
.id*id+id
shift
id.*id+id
reduce E id
E.*id+id
shift
E*.id+id
shift
E*id.+id
reduce E id
E*E.+id
reduce E E*E
E.+id
shift
E+.id
shift
E+id.
Reduce E id
E+E.
Reduce E E+E
E.
ACCEPT

Consider the following grammar as an example:

E E + E

| E * E

| id

Detailed steps through the actions of a shift reduce parser might make in parsing the input string "id * id + id" as shown in the slide.