1 /* Plural expression evaluation.
2 Copyright (C) 2000-2020 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 Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 /* Evaluate the plural expression and return an index value. */
24 plural_eval (const struct expression
*pexp
, unsigned long int n
)
29 switch (pexp
->operation
)
42 /* pexp->operation must be lnot. */
43 unsigned long int arg
= plural_eval (pexp
->val
.args
[0], n
);
48 unsigned long int leftarg
= plural_eval (pexp
->val
.args
[0], n
);
49 if (pexp
->operation
== lor
)
50 return leftarg
|| plural_eval (pexp
->val
.args
[1], n
);
51 else if (pexp
->operation
== land
)
52 return leftarg
&& plural_eval (pexp
->val
.args
[1], n
);
55 unsigned long int rightarg
= plural_eval (pexp
->val
.args
[1], n
);
57 switch (pexp
->operation
)
60 return leftarg
* rightarg
;
62 #if !INTDIV0_RAISES_SIGFPE
66 return leftarg
/ rightarg
;
68 #if !INTDIV0_RAISES_SIGFPE
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
);