15-212: Principles of Programming

Lecture 22: Grammars and Parsing

In this lecture we continue our discussion of context-free grammars, and demonstrate their role in parsing.

Shift-reduce parsing uses a stack to delay application of rewrite rules, enabling operator precedence to be enforced. Recursive descent parsing is another style that uses recursion in a way that mirrors the grammar productions. Although parser generator tools exist for restricted classes of grammars, a direct implementation can allow greater flexibility and better error handling. We present an example of a shift-reduce parser for a grammar of arithmetic expressions.

Key Concepts

Sample Code

On-line Notes by Robert Harper

Suggested Reading in Programming in Standard ML:

[ CS 15-212 Home page | schedule | language | assignments | handouts ]

Michael Erdmann