Compilers (CS362 2002F)

Parsing Expressions

Preliminaries

Summary: In today's lab, you will explore a predictive parser for simple expressions that evaluates expressions while parsing them.

Collaboration: Feel free to work on this lab in pairs or trios.

Turning It In: Save your answers in a plain text file and submit it using the ECA.

Grading: I expect that you will gain more from doing this lab than from me grading this lab. I may simply scan through your answers to see if you had any particularly valuable insights.

Supporting Files:

Background

The file expression.ss contains a predictive parser for simple single-digit expressions that evaluates the expressions as it parses them. You should make a copy of the file and read through it to give yourself some sense of the procedures it contains.

Exercises

1. Load expression.ss in DrScheme. Evaluate a variety of expressions to verify that the evaluate procedure works correctly. You should try expressions that involve precedence and associativity. You should also try erroneous expressions.

2. Update expression.ss to support infix max and min operators. You can choose appropriate characters to represent those operators. You may assume that they have the same precedence and associativity as the additive operators.

3. Update expression.ss to return a Scheme expression equivalent to the infix expression, rather than returning the value of the infix expression. One strategy is to change the portions of the code in which a value is computed. Another is to change operator.

4. Update expression.ss to support numbers with more than one digit. You'll probably need a new procedure to parse numbers.

5. Update expression.ss to support exponentiation. You'll need to add a new nonterminal (e.g., ExpExp) and modify code in a variety of places.

 

History

Monday, 30 September 2002 [Samuel A. Rebelsky]

  • Created.

Tuesday, 1 October 2002 [Samuel A. Rebelsky]

 

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Dec 10 08:53:28 2002.
The source to the document was last modified on Tue Oct 1 08:34:29 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2002F/Labs/lab.05.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Glimmer Labs: The Grinnell Laboratory for Interactive Multimedia Experimentation & Research
glimmer@grinnell.edu