从头开始学习词法扫描和解析

发布于 2024-11-17 03:51:13 字数 98 浏览 0 评论 0原文

我想知道是否有人可以建议实现简单词法分析器和解析器的项目(无需 lex 和 yacc 等工具的帮助),以便我查看源代码。我对这个主题很感兴趣,在此之前我想看看并研究如何手动实现它们。

I was wondering if somebody could suggest projects that implement simple lexers and parsers (without the help of tools like lex and yacc) for me to look at the source. I'm interested in the subject, and before I would like to see and study how they can be implemented manually.

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

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

发布评论

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

评论(3

情感失落者 2024-11-24 03:51:13

《龙》这本书在这方面讲得很好。这是对整个编译器技术的非常深入的了解。这包括关于解析和解析树的很大一部分。

http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools

The Dragon book is very good on this. Its a very in depth look at the entire compiler technology. This includes a large section on parsing and parse trees.

http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools

三生池水覆流年 2024-11-24 03:51:13

访问 antlr.org 并了解 ANTLR 的工作原理。另外,权威 ANTLR 参考绝对物有所值。另外,ANTLR 拥有一个庞大且非常有帮助的用户社区。是的,ANTLR 是一个工具,但你可以查看源代码。从长远来看,开发自己的词法分析器和解析器可能不是您想做的事情,但您当然会编写自己的语法。 ANTLR v3 语法非常好用。

Go to antlr.org and read about how ANTLR works. Also The Definitive ANTLR Reference is definitely worth the money. Plus ANTLR has a large and very helpful user community. Yes ANTLR is a tool but you can look at the source. Developing your own lexers and parsers is probably not something you want to do in the long run but you will, of course, write your own grammars. The ANTLR v3 grammar is very nice to use.

听闻余生 2024-11-24 03:51:13

如果您想查看手写解析器的代码,那么我建议您寻找 gcc 和各种 xml 解析器。您可以从此处开始阅读有关 gcc 架构的内容。在您最喜欢的搜索引擎中输入“xml 解析器源代码”,您将获得大量 xml 解析器示例。如果您对学习如何编写本机解析器库更感兴趣,这不需要额外的代码生成步骤,您可以查看 boost::Spirit (C++) 或 AX (C++0x )。另请检查此表了解各种项目,其中一些提供源代码,但您需要这样做挖掘自己。

If you want to see a code for handwritten parsers then I suggest looking for gcc and various xml parsers. You can start reading from here about gcc architecture. Type "xml parser source code" in your favorite search engine and you will have plenty of examples of xml parsers. If you are more interested in learning how to write native parser libraries, which don't require extra step of code generation, you can look at boost::Spirit (C++) or AXE (C++0x). Also check this table for various projects, some of them offer source code, but you will need to do mining yourself.

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