CS计算机代考程序代写 scheme compiler #lang racket

#lang racket

; by First Last

(provide desugar desugar)
(require “utils.rkt”)

;; My implementation defines many functions, for example, I define
;; desugar-let, desugar-letrec*, desugar-improper-lambda, etc… That
;; way, desugar-aux can be uncluttered and can call out to each of the
;; helper functions I define. This is a good way to break up the
;; project. But be mindful: each of your helper functions will likely
;; need to call desugar-aux if you adopt this style.

;; TODO: this function is called by desugar. It wraps the input
;; expression in a let block to allow you (the compiler implementer)
;; to define “builtin” functions that you may then use within the
;; definition here. Note: make sure to name these something like
;; %my-builtin (begins with %), so that they are unlikely to clash
;; with user-defined bindings (e.g., what happens if your translation
;; uses %my-builtin but the user redefines it!?).
(define (desugar-aux e)
(match e
[(? prim? op) ‘todo]
[(? symbol?) e] ;; variables are just themselves
[`(quote ,dat) e]
[`(letrec* ([,xs ,es] …) ,ebody) ‘todo]
[`(letrec ([,xs ,es] …) ,ebody) ‘todo]
[`(let* ([,xs ,es] …) ,ebody) ‘todo]
[`(let ([,xs ,es] …) ,ebody) ‘todo]
[`(let ,loopvar ([,xs ,es] …) ,ebody) ‘todo]
[`(lambda (,xs …) ,ebody) ‘todo]
[`(lambda (,x0 ,xs … . ,xrest) ,ebody) ‘todo]
[`(lambda ,x ,ebody) ‘todo]
[`(if ,ec ,et ,ef) ‘todo]
[`(and ,es …) ‘todo]
[`(or ,es …) ‘todo]
[`(when ,ec ,et) ‘todo]
[`(unless ,ec ,ef) ‘todo]
[`(begin ,es …) ‘todo]
[`(cond ,clauses …) ‘todo]
[`(case ,key ,cases …) ‘todo]
[`(set! ,x ,e) ‘todo]
[`(delay ,e) ‘todo]
[`(force ,e) ‘todo]
;; For this project, you may simply leave call/cc alone, we will
;; be handling it in subsequent projects.
[`(call/cc ,e) `(call/cc (desugar-aux e))]
[`(apply ,ef ,ex) ‘todo]
[`(,(? prim? op) ,es …) ‘todo]
; have to quote all the inner datums, the syntax is ‘#(1 2 3) => (prim vector ‘1 ‘2 ‘3)
[`#(,(? datum? dats) …) ‘todo]
[`(,es …) ‘todo]
[else (error `(unexpected-syntax: ,e))]))

(define/contract (desugar e)
(-> scheme-exp? core-exp?)
(define (wrap e)
`(let*
(
;; TODO: you may want to define functions here that may be
;; then used by code you generate in desugar-aux. For
;; example, my implementation defines (at least)
;; %raise-handler, promise?, and force.
)
,e))
(desugar-aux (wrap e)))

; I, First Last, pledge on my honor that I have not given or
; received any unauthorized assistance on this project.