Mercurial > baum
annotate baum.c @ 6:ab87b154a96b
first tries for the read input function
author | meillo@marmaro.de |
---|---|
date | Fri, 08 Feb 2008 21:44:07 +0100 |
parents | c202ccccedb5 |
children | 6a6152cf63f7 |
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; |
0 | 19 |
20 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
21 void logit(char* text) { |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
22 fprintf(stderr, "[%s]\n", text); |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
23 } |
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 /* new */ |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
27 struct Node* newNode(char* name, unsigned char value) { |
0 | 28 struct Node* node; |
29 node = (struct Node*) malloc(sizeof(struct Node)); | |
30 node->name = name; | |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
31 node->value = value; |
0 | 32 node->right = 0; |
33 node->down = 0; | |
34 return node; | |
35 } | |
36 | |
37 | |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
38 void setValue(struct Node* node, unsigned char value) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
39 node->value = value; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
40 } |
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 struct Node* nextNode(struct Node* node) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
44 return node->right; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
45 } |
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 struct Node* lastNode(struct Node* node) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
48 while (node->right != NULL) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
49 node = node->right; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
50 } |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
51 return node; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
52 } |
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 void insertLast(struct Node* node, struct Node* insert) { |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
55 node = lastNode(node); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
56 node->right = insert; |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
57 } |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
58 |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
59 /* delete */ |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 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
|
64 } |
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 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
|
66 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
|
67 } |
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 free(node); node=0; |
0 | 69 } |
70 } | |
71 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
72 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
73 /* print */ |
0 | 74 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
|
75 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
|
76 fprintf(stderr, "Node: %20s (%d|%c)\n", node->name, node->value, node->value); |
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
|
77 } |
0 | 78 } |
79 | |
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 } 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
|
87 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
|
88 } |
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 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
|
90 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
|
91 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
|
92 } 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
|
93 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
|
94 } |
0 | 95 } |
96 } | |
97 | |
98 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
99 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
100 /* traverse */ |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
101 void traverse(struct Node* root) { |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
102 /* each node controlls the nodes below itself */ |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
103 action(root); |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
104 } |
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 /* init */ |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
107 void init() { |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
108 /* add some numbers |
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
|
109 root = newNode("print", 'n'); |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
110 root->down = newNode("sum", 0); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
111 |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
112 root->down->down = newNode("number", 60); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
113 |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
114 root->down->down->right = newNode("number", 50); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
115 |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
116 root->down->down->right->right = newNode("sum", 0); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
117 root->down->down->right->right->down = newNode("number", 1); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
118 root->down->down->right->right->down->right = newNode("number", 5); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
119 */ |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
120 |
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
|
121 /* input numbers and add them |
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
|
122 root = newNode("print", 'n'); |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
123 root->down = newNode("sum", 0); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
124 root->down->down = newNode("input", 0); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
125 root->down->down->right = newNode("input", 0); |
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
126 root->down->down->right->right = newNode("input", 0); |
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
|
127 */ |
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
|
128 |
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
|
129 /* prints HelloWorld |
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
|
130 */ |
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
|
131 struct Node* np = 0; |
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
|
132 |
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
|
133 root = newNode("blackhole", 0); |
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
|
134 root->down = newNode("sum", 0); |
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
|
135 root->down->down = newNode("print", 'c'); |
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
|
136 np = root->down->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
|
137 np->down = newNode("number", 'H'); |
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
|
138 |
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
|
139 np->right = newNode("print", 'c'); |
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
|
140 np->right->down = newNode("number", 'e'); |
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
|
141 np = np->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
|
142 |
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
|
143 np->right = newNode("print", 'c'); |
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
|
144 np->right->down = newNode("number", 'l'); |
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
|
145 np = np->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
|
146 |
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
|
147 np->right = newNode("print", 'c'); |
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
|
148 np->right->down = newNode("number", 'l'); |
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
|
149 np = np->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
|
150 |
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
|
151 np->right = newNode("print", 'c'); |
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
|
152 np->right->down = newNode("number", 'o'); |
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
|
153 np = np->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
|
154 |
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
|
155 np->right = newNode("print", 'c'); |
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
|
156 np->right->down = newNode("number", ' '); |
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
|
157 np = np->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
|
158 |
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
|
159 np->right = newNode("print", 'c'); |
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
|
160 np->right->down = newNode("number", 'L'); |
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
|
161 np = np->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
|
162 |
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
|
163 np->right = newNode("print", 'c'); |
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
|
164 np->right->down = newNode("number", 'y'); |
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
|
165 np = np->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
|
166 |
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
|
167 np->right = newNode("print", 'c'); |
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
|
168 np->right->down = newNode("number", 'd'); |
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
|
169 np = np->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
|
170 |
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
|
171 np->right = newNode("print", 'c'); |
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
|
172 np->right->down = newNode("number", 'i'); |
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
|
173 np = np->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
|
174 |
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
|
175 np->right = newNode("print", 'c'); |
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
|
176 np->right->down = newNode("number", 10); |
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
|
177 np = np->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
|
178 |
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
|
179 |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
180 } |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
181 |
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
182 |
6 | 183 /* read input */ |
184 void read_input(char* filename) { | |
185 FILE* fp; | |
186 char c; | |
187 char* line; | |
188 int indent; | |
189 char* name; | |
190 int value; | |
191 | |
192 fp = fopen(filename, "r"); | |
193 indent = 0; | |
194 | |
195 while ((c = getc(fp)) != EOF) { | |
196 if (c == ' ' || c == '\t') { | |
197 indent++; | |
198 } else if (c == '(') { | |
199 fscanf(fp, "%d", &value); | |
200 } else if (c == '\n') { | |
201 | |
202 if (strcmp(name, "") != 0) { | |
203 printf("\nindent: %d\nname: %s\nvalue: %d\n", indent, name, value); | |
204 } | |
205 indent = 0; | |
206 strcpy(name, ""); | |
207 value = 0; | |
208 } else { | |
209 fscanf(fp, "%[a-z]", name); | |
210 } | |
211 } | |
212 } | |
213 | |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
214 /* main */ |
0 | 215 int main(int argc, char* argv[]) { |
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
|
216 unsigned char shell_return; |
6 | 217 /* |
0 | 218 init(); |
4 | 219 |
0 | 220 printTree(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
|
221 fprintf(stderr, "\n\n"); |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
222 |
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
|
223 shell_return = action(root); |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
224 |
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
|
225 fprintf(stderr, "\n\n"); |
3
15d7d6b9766f
added input; added nextNode, lastNode, insertLast
meillo@marmaro.de
parents:
2
diff
changeset
|
226 printTree(root); |
4 | 227 |
1
3da0ff17c8e7
added features (print, sum, number); split in header file
meillo@marmaro.de
parents:
0
diff
changeset
|
228 delete(root); |
6 | 229 */ |
0 | 230 |
6 | 231 read_input("./input_addition"); |
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
|
232 exit(shell_return); |
0 | 233 } |