Create the following Software program Using Regular Expressi
Create the following Software program
Using Regular Expressions create a software that will accept in input a text file containing a Java Class. It will recognize the presence of Instance variables, Contructors and Methods. Plus, the package name and import packages.
If the file doesn\'t contain syntax errors, it will print in output something like \"the class is OK\". If it contains errors, it will print the line numbers where the problems are. Hints: Any statement ends with a semicolon.
A class can belong to one package only and must be the first thing specified in a file (remember that is not mandatory). Only one import with the same name can be considered correct.
So, if the file is trying to import the same package twice, this is an error.
A class can contain only one Constructor with the same signature, but any with different signatures; also no Contructor at all.
The same with Methods, only one with the same signature, any with different signatures, or no Methods at all. The Instance variables can be int, float, boolean, char and String
Solution
Pattern pattern1=Pattern.compile(\"[public,private,protected][class]([A-Z][a-z])*\")
Pattern pattern2 = Pattern.compile(\"[public,private protected][int,string,char,boolean,long,float,double][a-zA-Z 0-9]*\")
Pattern pattern3 = Pattern.compile(\"[public,private,protected][void,int,float,double][A-Za-z0-9]*)
Pattern pattern4 = Pattern.compile(\"[int,float,double,string,char][a-zA-Z0-9]*=[a-zA-Z0-9]*\")
Pattern pattern5 = Pattern.compile(\"[A-Za-z0-9]*\")
Pattern pattern6 = Pattern.compile(\"this.[a-za-z0-9]*=[a-za-z0-9]*\")
Pattern pattern7 = Pattern.compile(\"{\")
Pattern pattern8 = Pattern.compile(\"}\")
Pattern pattern9= Pattern.compile(\"[import][package][A-Za-z]*\")
Matcher m1 = Pattern9.matcher(mobile)
if(m1.matches())
{
Matcher m2 = Pattern1.matcher(mobile)
if(m2.matches())
{
Matcher m3 = Pattern3.matcher(mobile) || pattern4.matcher(mobile) || Matcher m = Pattern2.matcher(mobile)
if(m3.matches())
{
Matcher m4 = Pattern7.matcher(mobile)
if(m4.matches())
{
if(m1.matches() || m2.matches() || m3.matches() || m4.matches() || m5.matches())
{
Matcher m5 = Pattern8.matcher(mobile)
if(m5.matches())
{
}
}
}
}
}
}
}


