Question: Just wondering how to fix this part in java public static Set getIdRegex(String filename) throws Exception{ String[] keywordsArray = { IF, WRITE, READ, RETURN, BEGIN,END,

Just wondering how to fix this part in java

public static Set getIdRegex(String filename) throws Exception{ String[] keywordsArray = { "IF", "WRITE", "READ", "RETURN", "BEGIN","END", "MAIN", "INT", "REAL" }; Set keywords = new HashSet(); Set identifiers = new HashSet(); for (String s : keywordsArray) keywords.add(s);

FileReader reader = new FileReader(filename); BufferedReader br = new BufferedReader(reader); String line; Pattern idPattern = Pattern.compile("[a-zA-Z0-9]*"); Pattern quotedStringPattern = Pattern.compile("\"[a-zA-Z0-9.]*"); while ((line = br.readLine()) != null) { Matcher m_quotedString = quotedStringPattern.matcher(line); String lineWithoutQuotedStrings = m_quotedString.replaceAll(""); Matcher m = idPattern.matcher(lineWithoutQuotedStrings); while (m.find()) { String id = line.substring(m.start(), m.end()); if (!keywords.contains(id)) identifiers.add(id); } } return identifiers; }

Just wondering how to fix this part in java public static Set

The following test case is not passed. The ID count should be 5. Your answer is 6 INT f2 (INT X, INT Y ) BEGIN z := x*x - y*y; RETURN z; END INT MAIN F1 BEGIN INTX; READ (X, "A41.input"); INT Y; READ (V, "A42.input"); INT Z; z := 12 (x,y) + f2 (y,x); WRITE (z, "A4.output"); END The following test case is not passed. The ID count should be 4. Your answer is 5 BEGIN END INT MAIN AAA, X23Y, Fli A END The following test case is not passed. The ID count should be 6. Your answer is 7 aaaabbb!cccdddeee&ffff

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!