annotate c/regexParser/createRegexParser.cc @ 99:1e5b56e8263b impl-bitvector

remove some variable
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 10 Nov 2015 20:57:59 +0900
parents 0b6940588e88
children 3eb3cb5d581f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdlib.h>
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
2 #include <stdio.h>
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "regexParser.h"
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
5 NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr);
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 NodePtr charClass(RegexInfoPtr);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 NodePtr group(RegexInfoPtr);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 void token(RegexInfoPtr);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 NodePtr regexAtom(RegexInfoPtr);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 NodePtr regex(RegexInfoPtr);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 /**
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 * Create a node of regex parse tree.
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 * tokenType
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 * regexPosition(state)
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 * stateTransitionTable
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 */
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
18 NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) {
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 NodePtr n = (NodePtr)malloc(sizeof(Node));
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
20 n->tokenType = ri->tokenType;
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 n->self = n;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 n->Value.character = character;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 n->left = left;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 n->right = right;
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
25
99
1e5b56e8263b remove some variable
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
26 if (ri->tokenType == '*') {
1e5b56e8263b remove some variable
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
27 n->left->parent = n->self;
1e5b56e8263b remove some variable
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
28 } else if (ri->tokenType != 'a') {
97
0b6940588e88 add node->parent
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
29 n->right = right;
0b6940588e88 add node->parent
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
30 n->left->parent = n->right->parent = n->self;
0b6940588e88 add node->parent
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
31 }
0b6940588e88 add node->parent
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
32
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
33 if (ri->tokenType == 'a') {
91
912d7bd51f38 remove static variable in createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 89
diff changeset
34 n->nodeNumber = ri->nodeNumber;
912d7bd51f38 remove static variable in createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 89
diff changeset
35 ri->nodeNumber++;
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
36 ri->tokenType = 0;
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
37 }
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 return n;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 // <charClass> ::= '['<literal>'-'<literal>']'
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 NodePtr charClass(RegexInfoPtr ri) {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 NodePtr n = (NodePtr)malloc(sizeof(Node));
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 unsigned char startChar = ri->ptr[0];
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 while (ri->ptr[0] == '-') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 unsigned char endChar = ri->ptr[0];
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 unsigned char *charTable = (unsigned char*)malloc(sizeof(char)*256);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 return n;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 // <literal> ::= [a-z][A-Z][0-9]
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 NodePtr literal(RegexInfoPtr ri) {
85
5072a44ed842 add Word
masa
parents: 82
diff changeset
56 unsigned char *top = ri->ptr;
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
57 NodePtr n = createNode(ri,ri->ptr[0],0,0);
87
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
58 ri->ptr++;
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 return n;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 // <group> ::= '('<regex>')'
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 NodePtr group(RegexInfoPtr ri) {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 return regex(ri);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 void token(RegexInfoPtr ri) {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 while (ri->ptr[0] != '\0') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 if (ri->ptr[0] == '('){
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 ri->tokenType = '(';
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 ri->tokenValue = 0;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 if (ri->ptr[1] == ')') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 return;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 } else if (ri->ptr[0] == ')') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 ri->tokenType = ')';
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 ri->tokenValue = ri->ptr[0];
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 return;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 } else if (ri->ptr[0] == '[') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 ri->tokenType = '[';
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 ri->tokenValue = ri->ptr[0];
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 if (ri->ptr[1] == ']') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 return;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 } else if (ri->ptr[0] == '|'){
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 ri->tokenType = '|';
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 ri->tokenValue = 0;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 return;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 } else if (ri->ptr[0] == '*'){
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 ri->ptr++;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 ri->tokenType = '*';
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 ri->tokenValue = 0;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 return;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 } else if (ri->ptr[0] == '\\'){
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 // need more proccesing
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 /*
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 \277
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 \0xa5
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 \[
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 \\
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 \utf-8 etc...
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 */
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 } else {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 ri->tokenType = 'a';
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 ri->tokenValue = ri->ptr[0];
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 return;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 ri->tokenType = 0;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 ri->tokenValue = 0;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 return;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 // <regexAtom> ::= <literal>|<charClass>|<group>
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 NodePtr regexAtom(RegexInfoPtr ri) {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 token(ri);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 NodePtr n = NULL;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 if (ri->tokenType == 'a') n = literal(ri);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 else if (ri->tokenType == '[') n = charClass(ri);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 else if (ri->tokenType == '(') n = group(ri);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 return n;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 // <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex>
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 NodePtr regex(RegexInfoPtr ri) {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 NodePtr n = regexAtom(ri);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 while (ri->ptr[0]) {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 token(ri);
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 if (ri->tokenType == '*') {
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
140 n = createNode(ri,'*',n,0);
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 } else if (ri->tokenType == '|') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 NodePtr n1 = regex(ri);
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
143 n = createNode(ri,'|',n,n1);
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 } else if (ri->tokenType == ')') {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 return n;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 } else {
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 NodePtr n1 = regex(ri);
89
50a146c05192 add NodeNumber in Regex Parser tree
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
148 n = createNode(ri,'+',n,n1);
82
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 } return n;
1d9bbf922bb6 add createRegexTree.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 }