⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cstrnutl.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
     {      if (ValueToDouble(vptr1) < ValueToDouble(vptr2))        { return(LESS_THAN); }      else if (ValueToDouble(vptr1) > ValueToDouble(vptr2))        { return(GREATER_THAN); }              return(EQUAL);     }        /*================================*/   /* Compare an integer to a float. */   /*================================*/      if ((type1 == INTEGER) && (type2 == FLOAT))     {      if (((double) ValueToLong(vptr1)) < ValueToDouble(vptr2))        { return(LESS_THAN); }      else if (((double) ValueToLong(vptr1)) > ValueToDouble(vptr2))        { return(GREATER_THAN); }              return(EQUAL);     }          /*================================*/   /* Compare a float to an integer. */   /*================================*/      if ((type1 == FLOAT) && (type2 == INTEGER))     {      if (ValueToDouble(vptr1) < ((double) ValueToLong(vptr2)))        { return(LESS_THAN); }      else if (ValueToDouble(vptr1) > ((double) ValueToLong(vptr2)))        { return(GREATER_THAN); }              return(EQUAL);     }        /*===================================*/   /* One of the arguments was invalid. */   /* Return -1 to indicate an error.   */   /*===================================*/      return(-1);  }/****************************************************************//* ExpressionToConstraintRecord: Converts an expression into a  *//*   constraint record. For example, an expression representing *//*   the symbol BLUE would be converted to a  record with       *//*   allowed types SYMBOL and allow-values BLUE.                *//****************************************************************/globle CONSTRAINT_RECORD *ExpressionToConstraintRecord(theExpression)  struct expr *theExpression;  {   CONSTRAINT_RECORD *rv;      /*================================================*/   /* A NULL expression is converted to a constraint */   /* record with no values allowed.                 */   /*================================================*/      if (theExpression == NULL)      {      rv = GetConstraintRecord();      rv->anyAllowed = CLIPS_FALSE;      return(rv);     }      /*=============================================================*/   /* Convert variables and function calls to constraint records. */   /*=============================================================*/      if ((theExpression->type == SF_VARIABLE) ||       (theExpression->type == MF_VARIABLE) ||#if DEFGENERIC_CONSTRUCT       (theExpression->type == GCALL) ||#endif#if DEFFUNCTION_CONSTRUCT       (theExpression->type == PCALL) ||#endif       (theExpression->type == GBL_VARIABLE) ||       (theExpression->type == MF_GBL_VARIABLE))     {        rv = GetConstraintRecord();       rv->multifieldsAllowed = CLIPS_TRUE;       return(rv);      }   else if (theExpression->type == FCALL)     { return(FunctionCallToConstraintRecord(theExpression->value)); }        /*============================================*/   /* Convert a constant to a constraint record. */   /*============================================*/      rv = GetConstraintRecord();   rv->anyAllowed = CLIPS_FALSE;      if (theExpression->type == FLOAT)      {      rv->floatRestriction = CLIPS_TRUE;      rv->floatsAllowed = CLIPS_TRUE;     }   else if (theExpression->type == INTEGER)       {      rv->integerRestriction = CLIPS_TRUE;      rv->integersAllowed = CLIPS_TRUE;     }   else if (theExpression->type == SYMBOL)       {      rv->symbolRestriction = CLIPS_TRUE;      rv->symbolsAllowed = CLIPS_TRUE;     }   else if (theExpression->type == STRING)       {      rv->stringRestriction = CLIPS_TRUE;      rv->stringsAllowed = CLIPS_TRUE;     }   else if (theExpression->type == INSTANCE_NAME)       {      rv->instanceNameRestriction = CLIPS_TRUE;      rv->instanceNamesAllowed = CLIPS_TRUE;     }   else if (theExpression->type == INSTANCE_ADDRESS)     { rv->instanceAddressesAllowed = CLIPS_TRUE; }   if (rv->floatsAllowed || rv->integersAllowed || rv->symbolsAllowed ||       rv->stringsAllowed || rv->instanceNamesAllowed)     { rv->restrictionList = GenConstant(theExpression->type,theExpression->value); }           return(rv);  }    /*******************************************************//* FunctionCallToConstraintRecord: Converts a function *//*   call to a constraint record. For example, the +   *//*   function when converted would be a constraint     *//*   record with allowed types INTEGER and FLOAT.      *//*******************************************************/globle CONSTRAINT_RECORD *FunctionCallToConstraintRecord(theFunction)  VOID *theFunction;  {   CONSTRAINT_RECORD *rv;      rv = GetConstraintRecord();   rv->anyAllowed = CLIPS_FALSE;      switch ((char) ValueFunctionType(theFunction))     {      case 'a':        rv->externalAddressesAllowed = CLIPS_TRUE;        break;      case 'f':      case 'd':        rv->floatsAllowed = CLIPS_TRUE;        break;      case 'i':      case 'l':        rv->integersAllowed = CLIPS_TRUE;        break;      case 'j':        rv->instanceNamesAllowed = CLIPS_TRUE;        rv->symbolsAllowed = CLIPS_TRUE;        rv->stringsAllowed = CLIPS_TRUE;        break;              case 'k':        rv->symbolsAllowed = CLIPS_TRUE;        rv->stringsAllowed = CLIPS_TRUE;        break;      case 'm':        rv->singlefieldsAllowed = CLIPS_FALSE;         rv->multifieldsAllowed = CLIPS_TRUE;        break;      case 'n':        rv->floatsAllowed = CLIPS_TRUE;        rv->integersAllowed = CLIPS_TRUE;        break;      case 'o':        rv->instanceNamesAllowed = CLIPS_TRUE;        break;      case 's':        rv->stringsAllowed = CLIPS_TRUE;        break;      case 'u':        rv->anyAllowed = CLIPS_TRUE;        rv->multifieldsAllowed = CLIPS_TRUE;         break;      case 'w':      case 'c':      case 'b':        rv->symbolsAllowed = CLIPS_TRUE;        break;      case 'x':        rv->instanceAddressesAllowed = CLIPS_TRUE;        break;              case 'v':        break;     }        return(rv);  }  /*******************************************************//* ArgumentTypeToConstraintRecord: Converts one of the *//*   function argument types (used by DefineFunction2) *//*   to a constraint record.                           *//*******************************************************/globle CONSTRAINT_RECORD *ArgumentTypeToConstraintRecord(theRestriction)  int theRestriction;  {   CONSTRAINT_RECORD *rv;      rv = GetConstraintRecord();   rv->anyAllowed = CLIPS_FALSE;      switch (theRestriction)     {      case 'a':        rv->externalAddressesAllowed = CLIPS_TRUE;        break;      case 'e':        rv->symbolsAllowed = CLIPS_TRUE;        rv->instanceNamesAllowed = CLIPS_TRUE;        rv->instanceAddressesAllowed = CLIPS_TRUE;        break;      case 'd':      case 'f':        rv->floatsAllowed = CLIPS_TRUE;        break;      case 'g':        rv->integersAllowed = CLIPS_TRUE;        rv->floatsAllowed = CLIPS_TRUE;        rv->symbolsAllowed = CLIPS_TRUE;        break;      case 'h':        rv->factAddressesAllowed = CLIPS_TRUE;        rv->integersAllowed = CLIPS_TRUE;        rv->symbolsAllowed = CLIPS_TRUE;        rv->instanceNamesAllowed = CLIPS_TRUE;        rv->instanceAddressesAllowed = CLIPS_TRUE;        break;      case 'i':      case 'l':        rv->integersAllowed = CLIPS_TRUE;        break;      case 'j':        rv->symbolsAllowed = CLIPS_TRUE;        rv->stringsAllowed = CLIPS_TRUE;        rv->instanceNamesAllowed = CLIPS_TRUE;        break;      case 'k':        rv->symbolsAllowed = CLIPS_TRUE;        rv->stringsAllowed = CLIPS_TRUE;        break;      case 'm':        rv->singlefieldsAllowed = CLIPS_FALSE;        rv->multifieldsAllowed = CLIPS_TRUE;        break;      case 'n':        rv->floatsAllowed = CLIPS_TRUE;        rv->integersAllowed = CLIPS_TRUE;        break;      case 'o':        rv->instanceNamesAllowed = CLIPS_TRUE;        break;              case 'p':        rv->instanceNamesAllowed = CLIPS_TRUE;        rv->symbolsAllowed = CLIPS_TRUE;        break;      case 'q':        rv->symbolsAllowed = CLIPS_TRUE;        rv->stringsAllowed = CLIPS_TRUE;        rv->multifieldsAllowed = CLIPS_TRUE;        break;      case 's':        rv->stringsAllowed = CLIPS_TRUE;        break;      case 'w':        rv->symbolsAllowed = CLIPS_TRUE;        break;      case 'x':        rv->instanceAddressesAllowed = CLIPS_TRUE;        break;      case 'y':        rv->factAddressesAllowed = CLIPS_TRUE;        break;      case 'z':        rv->symbolsAllowed = CLIPS_TRUE;        rv->factAddressesAllowed = CLIPS_TRUE;        rv->integersAllowed = CLIPS_TRUE;        break;      case 'u':        rv->anyAllowed = CLIPS_TRUE;        rv->multifieldsAllowed = CLIPS_TRUE;         break;     }        return(rv);  }       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -