1 /* Plural expression evaluation.
2 Copyright (C) 2000-2003, 2007, 2015 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 <http://www.gnu.org/licenses/>. */
21 /* Evaluate the plural expression and return an index value. */
25 plural_eval (const struct expression *pexp, unsigned long int n)
30 switch (pexp->operation)
43 /* pexp->operation must be lnot. */
44 unsigned long int arg = plural_eval (pexp->val.args[0], n);
49 unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
50 if (pexp->operation == lor)
51 return leftarg || plural_eval (pexp->val.args[1], n);
52 else if (pexp->operation == land)
53 return leftarg && plural_eval (pexp->val.args[1], n);
56 unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
58 switch (pexp->operation)
61 return leftarg * rightarg;
63 #if !INTDIV0_RAISES_SIGFPE
67 return leftarg / rightarg;
69 #if !INTDIV0_RAISES_SIGFPE
73 return leftarg % rightarg;
75 return leftarg + rightarg;
77 return leftarg - rightarg;
79 return leftarg < rightarg;
81 return leftarg > rightarg;
83 return leftarg <= rightarg;
84 case greater_or_equal:
85 return leftarg >= rightarg;
87 return leftarg == rightarg;
89 return leftarg != rightarg;
99 /* pexp->operation must be qmop. */
100 unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
101 return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);