解析,哪里可以学到
我的工作是将一种语言“翻译”成另一种语言。 对于使用正则表达式的简单逐行方法来说,源代码太灵活(复杂)。 我在哪里可以了解有关词法分析和解析器的更多信息?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我的工作是将一种语言“翻译”成另一种语言。 对于使用正则表达式的简单逐行方法来说,源代码太灵活(复杂)。 我在哪里可以了解有关词法分析和解析器的更多信息?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(12)
我最近一直在使用 PLY 它是 lex 和 yacc 在 Python 中的实现。 开始使用它非常容易,并且文档中有一些简单的示例。
解析很快就会成为一个非常技术性的主题,并且您会发现,如果您使用像 PLY 这样的解析器构建器,您可能不需要了解解析算法的所有细节。
I've recently been working with PLY which is an implementation of lex and yacc in Python. It's quite easy to get started with it and there are some simple examples in the documentation.
Parsing can quickly become a very technical topic and you'll find that you probably won't need to know all the details of the parsing algorithm if you're using a parser builder like PLY.
很多人都推荐过书。 对于许多人来说,这些在具有作业和截止日期等的结构化环境中更有用。 即使没有,以不同的方式呈现材料也会有很大帮助。
(a) 您是否考虑过去一所拥有良好 CS 课程的学校?
(b) 网上讲座很多,比如MIT的开放课件< /a>. 他们的 EE/CS 部分 有许多涉及解析,尽管我看不到解析本身。 它通常作为最早的理论课程之一引入,因为语言分类和自动机是计算机科学理论的核心。
Lots of people have recommended books. For many these are much more useful in a structured environment with assignments and due dates and so forth. Even if not, having the material presented in a different way can help greatly.
(a) Have you considered going to a school with a decent CS curriculum?
(b) There are lots of online lectures, such as MIT's Open Courseware. Their EE/CS section has many courses that touch on parsing, though I can't see any on parsing per se. It's typically introduced as one of the first theory courses as language classification and automata is at the heart of much of CS theory.
如果您更喜欢基于 Java 的工具,Java 编译器编译器 JavaCC 是一个不错的解析器/扫描器。 它是配置文件驱动的,并将生成可以包含在程序中的 java 代码。 不过我已经好几年没有使用它了,所以我不确定当前版本如何。 您可以在此处了解更多信息:https://javacc.dev.java.net/
If you prefer Java based tools, the Java Compiler Compiler, JavaCC, is a nice parser/scanner. It's config file driven, and will generate java code that you can include in your program. I haven't used it a couple years though, so I'm not sure how the current version is. You can find out more here: https://javacc.dev.java.net/
词法分析/解析 + 类型检查 + 代码生成是一项很棒的 CS 练习,我会向任何想要打下坚实基础的人推荐它,所以我完全支持 Dragon Book
Lexing/Parsing + typecheck + code generation is a great CS exercise I would recommend it to anyone wanting a solid basis, so I'm all for the Dragon Book
我发现这个网站很有帮助:
Lex 和 YACC 入门/HOWTO
我第一次使用 lex/yacc 是为了一个相对简单的项目。 这个教程就是我真正需要的。 当我后来接触更复杂的项目时,我对本教程和一个简单项目的熟悉程度使我能够构建一些更奇特的东西。
I found this site helpful:
Lex and YACC primer/HOWTO
The first time I used lex/yacc was for a relatively simple project. This tutorial was all I really needed. When I approached more complex projects later, the familiarity I had from this tutorial and a simple project allowed me to build something fancier.
在学习了(相当多)一些编译器课程之后,我使用了 The Dragon Book 和 C&T。 我认为 C&T 在使编译器构造易于理解方面做得更好。 并不是要从《龙书》中拿走任何东西,但我认为《C&T》是一本实用得多的书。
另外,如果您喜欢用 Java 编写,我建议使用 JFlex 和 BYACC/J 满足您的词法分析和解析需求。
After taking (quite) a few compilers classes, I've used both The Dragon Book and C&T. I think C&T does a far better job of making compiler construction digestible. Not to take anything away from The Dragon Book, but I think C&T is a far more practical book.
Also, if you like writing in Java, I recommend using JFlex and BYACC/J for your lexing and parsing needs.
另一本值得考虑的教科书是编程语言语用。 比起龙书,我更喜欢它,但是YMMV。
如果您使用 Perl,另一个需要考虑的工具是 Parse ::RecDescent。
如果您只需要进行一次翻译,并且对编译器技术一无所知,我建议您尽可能进行一些相当简单的翻译,然后手动修复它。 是的,这是很多工作。 但这比学习一门复杂的学科并为一项工作编写正确的解决方案要少一些工作。 也就是说,您仍然应该学习该主题,但不要让不了解它成为完成当前项目的障碍。
Yet another textbook to consider is Programming Language Pragmatics. I prefer it over the Dragon book, but YMMV.
If you're using Perl, yet another tool to consider is Parse::RecDescent.
If you just need to do this translation once and don't know anything about compiler technology, I would suggest that you get as far as you can with some fairly simplistic translations and then fix it up by hand. Yes, it is a lot of work. But it is less work than learning a complex subject and coding up the right solution for one job. That said, you should still learn the subject, but don't let not knowing it be a roadblock to finishing your current project.
解析技术 - 实用指南
作者:Dick Grune 和 Ceriel JH Jacobs
这本书(免费提供 PDF 版本)对不同的解析技术/算法进行了广泛的概述。 如果你真的想了解不同的解析算法,IMO 是比 Dragon Book 更好的参考(因为解析技术完全专注于解析,而 Dragon Book 仅将解析作为编译器构建过程的一部分(尽管很重要)) 。
Parsing Techniques - A Practical Guide
By Dick Grune and Ceriel J.H. Jacobs
This book (freely available as PDF) gives an extensive overview of different parsing techniques/algorithms. If you really want to understand the different parsing algorithms, this IMO is a better reference than the Dragon Book (as Parsing Techniques focuses entirely on parsing, while the Dragon Book covers parsing only as one - although important - part of the compiler construction process).
flex 和 bison 是新的 lex 和 yacc。 BNF 的语法经常被嘲笑为有点迟钝。 由于这个原因,有些人已经转向 ANTLR 和 Ragel。
如果您不做太多翻译,您可能需要使用 Perl 或 Ruby 的多行正则表达式来完成一次一次性的翻译。 为现有语言编写兼容的 BNF 语法并不是一件容易的事。
另一方面,如果任何给定语言的 .l 和 .y 文件作为开源提供,则完全有可能利用它们。 然后,您可以从现有的解析树构造新代码。
flex and bison are the new lex and yacc though. The syntax for BNF is often derided for being a bit obtuse. Some have moved to ANTLR and Ragel for this reason.
If you're not doing much translation, you may one to pull a one-off using multiline regexes with Perl or Ruby. Writing a compatible BNF grammar for an existing language is not a task to be taken lightly.
On the other hand, it is entirely possible to leverage any given language's .l and .y files if they are available as open source. Then, you could construct new code from an existing parse tree.
如果您想获得有关该主题的“情感”,请获取“龙书”。 它通常是编译器设计课程中的文本。 它肯定会满足您“了解有关词法分析和解析器的更多信息”以及一堆其他有趣内容的需求!
IMH(笨拙)O,救救自己的手臂和/或腿并购买旧版本 - 它将满足您的信息需求。
If you want to get "emotional" about the subject, pick up a copy of "The Dragon Book." It is usually the text in a compiler design course. It will definitely meet your need "learn more about lexical analysis and parsers" as well as a bunch of other fun stuff!
IMH(umble)O, save yourself an arm and/or leg and buy an older edition - it will fill your information desires.
尝试 ANLTR:
还有一本书。
Try ANLTR:
There's a book for it also.
Niklaus Wirth 的书“编译器构造”(以免费 PDF 形式提供)
http://www.google.com/search?q=wirth+compiler+construction
Niklaus Wirth's book "Compiler Construction" (available as a free PDF)
http://www.google.com/search?q=wirth+compiler+construction