changeset 79:52da06c3f050

add printTree.cc & fix Makefile
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 29 Sep 2015 18:36:31 +0900
parents 23a96fefa643
children 0a452d69f0e2
files c/regexParser/Makefile c/regexParser/main.cc c/regexParser/printTree.cc
diffstat 3 files changed, 46 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/c/regexParser/Makefile	Mon Sep 28 16:53:06 2015 +0900
+++ b/c/regexParser/Makefile	Tue Sep 29 18:36:31 2015 +0900
@@ -1,13 +1,30 @@
 TARGET= regexParser
-OPTION= -Wall -O0 -g
+CFLAGS= -Wall -O0 -g
+CC= clang++
+
+SRCS_TMP = $(wildcard *.cc)
+SRCS_EXCLUDE =  # 除外するファイルを書く
+SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
+OBJS = $(SRCS:.cc=.o)
+
+.SUFFIXES: .cc .o
 
-$(TARGET):main.cc
-	clang $(OPTION) -o $(TARGET) main.cc
+.cc.o:
+	$(CC) $(CFLAGS) -c $< -o $@
+
+all: $(TARGET)
+
+$(TARGET):$(OBJS)
+	$(CC) -o $@ $(OBJS)
+
+link:
+	$(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS)
 
 clean:
-	rm -f $(TARGET)
-	rm -r $(TARGET).dSYM
+	rm -f $(TARGET) $(OBJS)
 	rm -f *~ \#*
 
 test:
 	$(TARGET) -regex "(ab)c"
+	$(TARGET) -regex "(a|b)c"
+	$(TARGET) -regex "(ab)*c"
--- a/c/regexParser/main.cc	Mon Sep 28 16:53:06 2015 +0900
+++ b/c/regexParser/main.cc	Tue Sep 29 18:36:31 2015 +0900
@@ -14,7 +14,6 @@
 unsigned char *ptr;
 unsigned char tokenType;
 int tokenValue;
-NodePtr regexHeadNode;
 
 NodePtr charClass();
 NodePtr group();
@@ -22,6 +21,7 @@
 NodePtr createNode(unsigned char,NodePtr,NodePtr);
 void token();
 NodePtr regexAtom();
+extern void printTree(NodePtr);
 
 
 bool isLiteral(char c) {
@@ -160,27 +160,6 @@
     } return n;
 }
 
-void descendTree(NodePtr n) {
-    static int d = 0;
-    if (n->right != NULL) {
-        d++;
-        descendTree(n->right);
-        d--;
-    }
-    printf("%*c%c\n",d*4, ' ',n->Value.character);
-    if (n->left != NULL) {
-        d++;
-        descendTree(n->left);
-        d--;
-    }
-}
-
-void printTree(NodePtr n) {
-    puts("---Print Node----");
-    descendTree(n);
-    puts("-----------------");
-}
-
 
 int main(int argc, char **argv)
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/c/regexParser/printTree.cc	Tue Sep 29 18:36:31 2015 +0900
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include "regexParser.h"
+
+void descendTree(NodePtr n) {
+    static int d = 0;
+    if (n->right != NULL) {
+        d++;
+        descendTree(n->right);
+        d--;
+    }
+    printf("%*c%c\n",d*4, ' ',n->Value.character);
+    if (n->left != NULL) {
+        d++;
+        descendTree(n->left);
+        d--;
+    }
+}
+
+void printTree(NodePtr n) {
+    puts("---Print Node----");
+    descendTree(n);
+    puts("-----------------");
+}