为什么C作为翻译的目标语言? [英] why C as target language of a translator?

查看:81
本文介绍了为什么C作为翻译的目标语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


有谁能告诉我使用C作为源代码编译源的目标语言的优势?

谢谢。

解决方案

假设你谈到一个使用C作为后端语言的编译器(就像早期的C ++编译器那样),那么有几个很好的理由:



  1. C编译器适用于任何平台 - >您可以在任何可用C的平台和架构上使用您的语言
  2. C编译器可以积极优化 - >你不必关心任何寄存器分配,常见的子表达式消除,循环展开等。
  3. C语言比任何专有中间语言更容易理解





缺点是C编译器的附加编译步骤。但是通过上述好处可以轻松平衡学生项目。



干杯

Andi


< BLOCKQUOTE>无。语言翻译(如果机器语言比在口语语言的情况下更多)是复杂的文本操作。对于您使用的语言无动于衷,您将需要文本处理工具,如正则表达式,词法分析器,词典等。这些不是普通老C的亮点。当然,使用C你会做一个小而且可能很快的工具 - 如果你不搞乱它,它可能比C更高的可能性,比如C#例如,如果你必须自己制作文本处理工具。所以一般来说,我会注意推荐C作为第一种方法。 C#中的相同逻辑将是更小且可维护的代码,更快的开发,但是资源消耗更大,并且可能运行得慢得多。

但这只是一种意见。

C在结构和语法方面是一种相当简单的语言。不幸的是,它还缺少许多在现代开发中有用的功能。


Hi Can anyone please tell me the advantage of using C as the target language of a source to source compiler?
Thanks.

解决方案

Assuming you talk about a "compiler" that uses C as a backend language (like the early C++ compilers did), then there are several good reasons for this:


  1. C compilers are available for any platform -> your language is available on any platform and architecture where C is available
  2. C compilers can agressively optimize -> you do not have to care any register allocation, common sub-expression elimination, loop unrolling, etc.
  3. C language is easier to understand than any "proprietary" intermediate language



The cons are the additional compilation step for the C compiler. But that is easily balanced for a student project by the above mentioned benefits.

Cheers
Andi


No. language translation (more in case if the machine languages, than in case of spoken ones) is a complicated text manipulation. Indifferent of what language you use, you will need text processing tools like regular expression, lexers, dictionaries and so on. These are not the highlights of the plain old C. Of course, using C you will make a small and probably fast tool - if you don''t mess it up, which can have a higher likelihood with C, than with C# for example, if you have to make your text processing tools on your own. So in general I would note recommend C for that as first approach. The same logic in C# would be a smaller and maintainable code, faster developement, but larger footprint in resource consumption, and would probably run much slower.
But that''s only one opinion.


C is a fairly simple language in terms of structure and syntax. Unfortunately it also lacks many of the features that are useful in modern development.


这篇关于为什么C作为翻译的目标语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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