In this assignment you will be working with the simple calculator style compiler (actually, interpreter) available on the course web page. You are to extend the compiler in the following ways:
%
, so that a % b
evaluates to the value k
in the range [0,b)
such that a = rb + k
for some integer r
.
x**
denotes x
squared, x***
denotes x cubed, and so on.
phi
that evaluates to the value of the golden ratio, φ.true
and false
that evaluate to the boolean values true and false, respectively.
|
(or) and &
(and) and ^
(xor).
~
(not)-
(minus)max(x1,x2,...,xn)
and min(x1,x2,...,xn)
that take a variable number of arithmetic expressions as arguments and evaluate to their maximum, respectively, minimum value.
if ( condition ) { expression-list } else { expression-list }or simply
if ( condition ) { expression-list }
a ? b : c
evaluates to b
if a
is true and c
if a
is false.
++a
should have the same effect as (a = a + 1)
.
a++
should have the same effect as (a = a + 1)
, but evaluates to the value of a before the increment takes place. To see the difference, note you should compare the results of the following
a = 5; x = a++; /* Now x = 5 */ a = 5; x = ++a; /* Now x = 6 */
function function-name (arg1, arg2, arg3, ..., argN) { expression-list }A function is called with the syntax
call function-name (arg1, arg2, arg3, ..., argN)A function may be defined anywhere within the main body of the program and can be called from anywhere (even before it is defined). Thus checking whether a non-existent function is being called can only be done once the entire input has been parsed.
Note that the arguments to a function are variables that are local to
that invocation of that function. This means that the execution
environment must contain one stack frame per function that is
currently executing. It will require non-trivial changes to the Environment
class to implement this.