CS 3723/3721 Programming Languages
Shift-Reduce Parser


Overview: Parsers are algorithms and programs that will unravel the syntax of a sentence described by a formal grammar. Most parsers will not handle an arbitrary grammar, but place limitations on the form of grammar allowed. These parsers go through the motions of building a parse tree without actually generating the tree. While the parse is going on, extra code can carry a variety of tasks related to translating the source into some other form.

Initial Recitation work:

What to turn in to the recitation instructor: Turn in answers to the last two a and b items above (those without answers provided).

Key ideas: The shift-reduce parser using a stack is a common strategy. The version shown here is relatively simple, but there are much more sophisticated versions called LR parsers (text, pages 170-174), and LALR parsers (beyond the scope of the course). These parsers are the most capable and are the ones usually employed for real compilers. An LR parser handles the most complex grammar possible using a simple left-to-right scan, and it can determine a syntax error at the earliest possible point.


Revision date: 2003-09-12. (Use ISO 8601, an International Standard.)