Is there a more modern, OO version of “Let's B

2019-03-08 12:14发布

Is there a more modern, maybe object-oriented, equivalent to Jack Crenshaw's "Let's Build a Compiler" series?

A while back I stumbled across "Let's Build a Compiler" and could just not resist writing some code. I wrote a recursive-descent C compiler in C# that output .NET CIL. "Write once, leak everywhere" was my slogan.

Too bad I did not realize until too late that parsing C is a nightmare.

I am now interested in writing a Java compiler in Java that outputs .NET CIL or assemblies with the goal of being self-bootstrapping. I was hoping there might some newer tutorials kicking around.

As an aside, would you spend more time with up-front design or would you just write a ton of tests to support the ability to mercilessly refactor. Thinking back, I am leaning towards the latter. The compiler worked but the code was really awful.

9条回答
我只想做你的唯一
2楼-- · 2019-03-08 12:48

How about Watt & Brown's Programming Language Processors in Java. It demonstrates what OO patterns to use in (simple) compiler design. I used it with C# successfully.

查看更多
淡お忘
4楼-- · 2019-03-08 12:53

I'm a fan of "MiniJava" and associated work based on the "Modern Compiler Implementation in Java" family of books. This doesn't quite meet all the requirements you mention as a MiniJava implementation will, generally, generate native code - but the backend can easily be changed to emit MSIL or whatever.

查看更多
登录 后发表回答