如何编写编译器 [英] How is a compiler written

查看:77
本文介绍了如何编写编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里可以找到一个很好的资源,在网上,这将给我一个很好的

全面了解如何用C语言编写编译器C或者
$ b $另一种语言。


http://petantik.blogsome。 com - 清醒地看待现实......也许吧?

Where can I find a good resource, on the web, that will give me a good
comprehensive idea of how to write a compiler in C for C or maybe
another language.


http://petantik.blogsome.com - A Lucid look at Reality ... maybe?

推荐答案

嗯,我没有谷歌,但是使用工具lex编写编译器的最好方法是使用工具。

和yacc (或者也称为 - 与某些

差异 - flex和bison),第一个是词法分析器

(扫描仪词法分析器),第二个是解析器。


我相信你可以在网上找到大部分信息,但是如果你真的想要了解b $ b想要学习这个东西,我建议你买龙书,

,正式命名为编译器,原理,技术和工具

by Aho,Sethi和Ullman,这是该领域的事实上的书。

Well, I did not google it, but the best way to write a compiler is
using the tools, "lex" and "yacc" (or also known as - with some
differences - "flex" and "bison"), the first one is a lexer
(scanner-lexical analyzer), and the second one is a parser.

I am sure you can find most of the info in the web, but if you really
want to learn this stuff, I would suggest you to buy the "Dragon Book",
which is formally named "Compilers, Principles, Techniques, and Tools"
by Aho, Sethi and Ullman, this is the de-facto book in the field.


" tuncay tekle" <涂***** @ gmail.com>写道:
"tuncay tekle" <tu*****@gmail.com> writes:
嗯,我没有谷歌,但编写编译器的最好方法是使用工具lex。和yacc (或者也称为 - 具有一些差异 - 弯曲和野牛),第一个是词法分析器(扫描仪 - 词法分析器),第二个是解析器。

我相信你可以在网上找到大部分信息,但如果你真的想要学习这些东西,我建议你买龙书,<由Aho,Sethi和Ullman正式命名为编译器,原理,技术和工具,这是该领域的事实上的书。
Well, I did not google it, but the best way to write a compiler is
using the tools, "lex" and "yacc" (or also known as - with some
differences - "flex" and "bison"), the first one is a lexer
(scanner-lexical analyzer), and the second one is a parser.

I am sure you can find most of the info in the web, but if you really
want to learn this stuff, I would suggest you to buy the "Dragon Book",
which is formally named "Compilers, Principles, Techniques, and Tools"
by Aho, Sethi and Ullman, this is the de-facto book in the field.




我认为你没有密切关注这个新闻组。如果你有
,你现在就知道,假设每个人都可以看到你回复的那篇文章是不安全的,那你就是需要

提供一些上下文。


如果你想通过groups.google.com发布一个后续,不要使用

破损的回复链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。


请向谷歌抱怨他们的界面坏了。


至于原始问题,解析C由于typedef问题,结果很难实现。 typedef名称在词法上是一个标识符,但它的作用类似于保留字 - 但仅限于定义它的

作用域。这意味着你的解析器无法在没有符号表反馈的情况下分析

代码。


一旦你解决了这个问题,你就得到了仍然只完成了实现编译器所需的工作的一小部分。你应该问问自己是否真的值得付出努力,因为它已经是一些免费软件了。我绝对不会说你不应该这样做,

只是这将是一项很大的工作。


还有一个comp.compilers新闻组(您应该在发布之前浏览

a,如果有的话,请阅读常见问题解答)。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



I take it you haven''t been following this newsgroup closely. If you
had, you would know by now that it''s unsafe to assume that everyone
can see the article to which you''re replying, and that you need to
provide some context.

If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

And please complain to Google about their broken interface.

As for the original question, parsing C turns out to be fairly
difficult because of the typedef problem. A typedef name is lexically
an identifier, but it acts like a reserved word -- but only in the
scope where it''s defined. That means your parser can''t analyze the
code without feedback from the symbol table.

Once you''ve solved this, you''ve still done only a fraction of the work
necessary to implement a compiler. You should ask yourself whether
it''s really worth the effort, given that ther are a number of freeware
C compilers already. I''m not by any means saying you shouldn''t do it,
just that it''s going to be a lot of work.

There''s also a "comp.compilers" newsgroup (which you should browse for
a while before posting, and read the FAQ if they have one).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


在文章< 11 ********************** @ z14g2000cwz.googlegroups .com>,

petantik< pe *********** @ gmail.com>写道:
In article <11**********************@z14g2000cwz.googlegroups .com>,
petantik <pe***********@gmail.com> wrote:
我在哪里可以找到一个好的资源,在网上,这将给我一个很好的全面的想法,如何用C语言编写编译器或者
另一种语言。
Where can I find a good resource, on the web, that will give me a good
comprehensive idea of how to write a compiler in C for C or maybe
another language.



http:/ /www.google.com/search?q=0201100886

dave

(如果你不必按照链接知道什么,奖励积分我是

谈论的)


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca

第一个编写可生成可执行文件的编译器的人

出于此目的。

- 在comp.lang.c中的Geoff Summerhayes



http://www.google.com/search?q=0201100886
dave
(bonus points if you don''t have to follow the link to know what I''m
talking about)

--
Dave Vandervies dj******@csclub.uwaterloo.ca
First person to write a compiler that makes an working executable
out of this gets shot.
--Geoff Summerhayes in comp.lang.c


这篇关于如何编写编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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