# How does interpreting a script work?

Suppose I have a script (.vbs, for example) that is stored in a file. How does the code in the file get converted into machine instructions? What is between the vbs file and the processor?

-

"Scripting" languages are typically interpreted, not compiled. That means that there will be a program called the "interpreter" for that language, which reads the programs written in the language, and executes them. You can start reading about interpreters from the Wikepedia entry:

http://en.wikipedia.org/wiki/Interpreter_(computing)

A compiler, on the other hand, translates a program in the programming language into machine language, and lets the CPU execute the machine language program. The only reason for compiling instead of interpreting is for speed. The CPU can typically execute the translated machine language program about 10-100 times faster than any interpreter. The reason is that the CPU is implemented in hardware. Otherwise, there is nothing that a CPU can do that a program can't.

Interpreted programs runs slow as compared to compiled ones due to the difference in execution process.

Scripting languages are usually used for expressing high-level operations. For such things, the speed advantage of the CPU becomes much less significant. So, interpreting them can be competitive to compiling them.

-
These days some scripting languages are compiled on-the-fly to bytecodes of an internal VM. –  Dave Clarke Feb 21 '13 at 9:48
There are very few, if any, "pure" interpreters, in the sense that they execute the text file provided by the programmer directly. Even 8-bit interpreted BASIC tokenised keywords first. –  Pseudonym Nov 6 '14 at 0:11

That depends on a lot of factors. If it is a pure interpreter (like most shells), the interpreter reads each line/instruction, analyzes it, and executes it. If it is a pure compiler, the program (or a part of it) is read in, analyzed, and then the machine language is written out to run later. Many programming languages are implemented by compiling into a fake machine language (like Java's Virtual Machine; Python and Perl does so too, but not so overtly), and the fake machine language is then interpreted.

This is a vast area, to get an idea of how a real compiler works a good introduction is Fraser and Hanson's "A Retargetable C Compiler: Design and Implementation", the full code of the compiler is available.

-
Thank you Von. Does the interpreter for a *.vbs file come with the the windows OS? Because if I create a *.vbs file on my machine and double click it, it works. And I did not install any interpretor. –  developer747 Feb 20 '13 at 15:07
@developer747: Yes, a VB Script interpreter comes with Windows. –  reinierpost Feb 21 '13 at 12:54