15-212: Principles of Programming |
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.
[ CS 15-212 Home page | schedule | language | assignments | handouts ]