7.0.0.13
2 — S-expressions Transformations
Due Tuesday, 23 Jan; 9:00am
Develop the following syntax transformations and plug them into the simplistic expander from last week’s lecture:
; (cond ; [S-expression1-1 S-expression1-2] ; ... ; [S-expressionN-1 S-expressionN-2]) ; ==> ; (if S-expression1-1 ; S-expression1-2 ; ... ; ... (if S-expressionN-1 ; S-expressionN-2 ; (void)) ... ; ...) ; ; and ; (cond ; [S-expression1-1 S-expression1-2] ; ... ; [S-expression1-1 S-expression1-2] ; [else S-expressionELSE]) ; ==> ; (if S-expression1-1 ; S-expression1-2 ; ... ; ... (if S-expressionN-1 ; S-expressionN-2 ; S-expressionELSE) ; ...) ; (case S-expression0 ; [Variable1 S-expression1] ; ... ; [VariableN S-expressionN]) ; ==> ; (let ((temporary-variable S-expression0)) ; (cond ; [(symbol=? temporary-variable Variable1) ; S-expression1] ; ... ; [(symbol=? temporary-variable VariableN) ; S-expressionN])) ; (letrec ((Variable1 S-expression1)) ; S-expression1) ; ==> ; (let ((Variable1 ; (Y-by-value-many ; (lambda (Variable1) ; S-expression1)))) ; S-expression1) loop
; (loop Variable0 (Variable1 S-expression1) ; S-expression2) ; ==> ; (letrec ((Variable0 (lambda (Variable1) S-expression1))) ; S-expression2) ; (for/list ((Variable0 S-expression0)) ; S-expression1) The expressions behaves exactly like Racket’s.For this exercise, proceed in two steps. First, develop a target S-expression for this form that performs the desired computation. You may assume that the target language contains empty?, first, rest, and cons. Everything else is something you need to define. Second, develop the transformation from the specified S-expression to the desired target.