如何构建自己的编译器? [英] how to build my own compiler?

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

问题描述

我擅长编程(C,C ++,Java)并且仍然在攻读我的学位。在4-5次实际会话中,我指出了编译器的缺点,我的老师就像你必须构建自己的编译器来解决它。所以我想知道如何建立我自己的编译器?我非常清楚做这种事情并不容易,而且非常耗时,但我想学习那些挑战我的事情。

I'm good at programming(C,C++,Java) and still pursuing my degree. In a practical session 4-5 times I pointed out cons of a compiler and my teachers are like u must build ur own compiler to sort it out. So I winded up on the question HOW TO BUILD MY OWN COMPILER?. I am very well aware that doing that kind of stuff is not easy and is very much time consuming but I want to learn those things that challenge me.

推荐答案

教师是并不总是对的。您对现有编译器的抱怨是什么(或者您是在谈论编程语言)?

您是要为现有语言编写编译器还是要设计自己的语言(然后编写它的编译器)?

如果您打算设计自己的语言,那么读一本书就像节目主持人 [ ^ ]。

此外,您可以使用一些工具来生成编译器(至少在早期阶段快速进行原型设计),例如oldie-goldie bison flex ,或 ANTLR
Teachers are not always right. What are your complaints about existing compilers (or are you talking about programming languages)?
Are you going to write a compiler for an existing language or are you going to design your own language (and then write the compiler for it)?
If you are going to design your own language then could be useful read a book like "Masterminds of programming"[^].
Moreover you could use some tools for generating the compiler (at least for quick prototyping it, at early stages) like the oldie-goldie bison and flex, or ANTLR.


查看我的文章: POLAR - 在.NET中创建虚拟机 [ ^ ]



在其中解释如何在.NET中创建虚拟机以及如何为此类虚拟机创建编译器。 POLAR语言实际上与C#非常相似,但是如果你理解了这个想法,你可以为任何东西创建一个编译器。
See my article: POLAR - Creating a Virtual Machine in .NET[^]

In it I explain how to create a virtual machine in .NET and how to create a compiler for such virtual machine. The POLAR language is actually pretty similar to C#, but if you understand the idea you could create a compiler for anything.


如果有疑问,请从谷歌开始:编写自己的编译器 [ ^ ]



它将引导您: http://编译器。 iecc.com/crenshaw/ [ ^ ]等地方 - 很多其他地方。信息有点过时,但它开始让你了解所涉及的过程和阶段。

一如既往,努力工作不一定是编译器:它是允许编码器的库使用编译器... CSC.EXE是一个相对较小的文件 - 对于.NET 4是1.7Mb - 与框架的其余部分相比,大约35Mb(取决于您的系统)
If in doubt, start with Google: write your own compiler[^]

It will lead you here: http://compilers.iecc.com/crenshaw/[^], among other places - lots of other places. The info is a little dated, but it starts to give you the idea of the processes and stages involved.
As ever, the hard work isn't necessarily the compiler: it's the libraries which allow the coder to use the compiler...CSC.EXE is a relatively small file - 1.7Mb for .NET 4 - compared with a the rest of the framework at around 35Mb (depending on your system)


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

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