This source file includes following definitions.
- matchword
- push
- pop
1
2
3
4
5
6
7
8 static char *rcs_id = "$Id: binary.c,v 1.2 2007/09/09 11:19:56 isao Exp $";
9
10 #include <stdio.h>
11 #include "staslova.h"
12 #include "table.h"
13
14 int mstck[MAXSTACK];
15 int msp = 0;
16 int stackop;
17
18 int
19 matchword(unsigned char *wd, struct cdent *cp)
20 {
21 void push(int);
22 int pop(void);
23
24 unsigned char **polp = cp->cdpolish;
25 int op2, ans;
26
27 stackop = 0;
28 while (*polp != NULL && stackop == 0) {
29 switch (**polp) {
30 case EXP :
31 push(unarymatch(wd, *polp + 2));
32 break;
33 case '+' :
34 push(pop() | pop());
35 break;
36 case '*' :
37 push(pop() * pop());
38 break;
39 case '#' :
40 op2 = pop();
41 push(pop() * (!op2));
42 break;
43 default :
44 fprintf(stderr, "Unknown expression.(matchword)\n");
45 return UNMATCH;
46 }
47 polp++;
48 }
49 ans = pop();
50 if (stackop != 0)
51 return UNMATCH;
52 return ans;
53 }
54
55 void
56 push(int val)
57 {
58 if (msp < MAXSTACK) {
59 mstck[msp++] = val;
60 stackop |= 0;
61 } else {
62 fprintf(stderr, "Expression stack full.(push)\n");
63 stackop |= 1;
64 }
65 }
66
67 int
68 pop(void)
69 {
70 if (msp > 0) {
71 return mstck[--msp];
72 stackop |= 0;
73 } else {
74 fprintf(stderr, "Expression stack empty," \
75 "probably problems in your multiple operations.(pop)\n");
76 stackop |= 2;
77 }
78 }