# JS-Interpreter Self-interpreter Demo

The JS-Interpreter can run itself. To run the demo you must first open acorn_interpreter.js, copy the entire file, then paste it at the top of the text area below.

Click Parse, then click Run once and wait a few seconds. Open your browser's console for errors.

// DO THIS FIRST! // PASTE CONTENTS OF acorn_interpreter.js HERE. var code = [ "var result = [];", "function fibonacci(n, output) {", " var a = 1, b = 1, sum;", " for (var i = 0; i < n; i++) {", " output.push(a);", " sum = a + b;", " a = b;", " b = sum;", " }", "}", "fibonacci(16, result);", "alert(result.join(', '));" ].join('\n'); function initAlert(interpreter, globalObject) { var wrapper = function(text) { return alert(arguments.length ? text : ''); }; interpreter.setProperty(globalObject, 'alert', interpreter.createNativeFunction(wrapper)); } myInterpreter = new Interpreter(code, initAlert); myInterpreter.REGEXP_MODE = 1; myInterpreter.run();

Back to the JS-Interpreter documentation.