Java Code
——————————————————————————————–
static Set getIdentifiers(String filename) throws Exception{Set identifiers = new HashSet();String state=”INIT”; // Initially it is in the INIT state.StringBuilder code = new StringBuilder();BufferedReader br = new BufferedReader(new FileReader(filename));String line;while ((line = br.readLine()) != null) {code=code.append(line+””);} // read the text line by line.code =code.append(‘$’); //add a special symbol to indicate the end of file.
int len=code.length();String token=””;for (int i=0; i
if (state.contentEquals(“INIT”)){if (isLetter(next_char)){state=”ID”; // go to the ID statetoken=token+next_char;} //ignore everything if it is not a letter}else if (state.equals(“ID”)) {if (isLetterOrDigit(next_char)) { //take letter or digit if it is in ID statetoken=token+next_char;} else { // end of ID stateidentifiers.add(token);token=””;state=”INIT”;}
}
}return identifiers;}
????
Enjoy 24/7 customer support for any queries or concerns you have.
Phone: +1 213 3772458
Email: support@gradeessays.com