1 /* Plural expression evaluation.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 /* Evaluate the plural expression and return an index value. */
23 STATIC
unsigned long int plural_eval
PARAMS ((struct expression
*pexp
,
31 struct expression
*pexp
;
37 switch (pexp
->operation
)
50 /* pexp->operation must be lnot. */
51 unsigned long int arg
= plural_eval (pexp
->val
.args
[0], n
);
56 unsigned long int leftarg
= plural_eval (pexp
->val
.args
[0], n
);
57 if (pexp
->operation
== lor
)
58 return leftarg
|| plural_eval (pexp
->val
.args
[1], n
);
59 else if (pexp
->operation
== land
)
60 return leftarg
&& plural_eval (pexp
->val
.args
[1], n
);
63 unsigned long int rightarg
= plural_eval (pexp
->val
.args
[1], n
);
65 switch (pexp
->operation
)
68 return leftarg
* rightarg
;
70 return leftarg
/ rightarg
;
72 return leftarg
% rightarg
;
74 return leftarg
+ rightarg
;
76 return leftarg
- rightarg
;
78 return leftarg
< rightarg
;
80 return leftarg
> rightarg
;
82 return leftarg
<= rightarg
;
83 case greater_or_equal
:
84 return leftarg
>= rightarg
;
86 return leftarg
== rightarg
;
88 return leftarg
!= rightarg
;
98 /* pexp->operation must be qmop. */
99 unsigned long int boolarg
= plural_eval (pexp
->val
.args
[0], n
);
100 return plural_eval (pexp
->val
.args
[boolarg
? 1 : 2], n
);