Skip to content

Commit

Permalink
Fix missing in-arrow to start state (#17)
Browse files Browse the repository at this point in the history
* fix: missing in-arrow to start state

The start state has to be explicitly specified with an in-arrow;
otherwise, the state with number 0 is select by default, which isn't
correct in our cases.

* fix: unused include

* docs: update example image

* docs: bump version
  • Loading branch information
Lai-YT authored Oct 24, 2024
1 parent 7680d45 commit 6387169
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Graph mode:
Written by: Lai-YT
regexp version: 1.0.2
regexp version: 1.0.3
```

### Example
Expand Down Expand Up @@ -162,7 +162,7 @@ This will then write the graph into `some/path/and/filename.dot`.
```console
$ dot -Tpng nfa.dot -o nfa.png
```
![The NFA of "(a|b)*abb"](https://imgur.com/WCbGHDu.png)
![The NFA of "(a|b)*abb"](https://imgur.com/aVNvEoK.png)
> [!note]
> The numbering of the states is related to the order of their creations.
Expand Down
2 changes: 1 addition & 1 deletion src/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The full text of the license can be found in
#define MESSAGES_H

#define PROGRAM_NAME "regexp"
#define PROGRAM_VERSION "1.0.2"
#define PROGRAM_VERSION "1.0.3"
#define PROGRAM_AUTHOR "Lai-YT"

void help();
Expand Down
6 changes: 5 additions & 1 deletion src/visstate.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdio.h>

#include "map.h"
#include "post2nfa.h"
#include "nfa.h"
#include "stack.h"

/// @details The label of an epsilon transition is "eps", others are the
Expand Down Expand Up @@ -50,5 +50,9 @@ void nfa2dot(const Nfa* nfa, FILE* f) {
fprintf(f, "\tnode [shape = doublecircle]; %d;\n", nfa->accept->id);
fputs("\tnode [shape = circle];\n", f);
states2dot(nfa->start, f);
// Generate an in-arrow to the start state.
// The name is irrelevant since it won't be displayed.
fputs("\tstart [shape = none, label = \"\"];\n", f);
fprintf(f, "\tstart -> %d\n", nfa->start->id);
fputs("}\n", f);
}

0 comments on commit 6387169

Please sign in to comment.