2

Compiled languages like C# and java, have just in time compilers, that convert them (from byte code) into machine code (0s and 1s). How does an interpreted language like VBScript get converted into machine code? Is it done by the operating system?

developer747
  • 15,419
  • 26
  • 93
  • 147
  • 1
    It's done by vbscript runtime (vbscript.dll) which parses&interprets the code on the fly as it's run, and calls own' internal functions such as alert() (which are already in assembly language). So basically it's like compilation, but during the program' run. – user1227804 Feb 28 '12 at 18:17
  • user1227804, I like your response. Can you please post it as an answer? – developer747 Feb 28 '12 at 18:38

4 Answers4

2

They don't necessarily get converted to machine code (and often don't).

The interpreter for that program runs the appropriate actions according to what the program requires.

Some interpreters might generate machine code (using JIT compilers), others might stick to plain interpretation of the script.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • 1
    How does the processor get instructions? (All work is ultimately done by the processor) Is it that the OS interprets the code and send the appropriate instructions to the processor? – developer747 Feb 28 '12 at 18:34
  • 1
    Not the OS. The interpreter (wscript.exe for example) reads the source script line by line and calls functions to do what the script wants to be done (this is way overly simplified, but it's the idea). The interpreter and the functions it calls are compiled code, like any other compiled program. – Mat Feb 28 '12 at 18:36
  • Ahh..so interpreter is the one that generates the machine code. – developer747 Feb 28 '12 at 18:41
  • 1
    No, it doesn't have to. All the code is already in the interpreter itself, it doesn't need to produce additional machine code (though it can). – Mat Feb 28 '12 at 18:42
  • I think the fairer analogy is that CPU executing machine code is analogous to an interpretor reading regular code. CPU parses each instruction using circuits and sets various state to which other circuits respond to; while an interpretor parses the whole code into an internal object literal notation that it can actually understand without doing text manipulation on it, then it maps the requests to perform stuff to the actual native dispatchers or its own bytecode that has already been compiled by the interpretor's compiler or that will also get interpreted on demand. – Dmytro Jan 22 '17 at 05:12
0

I know this is old, but given that I can't comment (rep), I want to add a clarifying answer:

An interpreter is used to interpret the script (be it VBScript, javascript, python, or any other script) into individual instructions. These instructions can be in the form of machine code or an intermediate representation (that the OS or other program can use). Some interpreters are made for something closer to assembly language and the source code is more or less executed directly.

Most modern scripting languages (eg, Python, Perl, Ruby) are interpreted to an intermediate representation, or to an intermediate representation and into compiled (aka machine, aka object) code. The important distinction (vs compiled languages) is that an interpreter isn't taking an entire body of code and translating its meaning to machine code, it's taking each line at a time and interpreting its meaning as a standalone unit.

Think of this as the difference between translating an entire essay from English to Russian (compiled code) vs taking each sentence in the essay and translating it directly (interpreted code). You may get a similar effect, but the result won't be identical. More importantly, translating an entire essay as a total body of work takes a lot more effort than doing one sentence at a time as a standalone unit, but the whole translation will be much easier for Russian speakers to read than the rather clunky sentence-by-sentence version. Hence the tradeoff between compiling code vs interpreting code.

Source: https://en.wikipedia.org/wiki/Interpreter_(computing), experience

Keith
  • 777
  • 8
  • 27
0

This is the answer I was looking for. Like javascript engine, there used to be a vbscript engine, that converted human readable code to machine code. This vbscript engine is analogous to the JIT compiler in CLR and JVM. Only that it converts directly from human readable code to machine code. As opposed to C# having an intermediate byte code.

developer747
  • 15,419
  • 26
  • 93
  • 147
  • The wikipedia link that you have mentioned in your post has no mention of vb script or vb script engine. I believe you wanted to refer [VBScript wikipedia](https://en.wikipedia.org/wiki/VBScript) – RBT Mar 03 '17 at 01:39
0

Referring to this VB Script wikipedia article,

  1. When VB script is executed in a browser it uses vbscript.dll to interpret VB script.
  2. When VB script file is executed from command-line or a batch file then cscript.exe is used to interpret VB script.
  3. When VB script is used by Windows OS itself for various purposes like showing error message boxes or yellow colored notification messages in the right corner of the task bar then it is interpreted using wscript.exe which is a windows service.
RBT
  • 24,161
  • 21
  • 159
  • 240