Starting from:

$30

CS450- Assignment 8 Translating SimpleJS into LambdaJS Solved

Translating SimpleJS into LambdaJS
1. Implement the following translation function from SimpleJS into LambdaJS.

def

J[[x.y]] ==(deref x)["y"]

def

J[[x.y := e]] ==let data = [[e]] in

let o = (deref x) in

x := o["y"] ← data; data

J[[x.y(e···)]]] ==def let m = (deref x)["y"] in

let f = (deref m)["$code"] in f(x,[[e···]])

J[[function(x···) {e}]] ==def alloc {"$code" : λ(this,x···).[[e]],"prototype" : alloc {}}

def

J[[new ef(e···)]] ==let ctor = deref [[ef]] in

let obj = alloc {"$proto" : ctor["prototype"]} in

let f = ctor["$code"] in f(obj,J[[e]]···); obj

def

J[[c]] ==c

def

J[[x]] ==x

def

J[[let x = e1 in e2]] ==let x = [[e1]] in [[e2]]

More products