Transforming Lisp to C++ -


i working on toy language compiles c++ based on lisp (very small subset of scheme), trying figure out how represent let expression,

(let ((var 10)       (test 12))   (+ 1 1)   var) 

at first thought execute exprs return last 1 returning kill ability nest let expressions, way go representing let?

also, resources on source source transformation appriciated, have googled fing 90 min scheme compiler.

one way expand let treat lambda:

((lambda (var test) (+ 1 1) var) 10 12) 

then, transform function , corresponding call in c++:

int lambda_1(int var, int test) {     1 + 1;     return var; }  lambda_1(10, 12); 

so in larger context:

(display (let ((var 10)                (test 12))            (+ 1 1)            var)) 

becomes

display(lambda_1(10, 12)); 

there lot more details, such needing access lexical variables outside let within let. since c++ doesn't have lexically nested functions (unlike pascal, example), require additional implementation.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -