How can I parse code to build a compiler in Java?

后端 未结 12 1364
时光说笑
时光说笑 2021-02-09 06:08

I need to write a compiler. It\'s homework at the univ. The teacher told us that we can use any API we want to do the parsing of the code, as long as it is a good one. That way

12条回答
  •  没有蜡笔的小新
    2021-02-09 06:50

    I would recommend ANTLR, primarily because of its output generation capabilities via StringTemplate.

    What is better is that Terence Parr's book on the same is by far one of the better books oriented towards writing compilers with a parser generator.

    Then you have ANTLRWorks which enables you to study and debug your grammar on the fly.

    To top it all, the ANTLR wiki + documentation, (although not comprehensive enough to my liking), is a good place to start off for any beginner. It helped me refresh knowledge on compiler writing in a week.

提交回复
热议问题