作为语言创建工具的C预处理程序的长度/限制是多少?在哪里可以了解更多有关这些的信息? [英] What are the lengths/limits C preprocessor as a language creation tool? Where can I learn more about these?

查看:57
本文介绍了作为语言创建工具的C预处理程序的长度/限制是多少?在哪里可以了解更多有关这些的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bjarne Stroustrup在他的常见问题解答中说:

In his FAQ, Bjarne Stroustrup says:

要构建[Cfront,第一个C ++编译器],我首先用C编写了一个带有类的C"到C的预处理器.C与班级"是一个C语言,成为C ++的直接祖先...然后,我写了第一个版本的在带类的C"中处于Cfront.

To build [Cfront, the first C++ compiler], I first used C to write a "C with Classes"-to-C preprocessor. "C with Classes" was a C dialect that became the immediate ancestor to C++... I then wrote the first version of Cfront in "C with Classes".

当我阅读本文时,它激起了我对 C 预处理器的兴趣.我已经看到它的宏功能适合简化通用表达式,但是我没有想到它的功能可以在我认为将类引入C的水平上显着增加语法和语义.

When I read this, it piqued my interest in the C preprocessor. I'd seen its macro capabilities as suitable for simplifying common expressions but hadn't thought about its ability to significantly add to syntax and semantics on the level that I imagine bringing classes to C took.

所以现在我有一些疑问:

So now I have some questions on my mind:

  1. 是否还有这种方法来将语言从 C 中引导出来?

Stroustrup原始作品的来源在任何地方都可以使用吗?

Is the source to Stroustrup's original work available anywhere?

在哪里可以了解有关使用此技术的详细信息?

Where could I learn more about the specifics of utilizing this technique?

该方法的长度/限制是多少?可以说创建一个预处理器宏集,让某人用Lisp/Scheme这样的东西写东西吗?

What are the lengths/limits of that approach? Could one, say, create a set of preprocessor macros that let someone write in something significantly Lisp/Scheme like?

推荐答案

有关可以使用C预处理程序创建的语言"这种怪异形式的示例,请查看以下头文件:

For an example of the kind of monstrosity of a "language" you can create using the C preprocessor, have a look at this header file:

http://minnie.tuhs.org/cgi-bin/utree.pl?file = V7/usr/src/cmd/sh/mac.h

它来自史蒂夫·伯恩(Steve Bourne)编写的原始Unix shell的源代码,它旨在将C变成类似于Algol的语言.这是一段代码在使用时的外观示例:

It's from the source code of the original Unix shell written by Steve Bourne and it aims to turn C into an Algol like language. Here is an example of what a piece of code looks like when using it:

http://minnie.tuhs.org/cgi-bin/utree.pl?file = V7/usr/src/cmd/sh/args.c

看起来有些奇怪,但它仍然是C.它看起来像是另一种语言,但是由于它是在预处理器中实现的,因此没有语法支持,例如.

That looks kind of bizarre but it is still C. It may look like a different language, but because it is implemented in the preprocessor, there's no syntactic support for it e.g.

WHILE foo
DO
    SWITCH
    ....
    ENDSW
OD

都很好并且可以很好地编译,但是

is all very fine and compiles nicely, but so does

WHILE foo
DO
    SWITCH
    ....
    OD
ENDSW

这篇关于作为语言创建工具的C预处理程序的长度/限制是多少?在哪里可以了解更多有关这些的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆