问题
From Wikipedia:
The REPL is commonly misnamed an interpreter. This is a misnomer—many programming languages that use compilation (including bytecode compilation) have REPLs, such as Common Lisp and Python.
From a reply to this post
Interactive interpreters use REPLs. An interpreter is not required to have one. You can run Python, for example, in non-interactive mode (on a file) and it will not use a read-eval-print loop.
I was wondering if REPL [del] always exists [/del] exists only for an interpreter? Does Wikipedia say REPL also exists for a compiler? If yes, how is that like?
Thanks and regards!
By interpreter, I mean the one perform execution immediately after compilation.
回答1:
I'm not sure whether you are asking for the words commonly used or something else.
In any case, a REPL is a Read Eval Print Loop (see first letters). If you have an interpreter that doesn't read your program or doesn't evaluate it (i.e. "understand" what you want it to do and do it) or doesn't print the results anywhere, what good is it?
If you wouldn't see anything at all and it wouldn't hear you it wouldn't do what you want anyway or you only had 1 try you could as well put a rock on the table instead of the computer.
Maybe there could be funny playing-with-words objections like "if it only changes an icon that is displayed, is it really printing?" and such :-) Or "if it isn't reading from the keyboard, is it really reading?". Silly pure philosophy, really.
What's true is that some systems react differently depending on whether you make them read from the keyboard or from a file. I'm not sure what the use of that is, but I guess you could offer help to the human (i.e. command completion etc) when he's actually typing on the keyboard.
Maybe some don't accept more than 1 expression when reading from a file?
I was wondering if REPL always exists for an interpreter?
I guess its a question of the definition of "interpreter". If you take it to mean (in the pragmatic sense) "something that does what I tell it to do", no. How would you tell it if it won't listen?
Does Wikipedia say REPL also exists for a compiler? If yes, how is that like?
Yes, of course. All LISP systems are like that. They feel exactly like an interpreter but stuff just gets magically faster over time as the system learns how you phrase yourself and learns what changes and what doesn't and just compiles what doesn't change to machine code.
Java also does that nowadays, the longer your VM session lasts the more it finds out how to make things faster and if you stop changing things it will eventually end up running the entire program in machine code.
The whole artificial distinction of interpreter/compiler came to be accidentially, that is to say, because of resource constraints back in the day.
回答2:
This maybe not a good answer, just some notes,
JavaScript in IE 6.0 doesn't come with a REPL.
REPL for compilers maybe look like interpreters as well, if the language can be parsed in one time, forward only. The compiler may insert breakpoint after each compiled statement, do the execution until it reaches the breakpoint, then returned back to user, wait for the next input line, and repeat. Finally, all input lines are compiled, and executed as well.
回答3:
REPL stands for Read-Eval-Print-Loop. Both an interpreter and a compiler can be used to do the eval
bit - either have an instance of the interpreter running in the background and feed it the input, or use the compiler to compile incrementally (granted, this takes much more work and some cooperation from the compiler writers, but it's possible, as countless instances show - you generally only compile to bytecode though). The rest is mostly I/O and some glue to keep all the previously entered definitions available for the next commands.
来源:https://stackoverflow.com/questions/5451042/relation-between-repl-interpreter-and-compiler