Consider the following grammar:
S ---> b M b ("S" is the start symbol)
M ---> ( L
M ---> a
L ---> M a )
Use the following shift-reduce table for this grammar:
| b | a | ( | ) | $ |
-----+-----+-----+-----+-----+------+
S | | | | | acc | ( "s" means "shift")
M | s | s | | | |
L | r | r | | | | ( "r" means "reduce")
b | | s | s | | r |
a | r | r | | s | | ( "acc" means "accept")
( | s | s | s | | |
) | r | r | | | |
- Carry out the shift-reduce parse of the following sentence,
showing the stack, current symbol, remaining symbols,
and next action to take at each stage. (This sentence has the
extra artifical symbol $ stuck in at the beginning
and the end.)
$ b ( ( a a ) a ) b $
(Remember that you should initially shift the starting
$ and then shift the next symbol.)
- Give the resulting parse tree.