Skip to content

Commit 0d8beb2

Browse files
committed
Update CFG, DFA, NFA, and TM README files to standardize section headers and transition formats
1 parent a0372dc commit 0d8beb2

File tree

7 files changed

+79
-64
lines changed

7 files changed

+79
-64
lines changed

src/main/java/ContextFreeGrammar/ContextFreeGrammarREADME.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Parsing is performed using the **CYK algorithm** (on Chomsky Normal Form).
2424

2525
## 3. CFG Definition File Format (`.cfg`)
2626

27-
Each section starts with a keyword and `=`. Lines may contain comments (`# ...`) and blank lines.
27+
Each section starts with a keyword and `:`. Lines may contain comments (`# ...`) and blank lines.
2828

2929
**Required sections:**
30-
- `Variables =` space-separated variable names (uppercase)
31-
- `Terminals =` space-separated terminal names (lowercase)
32-
- `Start =` one variable name (must be in `Variables`)
33-
- Productions: one per line, format `<Variable> -> <symbols> | <alternative> ...`
30+
- `vars:` space-separated variable names (uppercase)
31+
- `terminals:` space-separated terminal names (lowercase)
32+
- `start:` one variable name (must be in `vars`)
33+
- `rules:` header followed by production lines
3434

3535
**Productions:**
3636
- Left side: a variable (non-terminal)
@@ -39,10 +39,11 @@ Each section starts with a keyword and `=`. Lines may contain comments (`# ...`)
3939

4040
**Example**
4141
```text
42-
Variables = S A B
43-
Terminals = a b
44-
Start = S
42+
vars: S A B
43+
terminals: a b
44+
start: S
4545
46+
rules:
4647
S -> A B
4748
A -> a
4849
B -> b

src/main/java/DeterministicFiniteAutomaton/DeterministicFiniteAutomatonREADME.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,28 @@ Each section begins with a keyword and a colon. Lines may contain comments (`# .
2828
- `states:` space-separated state names
2929
- `alphabet:` space-separated input symbols (single chars)
3030
- `start:` one state name
31-
- `finals:` space-separated accepting states
31+
- `accept:` space-separated accepting states
3232
- `transitions:` one transition per line (see below)
3333

3434
**Transitions**
3535
```
36-
<fromState> <inputSymbol> -> <toState>
36+
<fromState>, <inputSymbol> -> <toState>
3737
```
3838

3939
**Example**
4040
```text
4141
states: q0 q1 q2
4242
alphabet: a b
4343
start: q0
44-
finals: q2
44+
accept: q2
45+
4546
transitions:
46-
q0 -> q1 (a)
47-
q0 -> q0 (b)
48-
q1 -> q1 (a)
49-
q1 -> q2 (b)
50-
q2 -> q1 (a)
51-
q2 -> q0 (b)
47+
q0, a -> q1
48+
q0, b -> q0
49+
q1, a -> q1
50+
q1, b -> q2
51+
q2, a -> q1
52+
q2, b -> q0
5253
```
5354

5455
## 4. Components

src/main/java/NondeterministicFiniteAutomaton/NondeterministicFiniteAutomatonREADME.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,32 @@ Each section begins with a keyword and a colon. Lines may contain comments (`# .
3131
- `states:` space-separated state names
3232
- `alphabet:` space-separated input symbols (single chars)
3333
- `start:` one state name
34-
- `finals:` space-separated accepting states
34+
- `accept:` space-separated accepting states
3535
- `transitions:` one transition per line (see below)
3636

3737
**Transitions**
3838
```
39-
<fromState> -> <toState> (<inputSymbol(s)>)
39+
<fromState>, <inputSymbol> -> <toState>
4040
```
4141
- \<inputSymbol> can be ***eps*** to indicate an epsilon transition.
42-
- For each (\<fromState>, \<toState>) pair, there must be ***at most one line***.
42+
- Each transition is on its own line with exactly one symbol.
4343

4444
**Example**
4545
```text
4646
states: q0 q1 q2
47-
start: q0
48-
finals: q2
4947
alphabet: a b
48+
start: q0
49+
accept: q2
50+
5051
transitions:
51-
q0 -> q1 (a eps)
52-
q0 -> q0 (b)
53-
q1 -> q1 (eps)
54-
q1 -> q2 (b)
55-
q2 -> q1 (a)
56-
q2 -> q0 (b eps)
52+
q0, a -> q1
53+
q0, eps -> q1
54+
q0, b -> q0
55+
q1, eps -> q1
56+
q1, b -> q2
57+
q2, a -> q1
58+
q2, b -> q0
59+
q2, eps -> q0
5760
```
5861

5962
## 4. Components

src/main/java/TuringMachine/TMREADME.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,35 @@ To use the module, you must define a TM in a text file with specific sections. E
4848

4949
### Required Sections
5050
- `states`: A space-separated list of all state names (e.g., `q0 q1 q_accept`).
51-
- `input_alphabet`: Space-separated symbols for the input.
52-
- `tape_alphabet`: Space-separated symbols allowed on the tape (must include input alphabet symbols).
51+
- `input`: Space-separated symbols for the input.
52+
- `tape`: Space-separated symbols allowed on the tape (must include input alphabet symbols).
5353
- `start`: The name of the start state.
5454
- `accept`: The name of the accept state.
55+
- `reject`: The name of the reject state.
5556
- `transitions`: The header for the transition rules.
5657

5758
### Transitions
5859
Each transition rule must be on a new line in the format:
59-
`<current_state> <read_symbol> -> <next_state> <write_symbol> <direction>`
60-
(Example: `q0 0 -> q1 X R`)
60+
`<current_state>, <read_symbol> -> <next_state>, <write_symbol>, <direction>`
61+
(Example: `q0, 0 -> q1, X, R`)
6162

6263
### Example `.tm` File
6364
This TM accepts strings with an even number of zeros.
6465
```
6566
states: q0 q1 q_accept q_reject
66-
input_alphabet: 0 1
67-
tape_alphabet: 0 1 _
67+
input: 0 1
68+
tape: 0 1 _
6869
start: q0
6970
accept: q_accept
7071
reject: q_reject
7172
7273
transitions:
73-
q0 0 -> q1 0 R
74-
q0 1 -> q0 1 R
75-
q0 _ -> q_accept _ R
76-
q1 0 -> q0 0 R
77-
q1 1 -> q1 1 R
78-
q1 _ -> q_reject _ R
74+
q0, 0 -> q1, 0, R
75+
q0, 1 -> q0, 1, R
76+
q0, _ -> q_accept, _, R
77+
q1, 0 -> q0, 0, R
78+
q1, 1 -> q1, 1, R
79+
q1, _ -> q_reject, _, R
7980
```
8081

8182
## 4. Core Java Components
Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
Start: q0
2-
Finals: q5 q7
3-
Alphabet: a b c
4-
States: q0 q1 q2 q3 q4 q5 q6 q7
1+
states: q0 q1 q2 q3 q4 q5 q6 q7
2+
alphabet: a b c
3+
start: q0
4+
accept: q5 q7
55

6-
Transitions:
7-
q0 -> q0 (c)
8-
q0 -> q1 (a b)
9-
q1 -> q2 (a)
10-
q1 -> q3 (b)
11-
q1 -> q1 (c)
12-
q2 -> q2 (a c)
13-
q5 -> q5 (a b c)
14-
q2 -> q4 (b)
15-
q4 -> q5 (a)
16-
q3 -> q4 (a)
17-
q6 -> q7 (a)
18-
q3 -> q3 (b c)
19-
q4 -> q6 (b c)
20-
q6 -> q0 (b c)
21-
q7 -> q7 (a b c)
6+
transitions:
7+
q0, c -> q0
8+
q0, a -> q1
9+
q0, b -> q1
10+
q1, a -> q2
11+
q1, b -> q3
12+
q1, c -> q1
13+
q2, a -> q2
14+
q2, c -> q2
15+
q5, a -> q5
16+
q5, b -> q5
17+
q5, c -> q5
18+
q2, b -> q4
19+
q4, a -> q5
20+
q3, a -> q4
21+
q6, a -> q7
22+
q3, b -> q3
23+
q3, c -> q3
24+
q4, b -> q6
25+
q4, c -> q6
26+
q6, b -> q0
27+
q6, c -> q0
28+
q7, a -> q7
29+
q7, b -> q7
30+
q7, c -> q7

src/test/java/common/GraphvizEngineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void testDFASimpleRendering() {
5959
"states: q0 q1 q2\n" +
6060
"alphabet: a b\n" +
6161
"start: q0\n" +
62-
"finals: q2\n" +
62+
"accept: q2\n" +
6363
"\n" +
6464
"transitions:\n" +
6565
"q0, a -> q1\n" +

src/test/java/service/TestServiceValidationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void testDfaSuccess() throws IOException {
5454
"states: q0 q1\n" +
5555
"alphabet: a b\n" +
5656
"start: q0\n" +
57-
"finals: q1\n" +
57+
"accept: q1\n" +
5858
"\n" +
5959
"transitions:\n" +
6060
"q0, a -> q1\n" +
@@ -390,7 +390,7 @@ void testNullAutomaton() throws IOException {
390390
@DisplayName("should throw exception for null test file path")
391391
void testNullTestFilePath() {
392392
DFA dfa = new DFA();
393-
dfa.parse("states: q0\nalphabet: a\nstart: q0\nfinals: q0\n\ntransitions:\nq0, a -> q0\n");
393+
dfa.parse("states: q0\nalphabet: a\nstart: q0\naccept: q0\n\ntransitions:\nq0, a -> q0\n");
394394
SessionService.TestSettings settings = new SessionService.TestSettings(
395395
0, 100, 30, null, null, null);
396396

@@ -402,7 +402,7 @@ void testNullTestFilePath() {
402402
@DisplayName("should throw exception for null settings")
403403
void testNullSettings() throws IOException {
404404
DFA dfa = new DFA();
405-
dfa.parse("states: q0\nalphabet: a\nstart: q0\nfinals: q0\n\ntransitions:\nq0, a -> q0\n");
405+
dfa.parse("states: q0\nalphabet: a\nstart: q0\naccept: q0\n\ntransitions:\nq0, a -> q0\n");
406406
File testFile = createTestFile("a,1\n");
407407

408408
assertThrows(IllegalArgumentException.class, () ->

0 commit comments

Comments
 (0)