Revision 6952,
1.7 KB
checked in by probe, 31 years ago
(diff) |
Initial revision
|
-
Property svn:executable set to
*
|
Line | |
---|
1 | /* Copyright (C) 1988 Tim Shepard All rights reserved. */ |
---|
2 | |
---|
3 | #include "synctree.h" |
---|
4 | |
---|
5 | static bool_exp newb() |
---|
6 | { |
---|
7 | register char *foo; |
---|
8 | if (foo = (char *) malloc(sizeof(struct boolstruct))) |
---|
9 | return (bool_exp) foo; |
---|
10 | else |
---|
11 | panic("bool newb: malloc returned null pointer"); |
---|
12 | } |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | bool_exp bool_var(s) |
---|
17 | char *s; |
---|
18 | { |
---|
19 | bool_exp new; |
---|
20 | new = newb(); |
---|
21 | new->type = VARIABLE; |
---|
22 | new->variable = s; |
---|
23 | return new; |
---|
24 | } |
---|
25 | |
---|
26 | bool_exp bool_not(b) |
---|
27 | bool_exp b; |
---|
28 | { |
---|
29 | bool_exp new; |
---|
30 | new = newb(); |
---|
31 | new->type = UNARY; |
---|
32 | new->op = NOT; |
---|
33 | new->left = b; |
---|
34 | return new; |
---|
35 | } |
---|
36 | |
---|
37 | bool_exp bool_and(bl,br) |
---|
38 | bool_exp bl,br; |
---|
39 | { |
---|
40 | bool_exp new; |
---|
41 | new = newb(); |
---|
42 | new->type = BINARY; |
---|
43 | new->op = AND; |
---|
44 | new->left = bl; |
---|
45 | new->right = br; |
---|
46 | return new; |
---|
47 | } |
---|
48 | |
---|
49 | bool_exp bool_or(bl,br) |
---|
50 | bool_exp bl,br; |
---|
51 | { |
---|
52 | bool_exp new; |
---|
53 | new = newb(); |
---|
54 | new->type = BINARY; |
---|
55 | new->op = OR; |
---|
56 | new->left = bl; |
---|
57 | new->right = br; |
---|
58 | return new; |
---|
59 | } |
---|
60 | |
---|
61 | void bool_free(b) |
---|
62 | bool_exp b; |
---|
63 | { |
---|
64 | switch(b->type) { |
---|
65 | case VARIABLE: |
---|
66 | sfree(b->variable); |
---|
67 | break; |
---|
68 | case BINARY: |
---|
69 | bool_free(b->right); |
---|
70 | case UNARY: |
---|
71 | bool_free(b->left); |
---|
72 | break; |
---|
73 | default: |
---|
74 | panic("bool_free"); |
---|
75 | } |
---|
76 | free(b); |
---|
77 | } |
---|
78 | |
---|
79 | bool bool_eval(b) |
---|
80 | bool_exp b; |
---|
81 | { |
---|
82 | switch(b->type) { |
---|
83 | case VARIABLE: |
---|
84 | return getvar(b->variable); |
---|
85 | case UNARY: |
---|
86 | switch(b->op) { |
---|
87 | case NOT: |
---|
88 | return (bool) ! bool_eval(b->left); |
---|
89 | default: |
---|
90 | panic("bool_eval: unknown unary operator"); |
---|
91 | } |
---|
92 | case BINARY: |
---|
93 | switch(b->op) { |
---|
94 | case AND: |
---|
95 | return (bool) (bool_eval(b->left) && bool_eval(b->right)); |
---|
96 | case OR: |
---|
97 | return (bool) (bool_eval(b->left) || bool_eval(b->right)); |
---|
98 | default: |
---|
99 | panic("bool_eval: unknown binary operator"); |
---|
100 | } |
---|
101 | default: |
---|
102 | panic("bool_eval: unknown bool_exp type"); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
Note: See
TracBrowser
for help on using the repository browser.