1 /* eval-plural.c - Plural expression evaluation. */
3 /* Copyright (C) 2000-2002, 2006-2009 Free Software Foundation, Inc.
5 This file is part of GNU Bush.
7 Bush is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bush is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bush. If not, see <http://www.gnu.org/licenses/>.
25 /* Evaluate the plural expression and return an index value. */
26 STATIC
unsigned long int plural_eval
PARAMS ((struct expression
*pexp
,
34 struct expression
*pexp
;
40 switch (pexp
->operation
)
53 /* pexp->operation must be lnot. */
54 unsigned long int arg
= plural_eval (pexp
->val
.args
[0], n
);
59 unsigned long int leftarg
= plural_eval (pexp
->val
.args
[0], n
);
60 if (pexp
->operation
== lor
)
61 return leftarg
|| plural_eval (pexp
->val
.args
[1], n
);
62 else if (pexp
->operation
== land
)
63 return leftarg
&& plural_eval (pexp
->val
.args
[1], n
);
66 unsigned long int rightarg
= plural_eval (pexp
->val
.args
[1], n
);
68 switch (pexp
->operation
)
71 return leftarg
* rightarg
;
73 #if !INTDIV0_RAISES_SIGFPE
77 return leftarg
/ rightarg
;
79 #if !INTDIV0_RAISES_SIGFPE
83 return leftarg
% rightarg
;
85 return leftarg
+ rightarg
;
87 return leftarg
- rightarg
;
89 return leftarg
< rightarg
;
91 return leftarg
> rightarg
;
93 return leftarg
<= rightarg
;
94 case greater_or_equal
:
95 return leftarg
>= rightarg
;
97 return leftarg
== rightarg
;
99 return leftarg
!= rightarg
;
109 /* pexp->operation must be qmop. */
110 unsigned long int boolarg
= plural_eval (pexp
->val
.args
[0], n
);
111 return plural_eval (pexp
->val
.args
[boolarg
? 1 : 2], n
);