Question: I need help creating the logic for the union, concatenate, plus, star, singleCharNFA , public class RegularExpression { private String regularExpression; private NFA nfa; /
I need help creating the logic for the union, concatenate, plus, star, singleCharNFA
public class RegularExpression
private String regularExpression;
private NFA nfa;
You are not allowed to change the name of this class or this constructor at all.
public RegularExpressionString regularExpression
this.regularExpression regularExpression.replaceAlls;
nfa generateNFA;
TODO: Complete this method so that it returns the nfa resulting from unioning the two input nfas.
private NFA unionNFA nfa NFA nfa
return null;
TODO: Complete this method so that it returns the nfa resulting from concatenating the two input nfas.
private NFA concatenateNFA nfa NFA nfa
return null;
TODO: Complete this method so that it returns the nfa resulting from "staring" the input nfa.
private NFA starNFA nfa
return null;
TODO: Complete this method so that it returns the nfa resulting from "plussing" the input nfa.
private NFA plusNFA nfa
return null;
TODO: Complete this method so that it returns the nfa that only accepts the character c
private NFA singleCharNFAchar c
return null;
You are not allowed to change this method's header at all.
public boolean testString string
return nfa.acceptsstring;
Parser. I strongly recommend you do not change any code below this line.
Do not change any of the characters recognized in the regex eg U
private int position ch;
public NFA generateNFA
nextChar;
return parseExpression;
public void nextChar
ch position regularExpression.length regularExpression.charAtposition : ;
public boolean eatint charToEat
if ch charToEat
nextChar;
return true;
return false;
public NFA parseExpression
NFA nfa parseTerm;
while true
if eatU
Create the nfa that is the union of the two passed nfas.
nfa unionnfa parseTerm;
else
return nfa;
public NFA parseTerm
NFA nfa parseFactor;
while true
Concatenate NFAs.
if ch ch ch
Create the nfa that is the concatentaion of the two passed nfas.
nfa concatenatenfa parseFactor;
else
return nfa;
public NFA parseFactor
NFA nfa null;
if eat
nfa parseExpression;
if eat
throw new RuntimeExceptionMissing ;
else if ch ch
Create the nfa that only accepts the character being passed regularExpressioncharAtposition or
nfa singleCharNFAregularExpressioncharAtposition;
nextChar;
if eat
Create the nfa that is the star of the passed nfa.
nfa starnfa;
else if eat
Create the nfa that is the plus of the passed nfa.
nfa plusnfa;
return nfa;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
