RPA Toolkit
Added more information when displaying the DFA states
authorMartin Stoilov <martin@rpasearch.com>
Thu, 28 Apr 2016 02:24:33 +0000 (19:24 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Thu, 28 Apr 2016 01:24:55 +0000 (18:24 -0700)
rex/rexdfa.c
tests/testrex/build/unix/testrex.mk
tests/testrex/main.c

index 086c02e..9930367 100644 (file)
@@ -180,7 +180,8 @@ void rex_dfa_dumpstate(rexdfa_t *dfa, rexuint_t nstate)
        if (!s)
                return;
        fprintf(stdout, "State %ld", (unsigned long)nstate);
-       fprintf(stdout, " (");
+       if (s->nsubstates)
+               fprintf(stdout, " : NFA-States(");
        for (index = 0; index < s->nsubstates; index++) {
                ss = REX_DFA_SUBSTATE(dfa, nstate, index);
                if (ss) {
@@ -191,10 +192,10 @@ void rex_dfa_dumpstate(rexdfa_t *dfa, rexuint_t nstate)
                                fprintf(stdout, ",");
                }
        }
-       fprintf(stdout, ")");
-
+       if (s->nsubstates)
+               fprintf(stdout, ")");
 
-       fprintf(stdout, ": ");
+       fprintf(stdout, " : ");
        if (s->type == REX_STATETYPE_ACCEPT) {
                fprintf(stdout, " REX_STATETYPE_ACCEPT ");
                fprintf(stdout, " (");
index 576138a..a0211a6 100644 (file)
@@ -12,6 +12,7 @@ LIBS += -lrex -lrlib -lm
 
 
 TESTS  += $(OUTDIR)/rexregex
+TESTS  += $(OUTDIR)/main
 
 
 all : $(OUTDIR) $(TESTS)
@@ -21,10 +22,6 @@ $(OUTDIR)/%: $(TESTS_SRCDIR)/%.c
        + $(CC) $(CFLAGS) -o $(OUTDIR)/$* $(TESTS_SRCDIR)/$*.c  -lrex $(LIBS) $(LDFLAGS) $(INCLUDE)
 
 
-$(OUTDIR)/%.o: $(TESTS_SRCDIR)/%.rpa
-       $(LD) -r -b binary -o $(OUTDIR)/$*.o $(TESTS_SRCDIR)/$*.rpa
-
-
 $(OUTDIR):
        @mkdir $(OUTDIR)
 
index 3a55ac1..814ea27 100644 (file)
@@ -4,10 +4,12 @@
 #include "rlib/rutf.h"
 #include "rlib/rarray.h"
 #include "rlib/rmem.h"
-#include "rexdb.h"
-#include "rexstate.h"
-#include "rexnfasimulator.h"
-#include "rexcompiler.h"
+#include "rex/rexdb.h"
+#include "rex/rexstate.h"
+#include "rex/rexnfasimulator.h"
+#include "rex/rexcompiler.h"
+#include "rex/rexdfaconv.h"
+
 
 static void init_ababb(rexdb_t *nfa)
 {
@@ -53,6 +55,28 @@ static void init_ababb(rexdb_t *nfa)
 }
 
 
+static void init_s4(rexdb_t *nfa)
+{
+       rexstate_t *s1 = rex_state_create(0, REX_STATETYPE_START);
+       rexstate_t *s2 = rex_state_create(2, REX_STATETYPE_NONE);
+       rexstate_t *s3 = rex_state_create(3, REX_STATETYPE_ACCEPT);
+       rexstate_t *s4 = rex_state_create(4, REX_STATETYPE_NONE);
+
+       rex_db_insertstate(nfa, s1);
+       rex_db_insertstate(nfa, s2);
+       rex_db_insertstate(nfa, s3);
+       rex_db_insertstate(nfa, s4);
+
+       rex_state_addtransition_e_dst(s2, s1);
+       rex_state_addtransition_e_dst(s4, s3);
+
+       rex_state_addtransition_dst(s1, 'a', 'a', s2);
+       rex_state_addtransition_dst(s2, 'b', 'b', s3);
+       rex_state_addtransition_dst(s1, 'c', 'c', s4);
+       rex_state_addtransition_dst(s4, 'c', 'c', s3);
+}
+
+
 int main(int argc, char *argv[])
 {
        int i;
@@ -76,9 +100,19 @@ int main(int argc, char *argv[])
                        for (j = 0; j < r_array_length(nfa->states); j++) {
                                rex_db_dumpstate(nfa, j);
                        }
+               } else if (strcmp(argv[i], "-d") == 0) {
+                       int j;
+                       rexdfa_t *dfa = rex_db_todfa(nfa, 1);
+                       for (j = 0; j < dfa->nstates; j++) {
+                               rex_dfa_dumpstate(dfa, j);
+                       }
+                       rex_dfa_destroy(dfa);
                } else if (strcmp(argv[i], "-ababb") == 0) {
                        init_ababb(nfa);
                        startstate = 0;
+               } else if (strcmp(argv[i], "-s4") == 0) {
+                       init_s4(nfa);
+                       startstate = 0;
                } else {
                        if (startstate < 0)
                                return 1;