This source file includes following definitions.
- polishbuild
1
2
3
4
5
6
7
8 static char *rcs_id = "$Id: polish.c,v 1.2 2007/09/09 11:19:56 isao Exp $";
9
10 #include <stdio.h>
11 #include "staslova.h"
12
13 unsigned char **
14 polishbuild(unsigned char **wp)
15 {
16 int i, nest;
17 unsigned char *tempc;
18 unsigned char *stack[MAXNEST][MAXSTACK];
19 unsigned char **sp;
20 unsigned char **sp_save[MAXNEST];
21 unsigned char *polish[MAXWORD+1];
22 unsigned char **wda = wp;
23 sp = stack[0];
24 i = nest = 0;
25
26 if (wda == NULL)
27 return NULL;
28 while (*wda != NULL) {
29 switch (**wda) {
30 case EXP :
31 polish[i++] = *wda;
32 break;
33 case '*' :
34 if (sp != (unsigned char **) &stack[nest]) {
35 if (*(tempc = *--sp) == '*')
36 polish[i++] = tempc;
37 else
38 *sp++ = tempc;
39 }
40 *sp++ = *wda;
41 break;
42 case '+' :
43 case '#' :
44 while (sp != (unsigned char **) &stack[nest])
45 polish[i++] = *--sp;
46 *sp++ = *wda;
47 break;
48 case '(' :
49 sp_save[nest] = sp;
50 if (nest++ == MAXNEST) {
51 fprintf(stderr, "Nesting of `( )\' is too many.\n");
52 return NULL;
53 }
54 sp = stack[nest];
55 break;
56 case ')' :
57 while (sp != (unsigned char **) &stack[nest])
58 polish[i++] = *--sp;
59 if (nest == 0) {
60 fprintf(stderr, "Expression error : pair`(\'not found.\n");
61 return NULL;
62 }
63 sp = sp_save[--nest];
64 break;
65 default :
66 fprintf(stderr, "Unexpected type of condition.\n");
67 return NULL;
68 }
69 wda++;
70 }
71
72 if (nest != 0) {
73 fprintf(stderr, "Expression error : pair`)\'not found.\n");
74 return NULL;
75 }
76 while (sp != (unsigned char **) &stack[nest])
77 polish[i++] = *--sp;
78 polish[i] = NULL;
79 for (i=0; polish[i] != NULL; i++)
80 *(wp + i) = polish[i];
81 *(wp + i) = NULL;
82 return wp;
83 }
84
85
86
87
88