Question: 5 A12 Program A12.java will use regular expressions in java.util.regex. Here is a tutorial for Java regex. There are many ways to solve the problem.

5 A12 Program A12.java will use regular expressions in java.util.regex. Here is a tutorial for Java regex. There are many ways to solve the problem. One approach is described in the starter code belowit read the code line by line. In each line, it finds quoted strings and replaces them with empty strings. Then find identifiers and put them into a set if they are not keywords. "INT", "REAL" \}; Set String > keywords = new HashSet (); Set String > identifiers = new HashSet(O; for (String a : keywordshrray) keywords.add (s); Fileheader reader = nev Fileheader (filenane); BufferedReader br = new BufferedReader(reader); String line; //Pattern idPattern =...; // Pattern quotedStringPattern =; while (( line = br.readline ())!= null ) f Matcher n_quotedString = quotedStringPattern.natcher(1ine); String linelithoutQuotedStrings = m_quotedString-replacedll(" "); Matcher m = idPattern_natcher(1inelithoutQuotedStrings); while (n.find()) f String id = line.substring(m.start () , m.end()); if ( I keywords - contains (id)) identifiers add(id); J \} return identifiers; 3 public static void nain(String [] args) throvs Exceptionf Set String ids"getIdRegex("A1.tiny"); for (String id :ids) System.out.println(id); \} J
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
