3 /* Plural expression evaluation.
4 Copyright (C) 2000-2003 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published
8 by the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 /* Evaluate the plural expression and return an index value. */
29 plural_eval (struct expression
*pexp
, unsigned long int n
)
34 switch (pexp
->operation
)
47 /* pexp->operation must be lnot. */
48 unsigned long int arg
= plural_eval (pexp
->val
.args
[0], n
);
53 unsigned long int leftarg
= plural_eval (pexp
->val
.args
[0], n
);
54 if (pexp
->operation
== lor
)
55 return leftarg
|| plural_eval (pexp
->val
.args
[1], n
);
56 else if (pexp
->operation
== land
)
57 return leftarg
&& plural_eval (pexp
->val
.args
[1], n
);
60 unsigned long int rightarg
= plural_eval (pexp
->val
.args
[1], n
);
62 switch (pexp
->operation
)
65 return leftarg
* rightarg
;
67 #if !INTDIV0_RAISES_SIGFPE
71 return leftarg
/ rightarg
;
73 #if !INTDIV0_RAISES_SIGFPE
77 return leftarg
% rightarg
;
79 return leftarg
+ rightarg
;
81 return leftarg
- rightarg
;
83 return leftarg
< rightarg
;
85 return leftarg
> rightarg
;
87 return leftarg
<= rightarg
;
88 case greater_or_equal
:
89 return leftarg
>= rightarg
;
91 return leftarg
== rightarg
;
93 return leftarg
!= rightarg
;
103 /* pexp->operation must be qmop. */
104 unsigned long int boolarg
= plural_eval (pexp
->val
.args
[0], n
);
105 return plural_eval (pexp
->val
.args
[boolarg
? 1 : 2], n
);