comparison c/regexParser/subsetConstraction.cc @ 141:71f36a59cf6a pairPro

add appendState
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Fri, 11 Dec 2015 13:12:42 +0900
parents 6c258910cacb
children de0f332d560c
comparison
equal deleted inserted replaced
140:84a2a5209d3a 141:71f36a59cf6a
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <ctype.h> 3 #include <ctype.h>
4 #include "subsetConstraction.h" 4 #include "subsetConstraction.h"
5 5
6 void printTransition(TransitionPtr ts) {
7 for (;;) {
8 printf("Input Condition : %c\n",ts->condition->cond->w->word);
9 printf("Next State : "); bitPrint(ts->nextState); printf("\n");
10 if (ts->next == NULL) break;
11 ts = ts->next;
12 }
13 }
14
6 TGValuePtr generateTransition(NodePtr n,TransitionGeneratorPtr tg) { 15 TGValuePtr generateTransition(NodePtr n,TransitionGeneratorPtr tg) {
7 TGValuePtr t = NULL; 16 TGValuePtr tgv0 = NULL;
17 TGValuePtr tgv1 = NULL;
18
19 if (n->tokenType == '+') {
20 tgv0 = generateTransition(n->left,tg);
21 tgv1 = generateTransition(n->right,tg);
22 } else if (n->tokenType == '|') {
23 tgv0 = generateTransition(n->left,tg);
24 tgv1 = generateTransition(n->right,tg);
25 tg->state->transition = appendTransition(tgv0->ts,tgv1->ts);
26 } else if (n->tokenType == '*') {
27 tgv0 = generateTransition(n->left,tg);
28 tgv0->asterisk = true;
29 } else {
30 tgv0 = (TGValuePtr)malloc(sizeof(TGValue));
31 BitVectorPtr bi = createBitVector(n);
32 tgv0->ts = createTransition(n->cc,bi);
33 tgv0->asterisk = false;
34 }
35
36 return tgv0;
37 }
38
39 StatePtr createStateList(NodePtr n) {
40 StatePtr s0 = NULL;
8 if (n->left != NULL) { 41 if (n->left != NULL) {
9 t = generateTransition(n->left, tg); 42 s0 = createStateList(n->left);
10 } 43 }
44
11 if (n->tokenType == 'a') { 45 if (n->tokenType == 'a') {
12 46 BitVectorPtr bi = createBitVector(n);
13 } else if (n->tokenType == 'c') { 47 StatePtr s1 = createState(bi,0,0);
14 t = generateTransition(n,tg); 48 } else if (n->tokenType == '+' || n->tokenType == '|') {
15 } else { 49
16
17 } 50 }
18 51
19 if (n->right != NULL) { 52 if (n->right != NULL) {
20 t = generateTransition(n->right, tg); 53 s0 = createStateList(n->right);
21 } 54 }
22 return t; 55 return s0;
23 } 56 }
57
58 TransitionGeneratorPtr generateTransitionList(NodePtr n) {
59 TransitionGeneratorPtr tg = (TransitionGeneratorPtr)malloc(sizeof(TransitionGenerator));
60 int d = 0;
61 tg->state = createStateList(n);
62 generateTransition(n,tg);
63 return tg;
64 }