Mercurial > hg > Members > masakoha > testcode
comparison c/regexParser/main.cc @ 76:d98a036441e2
add createNode comment
author | masa |
---|---|
date | Fri, 28 Aug 2015 20:36:16 +0900 |
parents | 6541eae41a73 |
children | 7f53a587bf97 |
comparison
equal
deleted
inserted
replaced
75:6541eae41a73 | 76:d98a036441e2 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <string.h> | 11 #include <string.h> |
12 | |
13 typedef struct charClass { | |
14 unsigned char table[256]; | |
15 struct utf8Range { | |
16 unsigned char *begin; | |
17 unsigned char *end; | |
18 struct utf8Range *next; | |
19 } *rangeList; | |
20 } CharClass, *CharClassPtr; | |
21 | 12 |
22 typedef struct node { | 13 typedef struct node { |
23 unsigned char type; | 14 unsigned char type; |
24 union value { | 15 union value { |
25 charClass *cc; | 16 charClass *cc; |
29 struct node *parent; | 20 struct node *parent; |
30 struct node *left; | 21 struct node *left; |
31 struct node *right; | 22 struct node *right; |
32 } Node, *NodePtr; | 23 } Node, *NodePtr; |
33 | 24 |
25 typedef struct charClass { | |
26 NodePtr nextState[256]; | |
27 struct utf8Range { | |
28 unsigned char *begin; | |
29 unsigned char *end; | |
30 struct utf8Range *next; | |
31 NodePtr nextState; | |
32 } *rangeList; | |
33 } CharClass, *CharClassPtr; | |
34 | |
34 unsigned char *ptr; | 35 unsigned char *ptr; |
35 unsigned char tokenType; | 36 unsigned char tokenType; |
36 int tokenValue; | 37 int tokenValue; |
37 NodePtr regexHeadNode; | 38 NodePtr regexHeadNode; |
38 | 39 |
39 NodePtr charClass(); | 40 NodePtr charClass(); |
40 NodePtr group(); | 41 NodePtr group(); |
41 NodePtr orexp(); | |
42 NodePtr asterisk(); | |
43 NodePtr regex(); | 42 NodePtr regex(); |
44 NodePtr createNode(unsigned char,NodePtr,NodePtr); | 43 NodePtr createNode(unsigned char,NodePtr,NodePtr); |
45 extern void token(); | 44 void token(); |
46 extern NodePtr regexAtom(); | 45 NodePtr regexAtom(); |
47 | 46 |
48 | 47 |
49 bool isLiteral(char c) { | 48 bool isLiteral(char c) { |
50 if (*ptr > 0x7f) return true; | 49 if (*ptr > 0x7f) return true; |
51 else if (*ptr == '(') return false; | 50 else if (*ptr == '(') return false; |
53 else if (*ptr == '|') return false; | 52 else if (*ptr == '|') return false; |
54 else if (*ptr == '*') return false; | 53 else if (*ptr == '*') return false; |
55 return true; | 54 return true; |
56 } | 55 } |
57 | 56 |
57 /** | |
58 * Create a node of regex parse tree. | |
59 * tokenType | |
60 * regexPosition(state) | |
61 * stateTransitionTable | |
62 */ | |
58 NodePtr createNode(unsigned char character, NodePtr left, NodePtr right) { | 63 NodePtr createNode(unsigned char character, NodePtr left, NodePtr right) { |
59 NodePtr n = (NodePtr)malloc(sizeof(Node)); | 64 NodePtr n = (NodePtr)malloc(sizeof(Node)); |
60 n->self = n; | 65 n->self = n; |
61 n->Value.character = character; | 66 n->Value.character = character; |
62 n->left = left; | 67 n->left = left; |