# Basic Factor to Javascript compiler

## Chris Double — 2006-12-11 15:51:01

    I wrote a toy compiler, taking a cut down Factor syntax, and compiling

    to Javascript. Details here:

    http://www.bluishcoder.co.nz/2006/12/compiling-factor-to-javascript.html

    The actual instance is online at:

    http://factor.bluishcoder.co.nz/responder/fjsc/

    I haven't implemented many library words yet but some examples that work:

    { 1 2 3 } [ 2 * ] map

    { 1 2 3 } 0 [ + ] reduce

    "hello world!" .

    : fac dup 1 = [ ] [ dup 1 - fac * ] if ;

    5 fac .

    : product 1 [ * ] reduce ;

    { 2 3 4 } product

    5 { 1 2 3 } [ over + ] map

    The compiler is written in Factor and runs on the server. Entering

    data in the textarea does an Ajax call to the server passing it the

    Factor code. It compiles it to Javascript and send it back to the

    browser to be evaluated. The javascript code as well as the stack

    contents is displayed.

    Chris.

    --

    http://www.bluishcoder.co.nz