-2

My knowledge of interpreter based languages is that for every time we change the code we don't need to compile it. Compilation will be done at the time of actual execution only. Then why does most of the scripting languages use interpreter's when we usually write script to automate something which we usually doesn't modify.

All the answers seems to be unrelevant of what i was expecting. So let me phrase my question in this way.

Pure interpreter based language : which compiles and executes the code line by line, everytime we execute the code(as of my knowledge).

Then why does scripting languages were developed interpreter based(NOT combination of compiler and interpreter), when we usually execute the same script file everytime(without changing the source code). It would be better if they make it compiler based(or even combination of compiler and interpreter) so that we can compile it once and execute any number of times.

user3436096
  • 129
  • 1
  • 1
  • 8
  • 1
    No - there is **no** compilation - the code is just interpreted .... – marc_s Sep 19 '14 at 04:51
  • Note that the strategy "compile and run" is limiting one, since real programs in general need the ability of self-modifying code. – Boris Stitnicky Sep 19 '14 at 05:23
  • 1
    Read about [just in time compilation](http://en.wikipedia.org/wiki/Just-in-time_compilation) and try [SBCL](http://sbcl.org/), a free software implementation of Common Lisp. See also [LuaJit](http://luajit.org/) – Basile Starynkevitch Sep 19 '14 at 07:15
  • 2
    Because pure intepreters have much lower latency on executing simple sequential code. Why waste time on compiling a bit of code if you'll only run it once? – SK-logic Sep 19 '14 at 08:36
  • @BasileStarynkevitch, thanks for bringing in the correct CS term. – Boris Stitnicky Sep 20 '14 at 08:39

3 Answers3

3

Do not confuse unrelated things together. Firstly, distinguish between a language and its implememntation. A language is given by its syntax + its semantics. A "computer" language (actually, a formally defined language) can be used to express things, such as algorithms, even if there is no known implementation of the invented and described language.

But in practice, the syntax specification is usually done by writing a parser (eg. using yacc) that can be understood by a machine, and semantics specification is done by writing code to be executed upon encoutering particular keywords and other semantic signs. In this way, a typical language creator performs the language specification by writing its first implementation, which then becomes an implicit standard for the language. People do it this way because it's simple, and because if you invent a language and merely publish it as a theoretical paper in a computer science journal, it is not guaranteed that anyone will bother to write its implementation for you.

This doesn't mean that the implementation provided by the language author is the only possible. If the language is well liked, people will attempt to write other implementations including compilers for it. This was eg. the case of Ruby, which was originally written by Yukihiro Matsumoto, but was liked well enough that people wrote a compiler of Ruby for JVM -- JRuby.

Boris Stitnicky
  • 12,444
  • 5
  • 57
  • 74
0

In a compiled language the program, once compiled, is expressed in the instructions of the target machine. In a interpreted language the program instructions are not directly executed by the the target machine, but instead read and executed by some other program (in java its called the JVM). This enables interpreted language to be "Write Once Execute Anywhere".

  • Thanks for your immediate response.But, i think the interpreter you are talking about is "combination of compiler and interpreter". I was asking about the languages where we only have an interpreter( not compiler + interpreter) – user3436096 Sep 19 '14 at 05:01
0

I think your question is based on a false premise. Most scripting-language interpreters of which I am aware will do some amount of "compilation" to an internal form to avoid having to re-parse the source for repeated code (function-calls or loops).

The strings that represent identifiers will usually be interned so that the internal form uses integers that index a string table. Constants will be converted to the machine format. Labels and function-names will be stored (in the internal form) as pointers.

At some point (but the line is very blurry) if the internal form is specified precisely, it can be considered a byte-code format, and the interpreter is then considered a virtual machine. But it is still an interpreter. The microprocessor is still an interpreter for its machine language.

luser droog
  • 18,988
  • 3
  • 53
  • 105