fixed bug
This commit is contained in:
parent
007f135c9e
commit
0c0dd043ec
1 changed files with 15 additions and 8 deletions
|
|
@ -98,8 +98,6 @@ public class NFAImpl implements NFA {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #TODO
|
|
||||||
@Override
|
@Override
|
||||||
public NFA kleeneStar() throws FinalizedStateException {
|
public NFA kleeneStar() throws FinalizedStateException {
|
||||||
if (!this.isFinalized) {
|
if (!this.isFinalized) {
|
||||||
|
|
@ -112,20 +110,22 @@ public class NFAImpl implements NFA {
|
||||||
nfa.states.addAll(this.states);
|
nfa.states.addAll(this.states);
|
||||||
nfa.transitions.addAll(this.transitions);
|
nfa.transitions.addAll(this.transitions);
|
||||||
|
|
||||||
|
// adding the initial state as accepting state because we have to accept the empty string
|
||||||
|
nfa.acceptingStates.add(this.initialState);
|
||||||
|
|
||||||
|
// for each accepting state
|
||||||
for (String acceptingState : this.acceptingStates) {
|
for (String acceptingState : this.acceptingStates) {
|
||||||
Transition loopBackTransition =
|
Transition loopBackTransition =
|
||||||
// creating an epsilon transition (null) for each accepting state
|
// creating an epsilon transition (null) for each accepting state
|
||||||
new Transition(acceptingState, null, this.initialState);
|
new Transition(acceptingState, null, this.initialState);
|
||||||
|
if (!nfa.transitions.contains(loopBackTransition)) {
|
||||||
nfa.transitions.add(loopBackTransition);
|
nfa.transitions.add(loopBackTransition);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// adding the initial state as accepting state because we have to accept the empty string
|
|
||||||
nfa.acceptingStates.add(this.initialState);
|
|
||||||
|
|
||||||
return nfa;
|
return nfa;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #TODO
|
|
||||||
@Override
|
@Override
|
||||||
public NFA plusOperator() throws FinalizedStateException {
|
public NFA plusOperator() throws FinalizedStateException {
|
||||||
if (!this.isFinalized) {
|
if (!this.isFinalized) {
|
||||||
|
|
@ -144,8 +144,10 @@ public class NFAImpl implements NFA {
|
||||||
Transition loopBackTransition =
|
Transition loopBackTransition =
|
||||||
// creating an epsilon transition (null) for each accepting state
|
// creating an epsilon transition (null) for each accepting state
|
||||||
new Transition(acceptingState, null, this.initialState);
|
new Transition(acceptingState, null, this.initialState);
|
||||||
|
if (!nfa.transitions.contains(loopBackTransition)) {
|
||||||
nfa.transitions.add(loopBackTransition);
|
nfa.transitions.add(loopBackTransition);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nfa;
|
return nfa;
|
||||||
}
|
}
|
||||||
|
|
@ -156,6 +158,11 @@ public class NFAImpl implements NFA {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void turnNFAIntoDFA(NFAImpl nfa) {
|
||||||
|
// #TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFinalized() {
|
public boolean isFinalized() {
|
||||||
return isFinalized;
|
return isFinalized;
|
||||||
|
|
|
||||||
Reference in a new issue