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
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; }
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&ffffStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started