I am writing a compiler for a big subset of java. I am currently trying to check reachability for statements . I found the JLS section that address this but it seems like there are a lot of rules that need to be “hard-coded”. Are they’re any algorithms that check this in a clean way? I have searched around but no luck!
Link : http://docs.oracle.com/javase/specs/jls/se5.0/html/statements.html#236365
Academic answer: This problem is undecidable, i.e. there is no algorithm that can strictly answer the question.
Practical answer: Check a textbook on static analysis. This is a very hard problem and you will not get a full blown answer here (I think).
Current compilers try a rather limited solution to the problem, other non-compiler tools try other things. In the end, for an implementation, you must decide which feasible cases you want to cover, and how slow your compiler is allowed to be. Because obviously, the more precise your analysis is, the longer it will take.
That being said, looking at a textbook will actually tell you what kind of things can be done, and how “expensive” they are.