如何开始设计自己的编译器 [英] How to start to design own compiler

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

问题描述

我很困惑如何开始设计编译器...

plz给我一些想法如何启动

I am confuse that how to start for designing compiler ...
plz give me some idea how to start

推荐答案

你可以阅读龙书 [ ^ ]然后开始编写自己的编译器,如果你有一年或五年备用或您可以加入像LLVM / Clang这样的项目,并通过为开发中的编译器做贡献来学习。

假设您正在编译C ++,您需要的最小基本组件是: -



用于读写源文件,中间文件和可执行文件的文件系统接口。 Binutils Linux软件包包含用于此目的的二进制文件描述符库,它非常好。



Bo预处理器如Boost :: Wave



一个用于C ++的Lexer和Parser(这被认为是一个很难的部分,你需要阅读和理解龙书以及其他几本才能写出来)



代码生成器,用于获取抽象Sytax树并为目标处理器生成IL或某种形式的汇编语言

语言。



将IL或ASM转换为可执行代码的汇编程序。



将编译单元的输出链接在一起形成可执行模块的链接器。



写下这些中的任何一个都是一项重大成就。好运。
You could read The Dragon Book[^] and then set out to write your own compiler from scratch if you have a year or five to spare or you could join a project like LLVM/Clang and learn by contributing to a compiler in development.
Assuming you''re compiling C++ the minimal basic components you''ll need are:-

A File System interface to read and write source, intermediate and executable files. The Binutils Linux package contains the Binary File Descriptor library for this purpose, It''s very good.

A C preprocessor like Boost::Wave

A Lexer and Parser for C++ ( This is considered a hard part and what you''d need to read and understand the Dragon book and several more in order to write )

A Code generator to take an Abstract Sytax Tree and generate IL or some form of assembly
language for the target processor.

An assembler to turn that IL or ASM into executable code.

A Linker to link together the ouputs of compilation units to form executable modules.

Writing any one of these would be a major achievement. Good Luck.


与所有这些事情一样,Google是一个好的开始: Designing Compiler [ ^ ]

简单搜索为您提供超过400万次点击。

查看一些链接 - 它们几乎肯定会包含您需要的内容。
As with all such things, Google is a good start: Designing Compiler[^]
That simple search gives you over 4 million hits.
Have a look at some of the links - they will almost certainly contain what you need.


编译器设计和构造中常用的两个程序是Lex和YACC 。网上应该有关于它们的大量信息。



[这些在linux世界很流行,我看到你标记了。]
Two programs that are popular for compiler design and construction are "Lex" and "YACC". There should be plenty of info on the web about them.

[These are popular in the linux world, which I see you flagged.]


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

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