COSC 3410 Programming Languages

Fall 2011

Homework Assignment #9

Assignment and Statements
Due: Monday, Nov 21, 11:00am CST
Submit: Turn in Scheme source files called "hw9.scm" (your interpreter) and "hw9-test.scm" (a Sc hemeUnit 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, extend the grammar from HW #8 with the grammar from Exercise 4.22 EoPL. The total grammar, in summary, should be:
<program>    ::=    <statement>
<statement>    ::=    <identifier> = < expression>
   |    print <expression>
   |    {{<statement>}*(;) }
   |    if <expression> then < statement> else <statement>
   |    while <expression> do <statement>
   |    var {<identifier> = <expression> }*(,) ; <statement>
   |    proc <identifier> ( { <identifier> }*(,) ) <statement>
   |    call <identifier> ( { <expression> }*(,) )
<expr>    ::=    <number>
   |    <symbol>
   |    <boolean>
   |    ( lambda ( {<symbol>}* ) <expr> )
   |    ( <expression> { <expression>}* )
   |    ( if <expr> <expr> <expr> )
   |    ( cond { ( <expr> <expr> ) }* ( else <expr> ) )
   |    ( let ( { ( <id> <expr> ) }* ) <expr> )
   |    ( let* ( { ( <id> <expr> ) }* ) <expr> )
   |    ( letrec ( { ( <id> ( lambda ( { <id> }* ) <expr> ) }* ) <expr> )
   |    ( set! <identifier> <expression> )

With primitive operators add, sub, mul, div, mod, cons, car, cdr, list, empty-list, empty?, equal, lesser, greater, and, or, xor.

Parser

Use the SLLGEN parser generator system to specify your lexical and syntax rules, and automatically build your scan&parse function.

You may modify your existing unparse function to work with the new abstract syntax and scan&parse function, but the introduction of syntax outside of the normal Scheme format will make this more difficult. I encourage you to write an unparse function for your own debugging purposes, but this new function will probably need to rely more on the Scheme display primitive wherever it is impractical to return a list structure for concrete syntax. Your unparse function will not be tested in grading.

Interpreter

Modify your run function to execute programs in the new language. Your existing evaluate and/or value-of functions will still be useful for all of the expressions in the grammar.

Notes:


Back
[Revised 2011 Nov 09 11:35 DWB]