Question

I'm just wondering on how would you check java codes like

System.Out.println("hi");

it should check if the syntax is correct. I've used a java template in ANTLR, but I'm not quite sure that ANTLR provide checking predefined java methods. Is it possible to check it by using another tool?

Was it helpful?

Solution

It doesn't matter which generator you use as long as the grammar describes the language accurately. It's unnecessary to treat built-in classes and methods specially as they are no different than user-defined ones.

OTHER TIPS

The moment your checks start looking at other compilation units you are generally past syntax checking and into semantic checking. A simple grammar parser is not generally able to detect issues like this.

Why not use javac directly? Or even the compiler API provided by modern Java implementations?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top