How to write a simple interpreter in JavaScript