相当于 Java 的 Yacc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1639512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:06:26  来源:igfitidea点击:

Yacc equivalent for Java

javayacc

提问by vuzun

I'm working on a compiler design project in Java. Lexical analysis is done (using jflex) and I'm wondering which yacc-like tool would be best(most efficient, easiest to use, etc.) for doing syntactical analysis and why.

我正在从事 Java 编译器设计项目。词法分析已经完成(使用 jflex),我想知道哪种类似 yacc 的工具最适合(最有效、最容易使用等)进行句法分析以及为什么。

采纳答案by kdgregory

If you specifically want YACC-like behavior (table-driven), the only one I know is CUP.

如果你特别想要类似 YACC 的行为(表驱动),我知道的唯一一个是CUP

In the Java world, it seems that more people lean toward recursive descent parsers like ANTLRor JavaCC.

在 Java 世界中,似乎越来越多的人倾向于使用递归下降解析器,如ANTLRJavaCC

And efficiency is seldom a reason to pick a parser generator.

效率很少成为选择解析器生成器的理由。

回答by toolkit

In the past, I've used ANLTR for both lexer and parser, and the JFlex homepage says it can interoperate with ANTLR. I wouldn't say that ANTLR's online documentation is that great. I ended up investing in 'The Definitive ANTLR reference', which helped considerably.

过去,我将 ANLTR 用于词法分析器和解析器,并且 JFlex 主页说它可以与 ANTLR 互操作。我不会说 ANTLR 的在线文档那么好。我最终投资了 'The Definitive ANTLR reference',这有很大帮助。

回答by ZZ Coder

GNU Bison has a Java interface,

GNU Bison 有一个 Java 接口,

http://www.gnu.org/software/bison/manual/html_node/Java-Bison-Interface.html

http://www.gnu.org/software/bison/manual/html_node/Java-Bison-Interface.html

You can use it go generate Java code.

您可以使用它来生成 Java 代码。

回答by Steve N

Another option would be the GOLD Parser.

另一种选择是GOLD Parser

Unlike many of the alternatives, the GOLD parser generates the parsing tables from the grammar and places them in a binary, non-executable file. Each supported language then has an engine which reads the binary tables and parses your source file.

与许多替代方案不同,GOLD 解析器根据语法生成解析表,并将它们放在一个二进制的、不可执行的文件中。每个受支持的语言都有一个引擎,可以读取二进制表并解析您的源文件。

I've not used the Java implementation specifically, but have used the Delphi engine with fairly good results.

我没有专门使用 Java 实现,但使用过 Delphi 引擎并取得了相当不错的结果。

回答by CaTalyst.X

There is also jacc.

还有jacc。

Jacc is about as close to yacc as you can get, but it is implemented in pure java and generates a java parser.

Jacc 与 yacc 尽可能接近,但它是用纯 Java 实现的,并生成一个 Java 解析器。

It interfaces well with jFlex

它与 jFlex 接口良好

http://web.cecs.pdx.edu/~mpj/jacc/

http://web.cecs.pdx.edu/~mpj/jacc/