annotate regexParser/main.cc @ 228:399380ad95b7

fix generateTransitionGenerator
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Fri, 15 Jan 2016 19:48:53 +0900
parents c38a7b2dd996
children d67649929e96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
89a198fa6b23 add dfrTobin
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
56
8901bc071d33 implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
2 #include <stdlib.h>
8901bc071d33 implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
3 #include <string.h>
187
ef798db705e9 remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 180
diff changeset
4 #include "regexParser.h"
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
5 #include "subsetConstruction.h"
190
3e8e5780ad4a change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 189
diff changeset
6 #include "node.h"
76
d98a036441e2 add createNode comment
masa
parents: 75
diff changeset
7
62
a49b4a8b8c14 implement isLiteral
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 61
diff changeset
8 int main(int argc, char **argv)
55
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
9 {
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
10 bool generate = true;
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
11 bool subset = false;
228
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
12 bool generateSequentialSearch = false;
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
13
178
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
14 RegexInfo ri;
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
15 ri.stateNumber = 1;
56
8901bc071d33 implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
16 for (int i = 1; i < argc; i++) {
8901bc071d33 implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
17 if (strcmp(argv[i],"-regex") == 0) {
178
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
18 ri.ptr = (unsigned char*)argv[i+1]; i++;
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
19 } else if (strcmp(argv[i],"-noGeneration") == 0) {
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
20 generate = false;
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
21 } else if (strcmp(argv[i],"-subset") == 0) {
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
22 subset = true;
228
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
23 } else if (strcmp(argv[i],"-seq") == 0) {
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
24 generateSequentialSearch = true;
56
8901bc071d33 implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
25 }
8901bc071d33 implement string() and literal()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
26 }
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
27 if (!ri.ptr) return 0;
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
28
178
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
29 printf("regex : %s\n",ri.ptr);
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
30 NodePtr n = regex(&ri); // parse only
214
a94f57af1600 remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 195
diff changeset
31 printTree(n);
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
32
219
a8e477f1352d add an example for subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 217
diff changeset
33 if (generate && !subset) { // NFA generation
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
34 TGValue tgv = generateTransitionList(n);
217
a9e3512120e2 NFA generation end
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 216
diff changeset
35 printTree(n);
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
36 printState(tgv.tg);
228
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
37 if (generateSequentialSearch) {
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
38 exportState(tgv.tg);
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
39 }
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
40 } else if (subset) {
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
41 TGValue tgv = generateTransitionList(n);
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
42 SCValue scv = createSCValue(tgv);
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
43 subsetConstruction(scv); // Determinization
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
44 printState(tgv.tg);
228
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
45 if (generateSequentialSearch) {
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
46 exportState(tgv.tg);
399380ad95b7 fix generateTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 222
diff changeset
47 }
216
4852bfa85db4 spell fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 214
diff changeset
48 }
45
89a198fa6b23 add dfrTobin
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 return 0;
89a198fa6b23 add dfrTobin
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }