00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef STATIC
00020 #define STATIC static
00021 #endif
00022
00023
00024 STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
00025 unsigned long int n))
00026 internal_function;
00027
00028 STATIC
00029 unsigned long int
00030 internal_function
00031 plural_eval (pexp, n)
00032 struct expression *pexp;
00033 unsigned long int n;
00034 {
00035 switch (pexp->nargs)
00036 {
00037 case 0:
00038 switch (pexp->operation)
00039 {
00040 case var:
00041 return n;
00042 case num:
00043 return pexp->val.num;
00044 default:
00045 break;
00046 }
00047
00048 break;
00049 case 1:
00050 {
00051
00052 unsigned long int arg = plural_eval (pexp->val.args[0], n);
00053 return ! arg;
00054 }
00055 case 2:
00056 {
00057 unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
00058 if (pexp->operation == lor)
00059 return leftarg || plural_eval (pexp->val.args[1], n);
00060 else if (pexp->operation == land)
00061 return leftarg && plural_eval (pexp->val.args[1], n);
00062 else
00063 {
00064 unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
00065
00066 switch (pexp->operation)
00067 {
00068 case mult:
00069 return leftarg * rightarg;
00070 case divide:
00071 #if !INTDIV0_RAISES_SIGFPE
00072 if (rightarg == 0)
00073 raise (SIGFPE);
00074 #endif
00075 return leftarg / rightarg;
00076 case module:
00077 #if !INTDIV0_RAISES_SIGFPE
00078 if (rightarg == 0)
00079 raise (SIGFPE);
00080 #endif
00081 return leftarg % rightarg;
00082 case plus:
00083 return leftarg + rightarg;
00084 case minus:
00085 return leftarg - rightarg;
00086 case less_than:
00087 return leftarg < rightarg;
00088 case greater_than:
00089 return leftarg > rightarg;
00090 case less_or_equal:
00091 return leftarg <= rightarg;
00092 case greater_or_equal:
00093 return leftarg >= rightarg;
00094 case equal:
00095 return leftarg == rightarg;
00096 case not_equal:
00097 return leftarg != rightarg;
00098 default:
00099 break;
00100 }
00101 }
00102
00103 break;
00104 }
00105 case 3:
00106 {
00107
00108 unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
00109 return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
00110 }
00111 }
00112
00113 return 0;
00114 }