Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

eval-plural.h

00001 /* Plural expression evaluation.
00002    Copyright (C) 2000-2002 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU Library General Public License as published
00006    by the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public
00015    License along with this program; if not, write to the Free Software
00016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00017    USA.  */
00018 
00019 #ifndef STATIC
00020 #define STATIC static
00021 #endif
00022 
00023 /* Evaluate the plural expression and return an index value.  */
00024 STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
00025                                               unsigned long int n))
00026      internal_function;
00027 
00028 STATIC
00029 unsigned long int
00030 internal_function
00031 plural_eval (pexp, n)
00032      struct expression *pexp;
00033      unsigned long int n;
00034 {
00035   switch (pexp->nargs)
00036     {
00037     case 0:
00038       switch (pexp->operation)
00039         {
00040         case var:
00041           return n;
00042         case num:
00043           return pexp->val.num;
00044         default:
00045           break;
00046         }
00047       /* NOTREACHED */
00048       break;
00049     case 1:
00050       {
00051         /* pexp->operation must be lnot.  */
00052         unsigned long int arg = plural_eval (pexp->val.args[0], n);
00053         return ! arg;
00054       }
00055     case 2:
00056       {
00057         unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
00058         if (pexp->operation == lor)
00059           return leftarg || plural_eval (pexp->val.args[1], n);
00060         else if (pexp->operation == land)
00061           return leftarg && plural_eval (pexp->val.args[1], n);
00062         else
00063           {
00064             unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
00065 
00066             switch (pexp->operation)
00067               {
00068               case mult:
00069                 return leftarg * rightarg;
00070               case divide:
00071                 return leftarg / rightarg;
00072               case module:
00073                 return leftarg % rightarg;
00074               case plus:
00075                 return leftarg + rightarg;
00076               case minus:
00077                 return leftarg - rightarg;
00078               case less_than:
00079                 return leftarg < rightarg;
00080               case greater_than:
00081                 return leftarg > rightarg;
00082               case less_or_equal:
00083                 return leftarg <= rightarg;
00084               case greater_or_equal:
00085                 return leftarg >= rightarg;
00086               case equal:
00087                 return leftarg == rightarg;
00088               case not_equal:
00089                 return leftarg != rightarg;
00090               default:
00091                 break;
00092               }
00093           }
00094         /* NOTREACHED */
00095         break;
00096       }
00097     case 3:
00098       {
00099         /* pexp->operation must be qmop.  */
00100         unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
00101         return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
00102       }
00103     }
00104   /* NOTREACHED */
00105   return 0;
00106 }

Generated on Sun Feb 16 23:39:49 2003 for FreeLCD by doxygen1.2.18