Re:Why I wrote a book about interpreters
by taneq on Thursday December 01, 2016 @05:57PM
(#13084389)
What, then, is the difference between a compiler and an interpreter? Just that the compiler saves its output rather than executing it?
[ Parent
| on HN ]
Re:Why I wrote a book about interpreters
by justinpombrio on Thursday December 01, 2016 @09:01PM
(#13085357)
They have very different outputs. Compilers produce programs, while interpreters produce answers. More specifically, compilers produce programs in another language (stereotypically machine code), while interpreters run your program to get an answer.
If all you have are compilers, you can never run a program. All you can do is convert it between different languages. Fortunately your computer comes with an interpreter built in: you can think of your cpu as an interpreter for machine code, implemented in hardware.
Re:Why I wrote a book about interpreters
by taneq on Thursday December 01, 2016 @09:58PM
(#13085618)
So by this definition, an interpreter is a compiler plus a virtual machine, bundled together?
Re:Why I wrote a book about interpreters
by cestith on Friday December 02, 2016 @05:26PM
(#13092884)
It can be but needn't be. You can evaluate straight from walking your AST. You can also transform from your AST into an output then run the output. Either one is commonly called an interpreter but the former is further to that end of a spectrum.
Re:Why I wrote a book about interpreters
by Patient0 on Thursday December 01, 2016 @06:55PM
(#13084755)
I would define it as: when a compiler operates on its own source code, the resultant compiled compiler executes as fast as the original. When an interpreter evaluates its own source code, the resultant interpreted interpreter is an order of magnitude slower. This definition allows for things like "just in time" compilation, and rules out silly tricks like bundling an interpreter and some source code into an executable image.
Re:Why I wrote a book about interpreters
by SixSigma on Thursday December 01, 2016 @11:08PM
(#13085931)
Until you get to the Forth family
Re:Why I wrote a book about interpreters
by bogomipz on Friday December 02, 2016 @12:41AM
(#13086310)
Why does that change with going to Forth?
Re:Why I wrote a book about interpreters
by SixSigma on Friday December 02, 2016 @07:08AM
(#13087932)
The speed differential. Your basically making a list of jumps into machine code and then jumping in a loop. The interpreter takes your input and turns it into a jump list which it pumps into the loop. You can reuse a jump list by defining it as a new word.
Re:Why I wrote a book about interpreters
by taneq on Thursday December 01, 2016 @09:34PM
(#13085492)
So compilation is idempotent? That's pithy, I like it.
Re:Why I wrote a book about interpreters
by kevin_thibedeau on Thursday December 01, 2016 @07:47PM
(#13085044)
An interpreter controls the entire state of its execution environment. A compiler generates code, passes it over the wall, and hopes for the best.
Re:Why I wrote a book about interpreters
by dougws on Thursday December 01, 2016 @07:26PM
(#13084952)
This is a pretty good blog post (based on a really good paper) that describes the fundamental differences between interpreters and compilers: http://blog.sigfpe.com/2009/05/three-projections-of-doctor-f...
Re:Why I wrote a book about interpreters
by yoz-y on Thursday December 01, 2016 @06:09PM
(#13084492)
For me, the compiler takes input program in language A and spits out the same program in language B. An interpreter goes (more or less) line by line and executes what it reads.
In theory, compilation is reversible, execution is not.
Re:Why I wrote a book about interpreters
by nv-vn on Thursday December 01, 2016 @08:20PM
(#13085197)
Minor nit-pick: an interpreter need not work line-by-line, but rather (more commonly?) AST-node-by-AST-node. This isn't necessarily true for BASIC interpreters or something resembling assembly, but in general the code is represented as a tree of parsed values by the time the interpreter starts running your code.