简体   繁体   English

什么是C ++解释器用于?

[英]What are C++ interpreters used for?

I wonder what is the usage of C++ interpreters. 我想知道C ++解释器的用法是什么。 When are they at their best? 他们什么时候处于最佳状态?

Just like ANY interpreted language, they can be used as: 就像任何解释语言一样,它们可以用作:

  • Embedded scripting language 嵌入式脚本语言

  • Shell scripting language Shell脚本语言

As an example, please look at Ch usage: http://en.wikipedia.org/wiki/Ch_interpreter#C.2FC.2B.2B_interpreter 例如,请查看Ch用法: http//en.wikipedia.org/wiki/Ch_interpreter#C.2FC.2B.2B_interpreter

Like any interpreter, I would say there are two uses: 像任何翻译一样,我会说有两种用途:

  • scripting 脚本
  • experimentation 实验

I don't see scripting catching on for C++, the language is too verbose and there are other more viable alternatives there (python/ruby/shell). 我没有看到C ++的脚本编写 ,语言太冗长,还有其他更可行的替代品(python / ruby​​ / shell)。

The experimentation however is very attractive. 然而,实验非常有吸引力。 Being able to test a construct on the side is like writing a small dedicated test. 能够在侧面测试构造就像写一个小的专用测试。 The typical example, for me, is the use of regular expressions (in Python): 对我来说,典型的例子是使用正则表达式(在Python中):

> s = "silly test++/++hello world"
> re.search(pattern, s).groups()

I don't want to execute the whole shebang just for the sake of testing that I did write my pattern correctly (the regex compiles) or that it doesn't capture the block I wanted. 我不想仅仅为了测试我是否正确地编写了我的模式(正则表达式编译)或者它没有捕获我想要的块来执行整个shebang。 A quick test catches most of the errors, and I can go on. 快速测试可以捕获大部分错误,我可以继续。

I suspect most of them will be made just for curiosity and academic research. 我怀疑他们中的大部分都是为了好奇心和学术研究而制作的。

The Advantage of interpreters in general is that you do not need a compiler for a specific platform. 一般来说,解释器的优点是您不需要特定平台的编译器 This way, can run any program on any platform you want - given that there exists an interpreter for that platform. 这样,可以在任何平台上运行任何程序 - 假设该平台存在解释器。

Another benefit of interpreters is that changes of the source code of the interpreted program can be immediately visible to the program, so it makes debugging far easier. 解释器的另一个好处是,解释程序的源代码的更改可以立即被程序看到,因此它使调试变得更加容易。

Interpreters can give you dynamic typing although the C++ has no constructs to make use of it. 解释器可以为您提供动态类型,尽管C ++没有构造可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM