diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 8a12d42..44bc23b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,6 +7,7 @@
+
@@ -17,7 +18,7 @@
@@ -49,27 +50,27 @@
- {
- "keyToString": {
- "RunOnceActivity.OpenProjectViewOnStart": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "WebServerToolWindowFactoryState": "false",
- "full.screen.before.presentation.mode": "false",
- "git-widget-placeholder": "main",
- "ignore.virus.scanning.warn.message": "true",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "project.structure.last.edited": "Project",
- "project.structure.proportion": "0.0",
- "project.structure.side.proportion": "0.0",
- "settings.editor.selected.configurable": "preferences.pluginManager",
- "vue.rearranger.settings.migration": "true"
+
-
+}]]>
+
@@ -87,6 +88,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -138,11 +156,11 @@
-
+
+
-
@@ -164,7 +182,7 @@
-
+
@@ -198,7 +216,15 @@
1704749811525
-
+
+
+ 1704750289780
+
+
+
+ 1704750289780
+
+
diff --git a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
index 57908e3..e678c18 100644
--- a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
+++ b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
@@ -16,6 +16,8 @@ public class NFAImpl implements NFA {
private Set alphabet;
+ private Set completeAlphabet;
+
private boolean isFinalized;
public NFAImpl(String startState) {
@@ -25,6 +27,10 @@ public class NFAImpl implements NFA {
this.transitions = new HashSet<>();
this.acceptingStates = new HashSet<>();
this.alphabet = new HashSet<>();
+ this.completeAlphabet = new HashSet<>();
+ for (char ch = 'a'; ch <= 'z'; ch++) {
+ this.completeAlphabet.add(ch);
+ }
this.isFinalized = false;
}
@@ -211,28 +217,55 @@ public class NFAImpl implements NFA {
return intersectionNFA;
}
- // #TODO
@Override
public NFA concatenation(NFA other) throws FinalizedStateException {
if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException();
}
+
NFAImpl concatenationNFA = new NFAImpl(this.initialState);
+ // Add states from 'this'
concatenationNFA.states.addAll(this.states);
- concatenationNFA.states.addAll(other.getStates());
+ // Add states from 'other', with renaming if necessary
+ Map renamedStates = new HashMap<>();
+ for (String state : other.getStates()) {
+ String newState = changeIfNecessary(state, concatenationNFA.states);
+ renamedStates.put(state, newState); // Old state name -> New state name
+ concatenationNFA.states.add(newState);
+ }
+
+ // Add transitions from 'this'
concatenationNFA.transitions.addAll(this.transitions);
- concatenationNFA.transitions.addAll(other.getTransitions());
- for (String accceptingState : this.acceptingStates) {
- Transition epsilon = new Transition(accceptingState, null, other.getInitialState());
+ // Add transitions from 'other', updating state names
+ for (Transition transition : other.getTransitions()) {
+ String newFromState = renamedStates.getOrDefault(transition.fromState(), transition.fromState());
+ String newToState = renamedStates.getOrDefault(transition.toState(), transition.toState());
+ Transition newTransition = new Transition(newFromState, transition.readSymbol(), newToState);
+ concatenationNFA.transitions.add(newTransition);
+ }
+
+ // Connect accepting states of 'this' to the initial state of 'other' with epsilon transitions
+ String newOtherInitialState = renamedStates.getOrDefault(other.getInitialState(), other.getInitialState());
+ for (String acceptingState : this.acceptingStates) {
+ Transition epsilon = new Transition(acceptingState, null, newOtherInitialState);
concatenationNFA.transitions.add(epsilon);
}
+ // Set accepting states of the concatenated NFA to be the accepting states of 'other'
+ concatenationNFA.acceptingStates.clear();
+ for (String acceptingState : other.getAcceptingStates()) {
+ concatenationNFA.acceptingStates.add(renamedStates.getOrDefault(acceptingState, acceptingState));
+ }
+
+ concatenationNFA.finalizeAutomaton();
+
return concatenationNFA;
}
+
@Override
public NFA kleeneStar() throws FinalizedStateException {
if (!this.isFinalized) {
@@ -256,6 +289,7 @@ public class NFAImpl implements NFA {
nfa.transitions.add(loopBackTransition);
}
+ nfa.finalizeAutomaton();
return nfa;
}
@@ -293,6 +327,8 @@ public class NFAImpl implements NFA {
}
*/
+ nfa.finalizeAutomaton();
+
return nfa;
}
@@ -388,6 +424,8 @@ public class NFAImpl implements NFA {
currentStates = epsilonClosure(currentStates, this);
}
+
+
return isAcceptingState(currentStates, this);
}