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
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.