03-60-440 Principles of Programming Languages (2011 Fall)

School of Computer Science, University of Windsor

 

[Home]

Assignment: Functional programming (4 points+1 bonus mark)

You need to write your program in a file named A1.scm, and send the file as an attachment in your email submission.

Due date: October October 3, 4pm

Please submit to Mr. Iman Rezaeian (Email rezaeia at uwindsor) by email.

Assignment specification

You will define a calculator  for simple arithmetic expressions in scheme. For example, when typing (calculator '( 1 + 2)), scheme interpreter will print 3. The calculator will accept expression of any length, and the expression associates to the right. For example, in (calculator  '(1 + 1 - 2 + 3 ))  the expression is interpreted as (1+ (1 -(2+3))), hence the value is -3.

You can assume that the expressions have + and - operators only. In addition, there are no brackets in expressions.

The syntax for the expression is

exp ::= number | exp op exp
op  ::= +|-

Marking

We will test your program using kawa, since different implmentations may behave differently. In particular, please notice that DrRacket supports different versions of the language. You may use LazyRacket.

If you evaluate the expression using left associativity, you will be awarded with one bonus mark. In your submission please indicate whether it is left associative or right associative.

You can assume that the input is a correct arithmatic expression. We will not test cases like

 
     (calculator '(1 + ))
or
 
     (calculator '(-  1  + 2))

 

Dr. Jianguo Lu   Email: jlu at uwindsor,  Office: LT5111