comparison c/regexParser/main.cc @ 62:a49b4a8b8c14

implement isLiteral
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 14 Jul 2015 16:45:07 +0900
parents 67cade0e35b0
children 8fd3d35e9861
comparison
equal deleted inserted replaced
61:67cade0e35b0 62:a49b4a8b8c14
28 NodePtr _or(); 28 NodePtr _or();
29 NodePtr asterisk(); 29 NodePtr asterisk();
30 NodePtr regex(); 30 NodePtr regex();
31 NodePtr createNode(char,NodePtr,NodePtr); 31 NodePtr createNode(char,NodePtr,NodePtr);
32 32
33 bool isLiteral(char c) {
34 if (('a'<=c && c<='z')||('A'<=c && c<='Z')||('0'<=c && c<='9')) {
35 return true;
36 }
37 return false;
38 }
39
33 void printNodeDate(NodePtr n) { 40 void printNodeDate(NodePtr n) {
34 puts("---------------------"); 41 puts("---------------------");
35 printf("Self Node char : %c\n", n->character); 42 printf("Self Node char : %c\n", n->character);
36 printf("Self Node addr : %p\n", n->self); 43 printf("Self Node addr : %p\n", n->self);
37 printf("left Node addr : %p\n", n->left); 44 printf("left Node addr : %p\n", n->left);
51 return n; 58 return n;
52 } 59 }
53 60
54 // <charClass> ::= '['<literal>'-'<literal>']' 61 // <charClass> ::= '['<literal>'-'<literal>']'
55 NodePtr charClass() { 62 NodePtr charClass() {
56 63 ptr++;
64 NodePtr n = (NodePtr)malloc(sizeof(Node));
65 return n;
57 } 66 }
58 67
59 // <literal> ::= [a-z][A-Z][0-9] 68 // <literal> ::= [a-z][A-Z][0-9]
60 NodePtr literal() { 69 NodePtr literal() {
61 char c = *ptr; 70 char c = *ptr;
62 NodePtr n = createNode(c,0,0); 71 NodePtr n = createNode(c,0,0);
63 ptr++; 72 ptr++;
64 return n; 73 return n;
65 }
66
67 bool isLiteral(char c) {
68 if (('a'<=c && c<='z')||('A'<=c && c<='Z')||('0'<=c && c<='9')) {
69 return true;
70 }
71 return false;
72 } 74 }
73 75
74 // <string> ::= <literal><literal>* 76 // <string> ::= <literal><literal>*
75 NodePtr string() { 77 NodePtr string() {
76 char c = *ptr; 78 char c = *ptr;
91 ptr++; 93 ptr++;
92 } else { 94 } else {
93 ptr++; 95 ptr++;
94 n = regex(); 96 n = regex();
95 } 97 }
96
97 return n; 98 return n;
98 } 99 }
99 100
100 101
101 // <or> ::= <regex>'|'<regex> 102 // <or> ::= <regex>'|'<regex>
129 } else { 130 } else {
130 n = string(); 131 n = string();
131 regexHeadNode = n; 132 regexHeadNode = n;
132 } 133 }
133 } 134 }
134
135 return n; 135 return n;
136 } 136 }
137 137
138 int 138 int main(int argc, char **argv)
139 main(int argc, char **argv)
140 { 139 {
141 for (int i = 1; i < argc; i++) { 140 for (int i = 1; i < argc; i++) {
142 if (strcmp(argv[i],"-regex") == 0) { 141 if (strcmp(argv[i],"-regex") == 0) {
143 ptr = argv[i+1]; i++; 142 ptr = argv[i+1]; i++;
144 } 143 }
145 } 144 }
146 145
147 printf("regex : %s\n",ptr); 146 printf("regex : %s\n",ptr);
148 NodePtr n = regex(); 147 NodePtr n = regex();
149
150 return 0; 148 return 0;
151 } 149 }