Relation between REPL, interpreter and compiler

后端 未结 3 1698
挽巷
挽巷 2021-01-06 08:06

From Wikipedia:

The REPL is commonly misnamed an interpreter. This is a misnomer—many programming languages that use compilation (including byte

相关标签:
3条回答
  • 2021-01-06 08:23

    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.

    0 讨论(0)
  • 2021-01-06 08:32

    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.

    0 讨论(0)
  • 2021-01-06 08:40

    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.

    0 讨论(0)
提交回复
热议问题