Mercurial > baum
annotate baum.c @ 10:0e15841ae111
s/list/stack/g because thats what it is
author | meillo@marmaro.de |
---|---|
date | Sat, 09 Feb 2008 16:49:29 +0100 |
parents | c020b0d1cfca |
children | 8e34daa80f64 |
rev | line source |
---|---|
0 | 1 /* |
2 * baum - an esoteric programming language | |
3 * | |
4 * (c) markus schnalke <meillo@marmaro.de> | |
5 * and julian forster | |
6 * | |
7 */ | |
8 | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
12 #include <string.h> |
0 | 13 |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
14 #include "baum.h" |
2 | 15 #include "actions.h" |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
16 |
0 | 17 |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
18 struct Node* root = 0; |
10 | 19 struct Stackitem* stack = NULL; |
0 | 20 |
21 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
22 void logit(char* text) { |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
23 fprintf(stderr, "[%s]\n", text); |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
24 } |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
25 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
26 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
27 /* new */ |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
28 struct Node* newNode(char* name, unsigned char value) { |
0 | 29 struct Node* node; |
30 node = (struct Node*) malloc(sizeof(struct Node)); | |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
31 strcpy(node->name, name); |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
32 node->value = value; |
0 | 33 node->right = 0; |
34 node->down = 0; | |
35 return node; | |
36 } | |
37 | |
38 | |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
39 void setValue(struct Node* node, unsigned char value) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
40 node->value = value; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
41 } |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
42 |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
43 |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
44 struct Node* nextNode(struct Node* node) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
45 return node->right; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
46 } |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
47 |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
48 struct Node* lastNode(struct Node* node) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
49 while (node->right != NULL) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
50 node = node->right; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
51 } |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
52 return node; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
53 } |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
54 |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
55 void insertLast(struct Node* node, struct Node* insert) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
56 node = lastNode(node); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
57 node->right = insert; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
58 } |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
59 |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
60 /* delete */ |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
61 void delete(struct Node* node) { |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
62 if (node != NULL) { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
63 if (node->down != NULL) { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
64 delete(node->down); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
65 } |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
66 if (node->right != NULL) { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
67 delete(node->right); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
68 } |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
69 free(node); node=0; |
0 | 70 } |
71 } | |
72 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
73 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
74 /* print */ |
0 | 75 void printNode(struct Node* node) { |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
76 if (node != NULL) { |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
77 fprintf(stderr, "Node: %10s (%d|%c)\n", node->name, node->value, node->value); |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
78 } |
0 | 79 } |
80 | |
81 void printTree(struct Node* root) { | |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
82 if (root != NULL) { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
83 printNode(root); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
84 fprintf(stderr, " down: "); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
85 if (root->down != NULL) { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
86 printTree(root->down); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
87 } else { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
88 fprintf(stderr, "NULL\n"); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
89 } |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
90 fprintf(stderr, " right: "); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
91 if (root->right != NULL) { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
92 printTree(root->right); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
93 } else { |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
94 fprintf(stderr, "NULL\n"); |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
95 } |
0 | 96 } |
97 } | |
98 | |
99 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
100 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
101 /* traverse */ |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
102 void traverse(struct Node* root) { |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
103 /* each node controlls the nodes below itself */ |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
104 action(root); |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
105 } |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
106 |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
107 |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
108 |
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
109 |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
110 void push(struct Node* node) { |
10 | 111 struct Stackitem* tmp; |
112 struct Stackitem* new; | |
113 new = (struct Stackitem*) malloc(sizeof(struct Stackitem)); | |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
114 new->node = node; |
10 | 115 tmp = stack; |
116 stack = new; | |
117 stack->next = tmp; | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
118 } |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
119 struct Node* pull() { |
10 | 120 if (stack == NULL) { |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
121 return NULL; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
122 } |
10 | 123 struct Stackitem* tmp; |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
124 struct Node* node; |
10 | 125 tmp = stack; |
126 stack = stack->next; | |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
127 node = tmp->node; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
128 free(tmp); tmp=0; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
129 return node; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
130 } |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
131 |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
132 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
133 |
6 | 134 /* read input */ |
8 | 135 void read_input() { |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
136 int c; |
8 | 137 int indent; |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
138 char name[256]; |
6 | 139 int value; |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
140 int last_indent; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
141 struct Node* last_node; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
142 struct Node* node; |
6 | 143 |
8 | 144 indent = 0; |
145 strcpy(name, ""); | |
146 value = 0; | |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
147 last_indent = -1; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
148 root = newNode("blackhole", 0); |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
149 last_node = root; |
6 | 150 |
8 | 151 while ((c = getchar()) != EOF) { |
152 if (c == '#') { /* comment */ | |
153 while ((c = getchar()) != '\n') { | |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
154 } |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
155 } |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
156 |
8 | 157 if (c == ' ' || c == '\t') { /* indent if at start of line */ |
158 if (strlen(name) == 0) { | |
159 indent++; | |
160 } | |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
161 } |
6 | 162 |
8 | 163 if (c == '\n') { /* end of line: create node */ |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
164 if (strlen(name) > 0) { |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
165 fprintf(stderr, " %d - %s - %d\n", indent, name, value); |
8 | 166 /* create node */ |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
167 node = newNode((char*) name, value); |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
168 if (indent > last_indent) { /* down */ |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
169 last_node->down = node; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
170 push(last_node); |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
171 } else if (indent == last_indent) { /* right */ |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
172 last_node->right = node; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
173 } else if (indent < last_indent) { /* up */ |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
174 /* FIXME what if it goes more than one level up? */ |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
175 last_node = pull(); |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
176 last_node->right = node; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
177 } |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
178 last_indent = indent; |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
179 last_node = node; |
6 | 180 } |
181 indent = 0; | |
182 strcpy(name, ""); | |
183 value = 0; | |
184 } | |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
185 |
8 | 186 if (c >= 'a' && c <= 'z') { /* name */ |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
187 int i = 1; |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
188 name[0] = (char) c; |
8 | 189 while ((c = getchar()) != '(') { |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
190 name[i] = (char) c; |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
191 i++; |
8 | 192 if (i > 255) { |
193 break; | |
194 } | |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
195 } |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
196 name[i] = '\0'; |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
197 } |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
198 |
8 | 199 if (c == '(') { /* value */ |
200 scanf("%d)", &value); | |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
201 } |
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
202 |
6 | 203 } |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
204 |
6 | 205 } |
206 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
207 /* main */ |
0 | 208 int main(int argc, char* argv[]) { |
7
6a6152cf63f7
new implementation of the read input function
meillo@marmaro.de
parents:
6
diff
changeset
|
209 unsigned char shell_return = 0; |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
210 |
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
211 read_input(); |
0 | 212 printTree(root); |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
213 |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
214 shell_return = action(root); |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
215 |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
216 printTree(root); |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
217 delete(root); |
9
c020b0d1cfca
read input is now finished in first version; removed init; added push and pull; name is now array instead of pointer
meillo@marmaro.de
parents:
8
diff
changeset
|
218 |
5
c202ccccedb5
added checks for null pointer; print echoes as char or number now (depends on value); all logging goes to stderr now; new nodes blackhole and times (not implemented yet)
meillo@marmaro.de
parents:
4
diff
changeset
|
219 exit(shell_return); |
0 | 220 } |