CS 3723 Programming Languages
Spring 2001 -- Review for Mid-Term Exam
Exam is Wednesday, 21 March 2001

Topics: Review Exercise on Shift-Reduce Parsers:

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  |     |     |      |
  1. 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.)
  2. Give the resulting parse tree.


Revision date: 2001-03-21. (Please use ISO 8601, the International Standard.)