Yacc equivalent for Java

坚强是说给别人听的谎言 提交于 2019-11-26 15:46:23

问题


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.


回答1:


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

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

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




回答2:


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.




回答3:


GNU Bison has a Java interface,

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

You can use it go generate Java code.




回答4:


There is also jacc.

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

It interfaces well with jFlex

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




回答5:


Another option would be the 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.

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



来源:https://stackoverflow.com/questions/1639512/yacc-equivalent-for-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!