Project #7: μ;

Submit: Turn in a Scheme source file called hw7.scm using the turnin command on morbius.mscsnet.mu.edu or one of the other Systems Lab machines.

Work is to be completed in teams of two. Be certain to include both teammates names in the file. You may submit multiple times, but only the last turnin will be kept. The automatic submission system will not accept work after the deadline. (If both partners are submitting work to TA-Bot -- which isn't a bad idea to get twice as much automated testing done during the week -- please be sure that one partner overwrites with a blank submission, or at least that the versions are identical. If the TA has to grade two separate versions of the project from a team, she is authorized to enter the lower of the two grades into the gradebook for that team!)

Include a comment block at the very top of each file that contains the following:

  ; COSC 3410 - Project [#]
  ; Explain briefly the functionality of the program.
  ; @authors [your names]
  ; Instructor [your instructor]
  ; TA-BOT:MAILTO [your email addresses]

Your source file should be in the EoPL dialect ("#lang eopl" at top of file) supported by DrRacket, and should not make use of non-standard features like comment boxes that produce an XML file rather than a flat text .scm file.

At the bottom of your hw7.scm, please include the line:

(provide scan&parse run)

The Grammar

Extend your grammar from the previous assignment to include the following new productions:

<program>    ::=    <statement>
    a-program (stmt)
<statement>    ::=    <identifier> = < expression>
    assign-stmt (var rhs)
     |    print <expression>
    print-stmt (exp)
     |    {{<statement>}*(;) }
    compound-stmt (stmts)
     |    if <expression> then < statement> else <statement>
    if-stmt (test-exp then-stmt else-stmt)
     |    while <expression> do <statement>
    while-stmt (test-exp body-stmt)
     |    var {<identifier> = <expression> }*(,) ; <statement>
    block-stmt (vars init-exps body-stmt)

The top level production now states that a program consists of a statement. Statements may include expressions, which are defined by the grammar from the previous assignment. All of the primitive operators defined in the previous assignment should also be in force.

This language is a close relative to the IMPLICIT-REFS language of EoPL Chapter 4, with more familiar Scheme syntax, and a variation on the statement language extensions of exercise 4.22 and 4.25.

Interpreter

Augment your μREC interpreter code from the previous assignment with code from the EXPLICIT-REFS interpreter in EoPL section 4.2, (particularly pages 110-113,) and the IMPLICIT-REFS interpreter in EoPL section 4.3 (particularly pages 118-119,) to interpret the μ; language.

Your interpreter should still be executed with the run function:

run : String → SchemeVal
Usage: (run "pgm") = v, the Scheme value that is the result of running the program "pgm" in your interpreter.
Examples:
> (run "var x = 5; print x")
5
run-complete
> (run "var x = 3; var y = 4;
     print(add x y)"))
7
run-complete
> (run "var x = 3; var y = 4; var z = 0;
     {while (greater x 0) do
      {z = (add z y);
       x = (sub x 1)};
      print z}")
12
run-complete
> (run "var x = 3;
     {print x;
      var x = 4;
       {print x};
     print x}")
3
4
3
run-complete
> (run "var f = (lambda (x y)
      (mul x y));
     var x = 3;
      print(f 4 x)")
12
run-complete

[back]

[Revised 2021 Mar 19 13:54 DWB]