0

Compiler VS interpreter in programming language translation, my question here is they say, the interpreter is not converted into machine code. But if that's the case then how is the machine executing the code?

I tried browsing around i found one solution saying that it does nto actually cinverts the code into object code but mearly simulated an illution as such but comverting it into instruction code for itself to execute the code. I am still unclear and lost.

  • Source code `bark`, compiler makes a binary that makes the machine go woof, interpreter goes woof. The machine code that is executed is of the interpreter and it performs the described action itself. – teapot418 Feb 03 '23 at 09:35
  • The machine does not execute the C code. It executes the interpreter code. The interpreter does whatever is needed. – Gerhardh Feb 03 '23 at 09:35
  • Consider a musical score and a player piano. The score is a program in a high level language. The piano is the hardware. An interpreter is a musician who plays the music on the keyboard. If the music is "compiled" into holes on a long roll of paper, the player piano can produce the music by "running the machine language version." Does this help? PS: The musician/interpreter knows how to play various chords. Chords are "high level" semantics.) – Fe2O3 Feb 03 '23 at 09:46
  • VS will have the ability to generate something that runs on top of .NET runtime, meaning that the computer will need to have that installed to execute the program. As opposed to a compiled executable which can run stand-alone. See this https://stackoverflow.com/questions/1564348/is-the-clr-a-virtual-machine – Lundin Feb 03 '23 at 09:57
  • @Lundin You know, I read that sentence as "Compiler vs. interpreter,"... My fault, probably. – Bob__ Feb 03 '23 at 10:14
  • @Bob__ Now that you mention it, it could as well mean that. This is why we shouldn't be using worthless 2-3 letter abbreviations but spell things out. – Lundin Feb 03 '23 at 10:28
  • Please clarify if "Compiler VS interpreter" means "Compiler Visual Studio" or "Compiler Versus" – Lundin Feb 03 '23 at 10:28
  • its versus sorry my bad – Bibin Antony Feb 04 '23 at 07:13

1 Answers1

0

All executed code on a computer is eventually machine code. Thus, the difference between a compiler and interpreter is not if but how/when the translation is done.

A compiler will read the entire source code and translate that into machine code which is stored such that the compiled program can be executed again and again without further involvement of the compiler.

An interpreter will read the source code statement by statement and directly execute machine code corresponding to each statement as it progresses. Therefore, the interpreter is involved each time the program is executed.

nielsen
  • 5,641
  • 10
  • 27