c++ - 解释器始终可以使用源代码是什么意思?

标签 c++ compiler-construction interpreter

来自 C++ 中的思考 - 卷。 1:

Interpreters have many advantages. The transition from writing code to executing code is almost immediate, and the source code is always available so the interpreter can be much more specific when an error occurs.

粗线是什么意思?
这是否意味着除非整个程序都在内存中,否则解释器无法工作?这意味着我们不能将程序分成模块,然后在需要时解释模块(就像我们对编译器所做的那样)?

如果是,那么这背后的原因是什么?


更新:

来自 C++ 中的思考 - 卷。 1:

Most interpreters require that the complete source code be brought into the interpreter all at once.

那么,现在这是否表明我上面写的是什么?

enter image description here

最佳答案

Does it mean that the interpreter cannot work unless whole of the program is in memory?

没有。整个程序不需要在内存中。这些部分会在需要时加载到内存中。

Means we cannot divide the program into modules and then have the modules interpreted as and when needed (like we do with compilers)?

您可以很好地模块化您的程序。但是当解释器需要时,所需的模块应该是可用的。

还有粗线:源代码始终可用

这意味着它是运行的源代码,即在运行时转换为机器特定指令。 逐行,无需转换为不同的(中间)格式。 (由编译器完成)

来自维基百科:

An interpreter may be a program that uses one the following strategies for program execution:

  1. executes the source code directly
  2. translates source code into some efficient intermediate representation (code) and immediately executes this
  3. explicitly executes stored precompiled code1 made by a compiler which is part of the interpreter system

Efficiency

The main disadvantage of interpreters is that when a program is interpreted, it typically runs more slowly than if it had been compiled. The difference in speeds could be tiny or great; often an order of magnitude and sometimes more. It generally takes longer to run a program under an interpreter than to run the compiled code but it can take less time to interpret it than the total time required to compile and run it. This is especially important when prototyping and testing code when an edit-interpret-debug cycle can often be much shorter than an edit-compile-run-debug cycle.

关于c++ - 解释器始终可以使用源代码是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14037090/

相关文章:

c++ - 命名空间与包含的类同名,gcc 可以,clang 不行

C++:单例类设计(错误:未解析的外部符号)

C++ Double 到 Int 转换复杂化

c++ - 跨 MPI 节点共享内存以防止不必要的复制

c# - 编译简单字符串

c++ - 这是有效的 C++ 吗?

c++ - 编译器如何使用编译器生成的临时文件确定函数所需的堆栈大小?

javascript - 在 Javascript/jQuery 中,如果我将代码压缩到 "one-liners"中,渲染性能会有所不同吗?

c++ - C/C++ 动态加载具有未知原型(prototype)的函数

c++ - 在用 C++ 编写的解释器中处理内置函数的好方法是什么?