File tree Expand file tree Collapse file tree 4 files changed +76
-13
lines changed Expand file tree Collapse file tree 4 files changed +76
-13
lines changed Original file line number Diff line number Diff line change
1
+ public class Automata {
2
+
3
+ private State inputState ;
4
+ private State outputState ;
5
+
6
+ public Automata (State input , State output ) {
7
+ this .inputState = input ;
8
+ this .outputState = output ;
9
+ }
10
+
11
+ public State getInputState () {
12
+ return inputState ;
13
+ }
14
+
15
+ public State getOutputState () {
16
+ return outputState ;
17
+ }
18
+
19
+ public void setInputState (State newInputState ) {
20
+ inputState = newInputState ;
21
+ }
22
+
23
+ public void setOutputState (State newOutputState ) {
24
+ outputState = newOutputState ;
25
+ }
26
+
27
+ /**
28
+ * Tests whether this NFA matches the input string.
29
+ * Delegates to the input state.
30
+ */
31
+ // public String test(String str) {
32
+ // return inputState.test(str);
33
+ // }
34
+ }
Original file line number Diff line number Diff line change
1
+ public class AutomataFactory {
2
+ public Automata createNFA (State input , State output ) {
3
+ return new Automata (input , output );
4
+ }
5
+
6
+ public Automata concatNFA (Automata first , Automata second ) {
7
+ State firstOutputState = first .getOutputState ();
8
+ firstOutputState .setAccepting (false );
9
+ return new Automata (first .getInputState (), second .getOutputState ());
10
+ }
11
+
12
+ // public NFA BuildNFA(String symbol) {
13
+ //
14
+ // State input = new State("q1", false);
15
+ // State output = new State("q2", true);
16
+ //
17
+ // input.addTransitionForSymbol(symbol, output);
18
+ //
19
+ // return new NFA(input, output);
20
+ // }
21
+ //
22
+ // public NFA concatPair(NFA first, NFA second) {
23
+ // return new NFA(first.initialState, second.finalState);
24
+ // }
25
+
26
+ }
Original file line number Diff line number Diff line change 1
- import java .util .List ;
2
- import java .io .IOException ;
3
-
4
1
public class Main {
5
-
6
- public static void main (String [] args ) throws IOException {
7
-
2
+ public static void main (String [] args ) {
8
3
State s1 = new State ("A" , false );
9
4
State s2 = new State ("B" , false );
10
- State s3 = new State ("C" , true );
11
5
12
- s1 .addTransitionForSymbol ("a" , s2 );
13
- s2 .addTransitionForSymbol ("b" , s3 );
14
- List <State > states = s2 .getTransitionsForSymbol ("b" );
6
+ AutomataFactory factory = new AutomataFactory ();
7
+ Automata m1 = factory .createNFA (s1 , s2 );
8
+
9
+ System .out .println (m1 .getInputState ().getName ());
15
10
16
- for (State state : states ) {
17
- System .out .println (state .getName ());
18
- }
11
+ // s1.addTransitionForSymbol("a", s2);
12
+ // s2.addTransitionForSymbol("b", s3);
13
+ // List<State> states = s2.getTransitionsForSymbol("b");
14
+ //
15
+ // for (State state : states) {
16
+ // System.out.println(state.getName());
17
+ // }
19
18
}
20
19
}
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ public boolean getIsAccepting() {
22
22
return accepting ;
23
23
}
24
24
25
+ public void setAccepting (boolean newValue ) {
26
+ accepting = newValue ;
27
+ }
28
+
25
29
public void addTransitionForSymbol (String symbol , State state ) {
26
30
27
31
List <State > stateArray = states .get (symbol );
You can’t perform that action at this time.
0 commit comments