COSC 3410 Programming Languages
Fall 2011
Homework Assignment #6
Conditionals
Due: Wednesday, Oct 26, 11:00am CDT
Submit: Turn in
Scheme source files called "hw6.scm" (your interpreter) and "hw6-test.scm" (a SchemeUnit testsuite for your interpreter)
using the
turnin command on
the
Systems Lab
machines. Include the names of all authors at the top of the files
in a comment block.
Work may be completed in pairs. Each team should have only one member turnin.
The Grammar
For this assignment, ammend the grammar from
HW #5
to include the following productions:
<expr> |
   ::=    |
( if <bool-expr> <expr>
<expr> ) |
|    |    |
( cond { ( <bool-expr> <expr> ) }*
( else <expr> ) ) |
<bool-expr> |
   ::=    |
#t |
|    |    |
#f |
|    |    |
<compare-expr> |
|    |    |
<logical-expr> |
<compare-expr> |
   ::=    |
( equal <expr> <expr> ) |
|    |    |
( greater <expr> <expr> ) |
|    |    |
( lesser <expr> <expr> ) |
<logical-expr> |
   ::=    |
( and <bool-expr> <bool-expr> ) |
|    |    |
( or <bool-expr> <bool-expr> ) |
|    |    |
( xor <bool-expr> <bool-expr> ) |
Parser
Use the SLLGEN parser generator system to specify your lexical and syntax
rules, and automatically build your
scan&parse function.
Modify your existing unparse function to work with the new
abstract syntax and scan&parse function.
Your scanner specification must now accept Boolean literals "#t"
and "#f"; note that these literals must scan into distinct
tokens, or you will not be able to tell them apart later.
Interpreter
Modify your
evaluate function to operate over the new syntax.
The cond construct should evaluate to only the first expression
that corresponds to a true condition. If none of the clauses has a true
condition, the else clause is always taken to be true.
Notes:
Although our input grammar includes lambda terms and
applications, for now your evaluate function may throw
an error if you encounter a lambda term or an application of
anything other than a primitive operator. Note that this implies
there will be no variable definitions.
Check rigorously for errors in the input, or for invalid expressions.
Appropriate errors should be thrown if your interpreter
encounters any trouble. See the eopl:error construct
used in the text. Think carefully about what kinds of errors the
interpreter can encounter.
Back
[Revised 2011 Oct 12 11:28 DWB]