Take the 2-minute tour ×
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

"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.

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 is competitive to compiling them.

share|improve this answer
    
These days some scripting languages are compiled on-the-fly to bytecodes of an internal VM. –  Dave Clarke Feb 21 '13 at 9:48

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.

share|improve this answer
    
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

Others have already given the answers. For .vbs, windows OS supports it, so even though you havent installed any interpreter, it works.

also .vbs means Visual Basic Script which is actually created by MS.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.