changeset 68:d27b3af1fe75

remove string()
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 11 Aug 2015 19:46:33 +0900
parents 4842ca2cf8ee
children eecddded9b91
files c/regexParser/main.cc
diffstat 1 files changed, 28 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/c/regexParser/main.cc	Tue Aug 11 15:25:21 2015 +0900
+++ b/c/regexParser/main.cc	Tue Aug 11 19:46:33 2015 +0900
@@ -1,7 +1,6 @@
 /*
  * <literal> ::= [a-z][A-Z][0-9]
  * <charClass> ::= '['<literal>'-'<literal>']'
- * <string> ::= <literal><literal>*
  * <group> ::= '('<regex>')'
  * <regexAtom> ::= <literal>|<charClass>|<group>
  * <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex>
@@ -27,6 +26,7 @@
         unsigned char character;
     } Value, *ValuePtr;
     struct node *self;
+    struct node *parent;
     struct node *left;
     struct node *right;
 } Node, *NodePtr;
@@ -37,7 +37,6 @@
 NodePtr regexHeadNode;
 
 NodePtr charClass();
-NodePtr string();
 NodePtr group();
 NodePtr orexp();
 NodePtr asterisk();
@@ -97,18 +96,6 @@
     return n;
 }
 
-// <string> ::= <literal><literal>*
-NodePtr string() {
-    char c = *ptr;
-    NodePtr n = NULL;
-    if (isLiteral(c)) {
-        n = createNode(0,literal(),string());
-    } else {
-        n = createNode(0,0,0);
-    }
-    return n;
-}
-
 // <group> ::= '('<regex>')'
 NodePtr group() {
     token();
@@ -193,34 +180,44 @@
             n = createNode('+',n,n1);
         }
     } return n;
-} 
+}
 /*
  * e.g.
  *
  * % ./regexParser -regex abc
- *
- *   #-c
- * #-+
- * # #-b
+ *     c
+ *   +
+ *     b
  * +
- * #-a
+ *   a
  *
  * % ./regexParser -regex (a*|bc)d
  *
- *
- * #-d
+ *     d
  * +
- * #   #-c
- * # #-+
- * # # #-b
- * #-|
- *   #
- *   #-*
- *     #-a
- *
+ *       c
+ *     +
+ *       b
+ *   |
+ *     *
+ *       a
  */
+
+void descendTree(NodePtr n,int d) {
+    if (n->right != NULL) {
+        d++;
+        descendTree(n->right, d);
+    } else if (n->left != NULL) {
+        d++;
+        descendTree(n->right, d);
+    } else {
+        printf("%c\n",n->Value.character);
+    }
+}
+
 void printTree(NodePtr n) {
-    
+    int depth = 0;
+    descendTree(n,depth);
 }