0

According to Wikipedia an interpreter uses at least one of the following Strategies:

  • Parse the source code and perform its behavior directly;
  • Translate source code into some efficient intermediate representation or object code and immediately execute that;
  • Explicitly execute stored precompiled bytecode made by a compiler and matched with the interpreter Virtual Machine.

So is a program that reads code and executes it directly an interpreter? Does an interpreter need to convert code into binary? Does a compiler need to convert code into binary?

Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
  • 2
    Does this answer your question? [How does an interpreter/compiler work](https://stackoverflow.com/questions/2377273/how-does-an-interpreter-compiler-work) – Adam Millerchip May 28 '22 at 16:32
  • Does this mean a Interpreter can be written using only if statements? Like for example: if B == "print": print( C ) else: print("") – justsomeguytrynasleep May 28 '22 at 17:59

1 Answers1

0

So is a program that reads code and executes it directly an interpreter?

Yes. By definition, an interpreter reads code, then performs what the code tells it to do. Unlike an interpreter, a compiler reads the code then makes an executable file that can be run later.

Does an interpreter need to convert code into binary?

Not always. An interpreter may just read the input code then perform what the code tells it to do, but another type of interpreters use JIT Compilation. Interpreters that use JIT Compilation turn the input code into machine code, but do not make an executable file. Instead, they run the code in memory then throw it away after it has been run. JIT Compilation can be faster than traditional interpreters.

Does a compiler need to convert code into binary?

Yes. In order to create an executable file, a compiler must first read the input code then turn it into something the computer can understand (machine code). This first step is just like JIT Compilation. Unlike JIT Compilation, compilers do not run the machine code it produces, and does not throw it away. Instead, it writes it to a file (called an executable file, or just executable) in a specific format for the OS it is being compiled on. This specific format is why Windows programs cannot run on Linux, and vice-versa.

Michael M.
  • 10,486
  • 9
  • 18
  • 34