Jump to content

What are interpreters?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
What do interpreters do, and how are they different than compilers? Are compilers and interpreters used in Java? I've never heard of an interpreter in any other language, do other languages use them?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
When you write a program, you have instructions that are meant to be read by a human. Your computer doesn't know what they mean. To have your computer do something useful with them, you have three options:

1) compile the program to machine code. This is understood by the computer and can be run. (C, C++, Delphi, and many other languages use this option)

2) compile the program to byte code. This can be understood by a virtual machine that acts as to translate the code into instructions. (Java does this)

3) run the code through an interpreter. This is a special program that knows how to read the code and it executes the code for you. This is similar to using a virtual machine, but you can't hide what your code does from other humans. (scripting languages use this option)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Alright, but how is that different from a compiler? They still both sound like the same thing.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
C++: to run the program foo.cpp you must compile it to foo.exe and run it. If you change foo.cpp you must recompile before you can see the effect of your changes.

Perl: to run the program bar.prl you simply double-click on it, and the Perl interpreter runs your program. If you change bar.prl the changes will be seen the next time you double-click it with no additional action on your part.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Oooooh, the compiler changes it to an executable file but an interpreter can run it as it is. I wish you'd given me that example at first.

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I've had a number of students who wished I'd start with examples before definitions. I've also seen what happens when you start with examples... no clue what I'm talking about.

Keep asking questions, we'll get you through all these ideas :)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Well I'm down with what an interpreter is, don't have any more problems with that.