Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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; }

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

Students also viewed these Databases questions

Question

What would you do?

Answered: 1 week ago

Question

Read and summarize Technical Advice Memorandum 201014051.

Answered: 1 week ago