CPS Transformation
Implement the full CPS transformation studied in class for the Scheme-like
language including the following constructs:
<exp> ::= <varref> varref (var)
| <number> lit (datum)
| (if <exp> <exp> <exp>) if (test-exp then-exp else-exp)
| (proc ({<var>}*) <exp>) proc (formals body)
| (<prim-op> {<exp>}*) prim-app (prim-rator rands)
| (<exp> {<exp>}*) app (rator rands)
| (:= <var> <exp>) varassign (var exp)
| (begin {<exp>}+) begin (exps)
| (let <decls> <exp>) let (decls body)
| (letrec <decls> <exp>) letrec (decls body)
<decls> ::= ({<decl>}*)
<decl> ::= (<var> <exp>) decl (var exp)
Pay special attention to the "begin" clause which requires a specific
treatment, since "begin" does not match the definition of heads/tails
we used to characterize the languages to which the CPS transformation
applies.
The function you must write will be called:
(cps-transform expr)
and it returns a new unparsed expression where the full CPS transformation
has been applied to all the lambda expressions in the expression.