Scala解析器组合器与ANTLR/Java生成的解析器? [英] Scala parser combinators vs ANTLR/Java generated parser?

查看:85
本文介绍了Scala解析器组合器与ANTLR/Java生成的解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为主要用Scala编写的应用程序编写表达式解析器.我已经在Scala中构建了AST对象,现在需要编写解析器.我听说过Scala的内置解析器组合器以及ANTLR3,我想知道:哪一种可以提供更好的性能和编写代码的便利性?到目前为止:

I am writing an expression parser for an app written mostly in Scala. I have built AST objects in Scala, and now need to write the parser. I have heard of Scala's built-in parser combinators, and also of ANTLR3, and am wondering: which would provide better performance and ease of writing code? So far:

ANTLR专家

  1. 知名
  2. 快速
  3. 外部DSL
  4. ANTLRWorks(用于语法分析器调试/测试的大型IDE)

ANTLR缺点

  1. 基于Java(Scala互操作可能具有挑战性,有经验吗?)
  2. 在运行时需要很大的依赖性

解析器组合专家

  1. Scala的一部分
  2. 少建一个步骤
  3. 不需要运行时依赖项;例如已经包含在Scala的运行时库中

解析器组合器的缺点

  1. 内部DSL(可能意味着执行速度较慢?)
  2. 没有ANTLRWorks(提供了不错的解析器测试和可视化功能)

有什么想法吗?

编辑:此表达式解析器解析代数/微积分表达式.完成后,它将在Android版Magnificalc应用中使用.

This expression parser parses algebraic/calculus expressions. It will be used in the app Magnificalc for Android when it is finalized.

推荐答案

Scala的解析器组合器效率不高.他们不是被设计成这样的.它们非常适合以较小的投入执行小任务.

Scala's parser combinators aren't very efficient. They weren't designed to be. They're good for doing small tasks with relatively small inputs.

因此,这实际上取决于您的要求. ANTLR应该不会有任何互操作问题.从Java调用Scala可能很麻烦,但是从Scala调用Java几乎总是可行.

So it really depends on your requirements. There shouldn't be any interop problems with ANTLR. Calling Scala from Java can get hairy, but calling Java from Scala almost always just works.

这篇关于Scala解析器组合器与ANTLR/Java生成的解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆