Java Syntax Checker/Validator
843811Feb 23 2004 — edited Feb 23 2004Hello...
I'm currently working on a research projet. This system is targetted at novice students who are learning Java programming language the first time. The system will give the user some simple senarios and ask the user to enter the Java snippets. An example:
Question: Write a Java statement with the variable noOfCars to represent 100 cars in a car park.
Expected user input: int noOfCars = 100;
What I need now is a Java syntax validator to validate the above Java statement. The system will parse that Java statement (int noOfCars = 100;) into the validator and return any mistakes generated. For example, with regards to the above question, the user now enters a invalid Java statement:
int noOfCars = "100";
The validator would return the following messages, just like when compiling them in a Java file using the normal javac:
incompatible types
found : java.lang.String
required: int
int noOfCars = "100";
Is it possible to extract that error message from the normal javac compiler and display to the user from the current program that I'm developing? If there is, how should I parse the string to the compiler/validator and extract the error message out to display to user?
If it is not possible with the existing javac compiler, is there any other tools available out in the community to guide me? I've researched on checkstyle (http://checkstyle.sourceforge.net/) but it seems like checking java files instead of single strings for my case.
Besides checking for the above statements, the system is also needed to check for correct structure for if, if-else, for-loop, while-loop statements.
Appriciate for any help ASAP.
Thanks a million.
David