用于编写解析器生成器的在线资源

发布于 2024-08-03 22:17:53 字数 218 浏览 5 评论 0原文

我想编写一个用于教育目的的解析器生成器,并且想知道是否有一些不错的在线资源或教程来解释如何编写一个解析器生成器。类似于 Jack Crenshaw 的“让我们构建一个编译器”。

我想为 LR(1) 语法编写解析器生成器。

我对生成操作和转到表背后的理论有很好的理解,但需要一些资源来帮助我实现它。

首选语言是 C/C++、Java,但其他语言也可以。

谢谢。

I want to write a parser-generator for educational purposes, and was wondering if there are some nice online resources or tutorials that explain how to write one. Something on the lines of "Let's Build a Compiler" by Jack Crenshaw.

I want to write the parser generator for LR(1) grammar.

I have a decent understanding of the theory behind generating the action and goto tables, but want some resource which will help me with implementing it.

Preferred languages are C/C++, Java though even other languages are OK.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不及他 2024-08-10 22:17:53

我同意其他人的观点,龙书是LR解析的良好背景。

如果您对递归下降解析器感兴趣,这个网站是一个非常有趣的学习体验,它引导您构建一个完全独立的编译器系统,可以编译自身和其他语言:

MetaII 编译器教程

这一切都基于 Val Schorre 撰写的一篇令人惊叹的 10 页技术论文:META II:面向语法的编译器编写语言 来自 1964 年的诚实到上帝。早在 1970 年,我就学会了如何构建编译器。当你终于明白编译器如何自我再生时,有一个令人兴奋的时刻......

我认识网站作者我的大学时光,但与网站无关。

I agree with others, the Dragon book is good background for LR parsing.

If you are interested in recursive descent parsers, an enormously fun learning experience is this website, which walks you through building a completely self-contained compiler system that can compile itself and other languages:

MetaII Compiler Tutorial

This is all based on an amazing little 10-page technical paper by Val Schorre: META II: A Syntax-Oriented Compiler Writing Language from honest-to-god 1964. I learned how to build compilers from this back in 1970. There's a mind-blowing moment when you finally grok how the compiler can regenerate itself....

I know the website author from my college days, but have nothing to do with the website.

白况 2024-08-10 22:17:53

如果你想走 python 路线,我会推荐以下内容。

我发现这两者都非常有帮助,并且 pyparsing 的作者 Paul McGuire 非常擅长在您遇到问题时帮助您解决问题。 《Python 中的文本处理》一书只是一本方便的参考资料,可帮助您在尝试构建解析器时进入正确的思维框架。

我还想指出,面向对象语言更适合作为语言解析引擎,因为它是可扩展的,并且多态性是正确的方法(恕我直言)。从状态机而不是“在 xyz 末尾查找分号”的角度来看待问题将表明您的解析器最终会变得更加健壮。

希望有帮助!

If you wanted to go the python route I would recommend the following.

I have found both of these to be extremely helpful and Paul McGuire the author of pyparsing is super at helping you out when you run into problems. The book Text Processing in Python is just a handy reference to have at your finger tips and helps get you into the right frame of mind when attempting to build a parser.

I would also point out that an OO language is better suited as a language parsing engine because it's extensible and polymorphism is the right way to do it (IMHO). Looking at the problem in terms of a state machine rather than "Look for a semicolon at the end of xyz" will demonstrate that your parser becomes much more robust in the end.

Hope that Helps!

花开半夏魅人心 2024-08-10 22:17:53

不是真的在线,但是龙之书对LR有相当详细的讨论解析。

Not really online, but the Dragon Book has fairly elaborate discussions of LR parsing.

十级心震 2024-08-10 22:17:53

我发现在学习编写 LR 解析器之前学习编写递归下降解析器更容易。老实说,在编写解析器多年之后,我从未发现有必要编写 LR 解析器。

我最近在 CodeProject 上编写了一篇教程,名为 在 C# 4.0 中实现编程语言工具它描述了递归下降解析技术。

I found it easier to learn to write recursive-descent parsers before learning to write LR parsers. Well to be honest, after many years of writing parsers, I never found it necessary to write an LR parser.

I've recently written a tutorial at CodeProject called Implementing Programming Language Tools in C# 4.0 which describes recursive descent parsing techniques.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文