CS 3723/3731 Programming Languages
Spring 2002 -- Review for Mid-Term Exam
Exam is Wednesday, 23 October 2002

Topics: Review Exercise.

  1. 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: 2002-10-21. (Please use ISO 8601, the International Standard.)