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

后端 未结 12 1159
时光说笑
时光说笑 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 07:00

    If you're going to go hardcore, throw in a bit of http://llvm.org in the mix :)

    0 讨论(0)
  • 2021-02-09 07:02

    Have a look at JavaCC, a language parser for Java. It's very easy to use and get the hang of

    0 讨论(0)
  • 2021-02-09 07:04

    I suggest you look at at the source for BeanShell. It has a compiler for Java and is fairly simple to read.

    0 讨论(0)
  • 2021-02-09 07:05

    Go classic - Lex + Yacc. In Java it spells JAX and javacc. Javacc even has some Java grammars ready for inspection.

    0 讨论(0)
  • 2021-02-09 07:07

    http://java-source.net/open-source/parser-generators and http://catalog.compilertools.net/java.html contain catalogs of tools for this. Compare also the Stackoverflow question Alternatives to Regular Expressions.

    0 讨论(0)
  • 2021-02-09 07:10

    JFlex is a scanner generator which, according to the manual, is designed to work with the parser generator CUP.

    One of the main design goals of JFlex was to make interfacing with the free Java parser generator CUP as easy as possibly [sic].

    It also has support for BYACC/J, which, as its name suggests, is a port of Berkeley YACC to generate Java code.

    I have used JFlex itself and liked it. Howeveer, the project I was doing was simple enough that I wrote the parser by hand, so I don't know how good either CUP or BYACC/J is.

    0 讨论(0)
提交回复
热议问题