A method and apparatus for interpreting and executing a program may include accessing
a program in memory, parsing the program, generating an intermediate representation
equivalent of the program, and executing the intermediate representation by accessing
the program's library of host objects through an interface to the library. The
program may be a JavaScript program embedded in HTML documents in a browser. The
Web browser is programmed to intercept the JavaScript code and pass execution control
over the program to the interpreter engine developed in Java. The parsing component
of the engine validates the JavaScript instructions. The validated instructions
are converted by the code generator component of the engine into an intermediate
representation equivalent in Java code. The interpreter engine accesses the program's
library of host objects through an interface to the library and executes the intermediate
representation to produce the desired results as programmed in the original JavaScript
source program.