changeset 66:f8fb3b463f70

fix when '|' come procces
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Tue, 04 Aug 2015 16:41:41 +0900
parents 20b7d4e958bb
children 4842ca2cf8ee
files c/regexParser/main.cc
diffstat 1 files changed, 35 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/c/regexParser/main.cc	Thu Jul 30 23:55:53 2015 +0900
+++ b/c/regexParser/main.cc	Tue Aug 04 16:41:41 2015 +0900
@@ -3,9 +3,8 @@
  * <charClass> ::= '['<literal>'-'<literal>']'
  * <string> ::= <literal><literal>*
  * <group> ::= '('<regex>')'
- * <or> ::= <regex>'|'<regex>
- * <*> ::= <regex>'*'
- * <regex> ::= <string>|<or>|<charClass>|<group>|<*>
+ * <regexAtom> ::= <literal>|<charClass>|<group>
+ * <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex>
  */
 
 #include <stdio.h>
@@ -177,8 +176,9 @@
     while (*ptr) {
         token();
         if (tokenType == '*') {
-            n = createNode('*',n,0);
+            n = createNode('*',n,0); ptr++;
         } else if (tokenType == '|') {
+            ptr++;
             NodePtr n1 = regex();
             n = createNode('|',n,n1);
         } else {
@@ -190,6 +190,36 @@
 }
 
 
+/*
+ * e.g.
+ *
+ * % ./regexParser -regex abc
+ *
+ *   #-c
+ * #-+
+ * # #-b
+ * +
+ * #-a
+ *
+ * % ./regexParser -regex (a*|bc)d
+ *
+ *
+ * #-d
+ * +
+ * #   #-c
+ * # #-+
+ * # # #-b
+ * #-|
+ *   #
+ *   #-*
+ *     #-a
+ *
+ */
+void printTree(NodePtr n) {
+
+}
+
+
 int main(int argc, char **argv)
 {
     for (int i = 1; i < argc; i++) {
@@ -200,5 +230,6 @@
 
     printf("regex : %s\n",ptr);
     NodePtr n = regex();
+    printTree(n);
     return 0;
 }