Java 的解析器、生成器具有以下要求
我正在寻找一个用于 Java 的解析器生成器,它可以执行以下操作: 我的语言项目非常简单,仅包含一小部分标记。
以纯可读的 Java 代码输出,以便我可以修改它(这就是我不使用 ANTLR 的原因) 成熟的库,至少可以与 Java 1.4 一起运行和工作
我已经查看了以下内容,它们可能会工作:JavaCC、jlex、Ragel?
I am looking for a parser generator for Java that does the following: My language project is pretty simple and only contains a small set of tokens.
Output in pure READABLE Java code so that I can modify it (this why I wouldn't use ANTLR)
Mature library, that will run and work with at least Java 1.4
I have looked at the following and they might work: JavaCC, jlex, Ragel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
也许您正在寻找解析器组合器而不是解析器生成器? 请参阅本文和JParsec。
编辑生成的解析器代码确实是一个坏主意——编辑语法文件然后重新编译它要容易得多。 除非您出于教育目的而这样做,否则 ANTLR 会为自己为如此强大的解析器生成器生成非常可读的代码而感到自豪。
Maybe you're looking for parser combinators instead of parser generators? See this paper and JParsec.
It's a really bad idea to edit generated parser code--it's a lot easier to edit the grammar file and then recompile it. Unless you're doing it for educational purposes, in which case ANTLR prides itself in generating pretty readable code for such a powerful parser generator.
你应该使用 Rats ...这样,你就不会必须将词法分析器和解析器分开,然后如果您想扩展您的项目,那将是微不足道的。 它是用java编写的,然后你可以用Java处理你的AST......
You should use Rats... This way, you don't have to separate lexer and parser and then if you want to extend your project that will be trivial. It's in java and then you can process your AST in Java...
我在 SableCC 中获得了很好的体验。
它的工作方式与大多数生成器不同,因为您会获得一个可扩展的 AST/Visitor 模型(通过继承)。
我无法在可读性方面评论其代码的“质量”(自从我使用它以来已经有一段时间了),但它确实具有您根本不必阅读代码的质量。 只是你的子类中的代码。
I had good experience SableCC.
It works different from most generators, in that you're given a AST/Visitor model that you extend (via inheritance).
I can't comment on the "quality" of its code in terms of readability (it's been a while since I've used it), but it does have the quality that you don't have to read the code at all. Just the code in your subclass.
也许 ANTLR 会为您做到这一点。 这是一个很好的解析器生成器,有一本很好的书可用于文档。
Maybe ANTLR will do it for you. It's a nice parser generator with a fine book available for documentation.
看看 SableCC。 Sablecc 是一个易于使用的解析器生成器,它接受您的语言语法作为 EBNF,而不混合操作代码,并生成一个 Java 解析器,该解析器生成可以使用树节点访问者遍历的语法树。 SableCC 功能强大,但使用起来比 ANTLR、JavaCC、yacc 等简单得多。它也不需要单独的词法分析器。 构造语言处理器相当于扩展从语法生成的访问者类,并覆盖解析器遇到语法构造时调用的方法。 对于每个语法规则 XYZ,当解析器匹配规则时,访问者将调用 inAXYZ(Node xyz)...outAXYZ(Node xyz) 方法。
Take a look at SableCC. Sablecc is an easy to use parser generator that accepts the grammar of your language as EBNF, without intermingling action code, and generates a Java parser that produces a syntax tree which can be traversed using a tree node visitor. SableCC is powerful, yet much simpler to use than ANTLR, JavaCC, yacc, etc. It also does not require a separate lexer. Constructing your language processor amounts to extending a visitor class generated from your grammar, and to overriding its methods which are called upon when a syntactic construct is encountered by the parser. For every grammar rule XYZ, the visitor will have a method inAXYZ(Node xyz)....outAXYZ(Node xyz) called upon when the parser matches the rule.
对于如此简单的语言,JFlex 可能就足够了。 它与 JLex 类似,但更快(这也可能意味着可读性较差,但我还没有看到JLex 的输出)。
它是一个词法分析器,而不是解析器,但它构建可以轻松地与CUP 或 BYacc/J。 再说一遍,对于一种简单的语言,编写自己的解析器可能会更容易(我之前已经这样做过)。
For a language that simple, JFlex might suffice. It's similar to JLex but faster (which might also mean less readable, but I've not seen JLex's output).
It is a lexer, not a parser, but it is built to interface easily with CUP or BYacc/J. And again, for a simple language, it might be easier to just write your own parser (I've done this before).
我们正在将 JavaCC 用于我们的(以及相当小的语言)并且对此感到满意。
We are using JavaCC for our (as well rather small language) and are happy with it.