COSC 152 Programming Languages
Fall 2006
Homework Assignment #6
Conditionals
Due: Wednesday, Oct 18, 2:00PM CDT
Submit: E-mail electronic
copy to professor, with a subject header "COSC 152 HW#6".
Work may be completed in groups of up to three students. Each group
should submit only once. Be certain to put all team member names on
work submitted. It would be courteous to carbon-copy your team mates
when e-mailing the final submission.
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> ) |
Use the SLLGEN parser generator system to specify your lexical and syntax
rules, and automatically build your parse function.
Modify your existing unparse function to work with the new
abstract syntax and 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.
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