ANTLR 和 JavaCC 哪个更好?

发布于 2024-07-09 21:28:40 字数 49 浏览 3 评论 0原文

关注点是文档/可学习性、Eclipse 集成、工具、社区支持和性能(大致按此顺序)。

Concerns are documentation/learnability, eclipse integration, tooling, community support and performance (in roughly that order).

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

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

发布评论

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

评论(8

沧桑㈠ 2024-07-16 21:28:40

您不应排除以下几种替代方案:

  • JParsec 是一个解析器组合器框架,允许您完全从代码构建您的解析器。
  • Scala 的解析器组合器框架解决了类似的问题; 然而,Scala 的语法使所有这些都更具可读性。
  • 还有 John Metsker 为他的书 用 Java 构建解析器; 我不记得图书馆具体在哪里了,但至少以前在互联网上流传过。 它解决了同样的问题:您不必在单独的非 Java 文件中定义语法和标记定义; 相反,这一切都是Java。
  • Fortress,Sun 多年来一直致力于开发的编程语言,现在似乎是建立在这个工具包之上的:

总的来说,我的印象是代码生成器的时代已经结束了。 如果我是你,我会使用 Scala 的解析器组合器工具包。 基本上,任何支持 Scala 的 IDE 也“支持”这个解析器组合器框架。 性能很好,AFAICT。

顺便说一句,ANTLR 作为 Eclipse 插件有相当不错的 IDE 支持(但也许 IntelliJ 中也有一些东西 - 我不记得了。)所以,如果您选择在外部定义词法分析器和解析器的经典方法你的语言,那么 ANTLR 应该是你的选择,我想。 它在 Java 开发人员中拥有最大的关注度,有工具支持,并且有 ANTLR 作者的一本很棒的书。 我认为其他任何工具包都无法做到这一点。

There are a couple of alternatives you shouldn't rule out:

  • JParsec is a parser combinator framework that allows you to construct your parser entirely from code.
  • Scala's parser combinator framework addresses a similar concern; however, Scala's syntax makes all of this much more readable.
  • Then there's also the parser combinator framework done by John Metsker, for his book Building Parsers With Java; I don't remember exactly where the library is, but it was at least floating around on the Internet in the past. It addresses the same concern: you don't define your grammar and token definitions in a separate non-Java file; instead, it's all Java.
  • Fortress, the programming language Sun has been working on for years now seems to be build on this toolkit: Rats. I don't have much information, but I reckon if they use it for their new programming language, it probably has some interesting features.

In general, I get the impression that the years of the code generators are over. If I would be you, I would use Scala's parser combinator toolkit. Basically, any IDE supporting Scala, also 'supports' this parser combinator framework. Performance is good, AFAICT.

By the way, ANTLR has quite decent IDE support, as an Eclipse plugin (but perhaps there's also something in IntelliJ - I don't remember.) So, if you would opt for the classic approach of defining your lexical analyzer and parser outside of your language, then ANTLR should be your choice, I think. It has the biggest mindshare among Java developers, there is tool support, and there is a great book by the author of ANTLR. I don't think any of the other toolkits can claim that.

π浅易 2024-07-16 21:28:40

初步估计,在实践中对您来说真正重要的是符号对于您的眼睛来说有多方便和直观。

话虽如此,我用 ANTLR 和 JavaCC 完成了项目,发现 ANTLR 对于大多数事情来说都是非常重量级的。

To a first approximation, what's really going to matter to you in practice is how convenient and intuitive the notation is to your eyes.

Having said that, I'd done projects with ANTLR and JavaCC, and found ANTLR to be awfully heavyweight for most things.

卖梦商人 2024-07-16 21:28:40

对于您提到的问题,我建议 JavaCC 是更好的选择。 对于 Java 开发人员来说,学习起来更快更容易(语法与普通 Java 极其相似),文档很全面,并且 Eclipse 集成也足够。

With respect to the concerns you mentioned, I'd suggest that JavaCC was a better choice. It's quicker and easier for a Java developer to learn (the syntax is extremely similar to ordinary Java), the documentation is comprehensive, and the Eclipse integration is adequate.

橘寄 2024-07-16 21:28:40

ANTLR 的功能更全面:它是一个开箱即用的编译器 - 词法分析、解析、AST、树转换和代码生成。

对于 JavaCC 来说,它更像是一个解析器生成器,而不是编译器编译器。 AST 支持是通过另一个名为 JJTree 的库提供的。

ANTLR is more fully featured: it is a much more out the box compiler compiler - lexing, parsing, AST, tree transformations and code generation.

For JavaCC, it is much more a Parser generator than a compiler compiler. AST support is provided through another lib called JJTree.

盛夏已如深秋| 2024-07-16 21:28:40

ANTLR 相对于 JavaCC 的一个具体优势是它具有除 Java 之外的其他语言的生成器。 这可能会使您的语言移植到其他地方变得更加容易。

A concrete advantage ANTLR has over JavaCC is that it has generators for languages other than Java. This might make porting your language to other places much easier.

枫林﹌晚霞¤ 2024-07-16 21:28:40

我上面第二个是詹姆斯。

ANTLR 的功能更全面:它是
更多开箱即用的编译器
编译器 - 词法分析、解析、AST、树
转换和代码生成。

对于 JavaCC,它更像是一个解析器
生成器比编译器编译器。
AST 支持通过以下方式提供
另一个名为 JJTree 的库。

根据我个人的经验,您可以使用 ANTLR 做更多的事情,包括在规则之间传递参数以及通过所有子规则,这在制作复杂的解析器(例如 C# 的解析器)时有很大帮助。 另外,规则重写也很经典。 它可以帮助您轻松格式化您理想的 AST。

不过,它确实很重。 对于一个简单的项目,您可能永远不会使用这些功能。 Javacc 更酷。

I second jamesh above.

ANTLR is more fully featured: it is a
much more out the box compiler
compiler - lexing, parsing, AST, tree
transformations and code generation.

For JavaCC, it is much more a Parser
generator than a compiler compiler.
AST support is provided through
another lib called JJTree.

From my personal experience, you can do a lot more things with ANTLR, including passing parameter between rules and through all the sub-rules, which helps a lot while making a complex parser, like the parser for C#. Also, the rule re-writing is a classic too. It helps you to format your ideal AST easily.

However, it's really heavy. For a simple project, you probably will never use these functionalities. Javacc is cooler for it.

诺曦 2024-07-16 21:28:40

我有一段时间没有使用解析器生成器了,但几年前当我对它们感兴趣时,我记得喜欢 SableCC 最好的。 它实现了一些关于面向对象解析器生成的有趣想法,这些想法可能已被替代方案采纳,也可能未采纳。

I haven't used parser generators in a while, but several years back when I was interested in them, I remember liking SableCC best. It implemented some interesting ideas with respect to object oriented parser generation that may or may not have been picked up by the alternatives.

一笑百媚生 2024-07-16 21:28:40

我用 SableCC 编写了一个 CAS 语言的编译器,例如 Maple 或 MuPAD 来转换它
Maxima(用于 CAS-Capacity)和 LaTeX(用于显示)的单一语言。 SableCC 的 AST 是
严格面向对象,并且很容易扩展它以生成不同的语言。 如果你
想要将一种语言编译成多种其他语言,请尝试一下。

I wrote a compiler for CAS-language like Maple or MuPAD with SableCC to convert this
single language to Maxima (for CAS-Capacity) and LaTeX (to display). SableCC's AST is
strict object-oriented and it's easy to extends it to generate diffence languages. If you
want to compile a language into more than one others languages, just give it a try.

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