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

📄 symbol.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
  BITMAP_HN *theValue;  {   if (theValue->count < 0)     {      CLIPSSystemError("SYMBOL",7);      ExitCLIPS(5);     }   if (theValue->count == 0)     {      CLIPSSystemError("SYMBOL",8);      ExitCLIPS(5);     }   theValue->count--;   if (theValue->count != 0) return;   if (theValue->markedEphemeral == CLIPS_FALSE)      {        AddEphemeralHashNode((GENERIC_HN *) theValue,&EphemeralBitMapList,                           sizeof(BITMAP_HN),sizeof(long));     }   return;  }    /*************************************************************//* RemoveHashNode: Removes a hash node from the SymbolTable, *//*   FloatTable, IntegerTable, or BitMapTable.               *//*************************************************************/static VOID RemoveHashNode(theValue,theTable,size,type)  GENERIC_HN *theValue, **theTable;  int size, type;  {   GENERIC_HN *previousNode, *currentNode;   /*=============================================*/   /* Find the entry in the specified hash table. */   /*=============================================*/      previousNode = NULL;   currentNode = theTable[theValue->bucket];   while (currentNode != theValue)     {      previousNode = currentNode;      currentNode = currentNode->next;      if (currentNode == NULL)        {         CLIPSSystemError("SYMBOL",9);         ExitCLIPS(5);        }     }   /*===========================================*/   /* Remove the entry from the list of entries */   /* stored in the hash table bucket.          */   /*===========================================*/      if (previousNode == NULL)     { theTable[theValue->bucket] = theValue->next; }   else     { previousNode->next = currentNode->next; }   /*=================================================*/   /* Symbol and bit map nodes have additional memory */   /* use to store the character or bitmap string.    */   /*=================================================*/      if (type == SYMBOL)      {       rm(((SYMBOL_HN *) theValue)->contents,         (int) strlen(((SYMBOL_HN *) theValue)->contents) + 1);     }   else if (type == BITMAPARRAY)     {       rm(((BITMAP_HN *) theValue)->contents,         (int) ((BITMAP_HN *) theValue)->size);     }        /*===========================*/   /* Return the table entry to */   /* the pool of free memory.  */   /*===========================*/      rtn_sized_struct(size,theValue);  }/***********************************************************//* AddEphemeralHashNode: Adds a symbol, integer, float, or *//*   bit map table entry to the list of ephemeral atomic   *//*   values. These entries have a zero count indicating    *//*   that no structure is using the data value.            *//***********************************************************/static VOID AddEphemeralHashNode(theHashNode,theEphemeralList,                                 hashNodeSize,averageContentsSize)  GENERIC_HN *theHashNode;  struct ephemeron **theEphemeralList;  int hashNodeSize, averageContentsSize;  {   struct ephemeron *temp;   /*===========================================*/   /* If the count isn't zero then this routine */   /* should never have been called.            */   /*===========================================*/      if (theHashNode->count != 0)     {      CLIPSSystemError("SYMBOL",10);      ExitCLIPS(5);     }   /*=====================================*/   /* Mark the atomic value as ephemeral. */   /*=====================================*/      theHashNode->markedEphemeral = CLIPS_TRUE;   /*=============================*/   /* Add the atomic value to the */   /* list of ephemeral values.   */   /*=============================*/      temp = get_struct(ephemeron);   temp->associatedValue = theHashNode;   temp->next = *theEphemeralList;   *theEphemeralList = temp;   /*=========================================================*/   /* Increment the ephemeral count and size variables. These */   /* variables are used by the garbage collection routines   */   /* to determine when garbage collection should occur.      */   /*=========================================================*/      EphemeralItemCount++;   EphemeralItemSize += sizeof(struct ephemeron) + hashNodeSize +                        averageContentsSize;  }/***************************************************//* RemoveEphemeralAtoms: Causes the removal of all *//*   ephemeral symbols, integers, floats, and bit  *//*   maps that still have a count value of zero,   *//*   from their respective storage tables.         *//***************************************************/globle VOID RemoveEphemeralAtoms()  {   RemoveEphemeralHashNodes(&EphemeralSymbolList,(GENERIC_HN **) SymbolTable,                            sizeof(SYMBOL_HN),SYMBOL,AVERAGE_STRING_SIZE);   RemoveEphemeralHashNodes(&EphemeralFloatList,(GENERIC_HN **) FloatTable,                            sizeof(FLOAT_HN),FLOAT,0);   RemoveEphemeralHashNodes(&EphemeralIntegerList,(GENERIC_HN **) IntegerTable,                            sizeof(INTEGER_HN),INTEGER,0);   RemoveEphemeralHashNodes(&EphemeralBitMapList,(GENERIC_HN **) BitMapTable,                            sizeof(BITMAP_HN),BITMAPARRAY,AVERAGE_BITMAP_SIZE);  }/****************************************************************//* RemoveEphemeralHashNodes: Removes symbols from the ephemeral *//*   symbol list that have a count of zero and were placed on   *//*   the list at a higher level than the current evaluation     *//*   depth. Since symbols are ordered in the list in descending *//*   order, the removal process can end when a depth is reached *//*   less than the current evaluation depth. Because ephemeral  *//*   symbols can be "pulled" up through an evaluation depth,    *//*   this routine needs to check through both the previous and  *//*   current evaluation depth.                                  *//****************************************************************/static VOID RemoveEphemeralHashNodes(theEphemeralList,theTable,                                     hashNodeSize,hashNodeType,averageContentsSize)  struct ephemeron **theEphemeralList;  GENERIC_HN **theTable;  int hashNodeSize, hashNodeType, averageContentsSize;  {   struct ephemeron *edPtr, *lastPtr = NULL, *nextPtr;   edPtr = *theEphemeralList;   while (edPtr != NULL)     {      /*======================================================*/      /* Check through previous and current evaluation depth  */      /* because these symbols can be interspersed, otherwise */      /* symbols are stored in descending evaluation depth.   */      /*======================================================*/      nextPtr = edPtr->next;      /*==================================================*/      /* Remove any symbols that have a count of zero and */      /* were added to the ephemeral list at a higher     */      /* evaluation depth.                                */      /*==================================================*/      if ((edPtr->associatedValue->count == 0) &&          (edPtr->associatedValue->depth > CurrentEvaluationDepth))        {         RemoveHashNode(edPtr->associatedValue,theTable,hashNodeSize,hashNodeType);         rtn_struct(ephemeron,edPtr);         if (lastPtr == NULL) *theEphemeralList = nextPtr;         else lastPtr->next = nextPtr;         EphemeralItemCount--;         EphemeralItemSize -= sizeof(struct ephemeron) + hashNodeSize +                              averageContentsSize;        }      /*=======================================*/      /* Remove ephemeral status of any symbol */      /* with a count greater than zero.       */      /*=======================================*/      else if (edPtr->associatedValue->count > 0)        {         edPtr->associatedValue->markedEphemeral = CLIPS_FALSE;         rtn_struct(ephemeron,edPtr);         if (lastPtr == NULL) *theEphemeralList = nextPtr;         else lastPtr->next = nextPtr;         EphemeralItemCount--;         EphemeralItemSize -= sizeof(struct ephemeron) + hashNodeSize +                              averageContentsSize;        }      /*==================================================*/      /* Otherwise keep the symbol in the ephemeral list. */      /*==================================================*/      else        { lastPtr = edPtr; }      edPtr = nextPtr;     }  }/*********************************************************//* GetSymbolTable: Returns a pointer to the SymbolTable. *//*********************************************************/globle SYMBOL_HN **GetSymbolTable()  {   return(SymbolTable);  }/******************************************************//* SetSymbolTable: Sets the value of the SymbolTable. *//******************************************************/globle VOID SetSymbolTable(value)  SYMBOL_HN **value;  {   SymbolTable = value;  }/*******************************************************//* GetFloatTable: Returns a pointer to the FloatTable. *//*******************************************************/globle FLOAT_HN **GetFloatTable()  {   return(FloatTable);  }/****************************************************//* SetFloatTable: Sets the value of the FloatTable. *//****************************************************/globle VOID SetFloatTable(value)  FLOAT_HN **value;  {   FloatTable = value;  }/***********************************************************//* GetIntegerTable: Returns a pointer to the IntegerTable. *//***********************************************************/globle INTEGER_HN **GetIntegerTable()  {   return(IntegerTable);  }/********************************************************//* SetIntegerTable: Sets the value of the IntegerTable. *//********************************************************/globle VOID SetIntegerTable(value)  INTEGER_HN **value;  {   IntegerTable = value;  }  /*********************************************************//* GetBitMapTable: Returns a pointer to the BitMapTable. *//*********************************************************/globle BITMAP_HN **GetBitMapTable()  {   return(BitMapTable);  }/******************************************************//* SetBitMapTable: Sets the value of the BitMapTable. *//******************************************************/globle VOID SetBitMapTable(value)  BITMAP_HN **value;  {   BitMapTable = value;  }  /*****************************************************//* RefreshSpecialSymbols: Resets the values of the   *//*   CLIPSTrueSymbol, CLIPSFalseSymbol, Zero,        *//*   PositiveInfinity, and NegativeInfinity symbols. *//*****************************************************/globle VOID RefreshSpecialSymbols()  {   CLIPSTrueSymbol = (VOID *) FindSymbol(TRUE_STRING);   CLIPSFalseSymbol = (VOID *) FindSymbol(FALSE_STRING);   PositiveInfinity = (VOID *) FindSymbol(POSITIVE_INFINITY_STRING);   NegativeInfinity = (VOID *) FindSymbol(NEGATIVE_INFINITY_STRING);   Zero = (VOID *) FindLong(0L);  }/*****************************************************************//* FindSymbolMatches: Finds all symbols in the SymbolTable which *//*   begin with a specified symbol. This function is used to     *//*   implement the command completion feature found in some of   *//*   the CLIPS machine specific interfaces.                      *//*****************************************************************/globle struct symbolMatch *FindSymbolMatches(searchString,numberOfMatches,commonPrefixLength)  char *searchString;  int *numberOfMatches;  int *commonPrefixLength;  {   struct symbolMatch *reply = NULL, *temp;   struct symbolHashNode *hashPtr = NULL;   int searchLength;   searchLength = strlen(searchString);   *numberOfMatches = 0;   while ((hashPtr = GetNextSymbolMatch(searchString,searchLength,hashPtr,                                        CLIPS_FALSE,commonPrefixLength)) != NULL)     {      *numberOfMatches = *numberOfMatches + 1;      temp = get_struct(symbolMatch);      temp->match = hashPtr;      temp->next = reply;      reply = temp;     }   return(reply);  }/*********************************************************//* ReturnSymbolMatches: Returns a set of symbol matches. *//*********************************************************/globle VOID ReturnSymbolMatches(listOfMatches)  struct symbolMatch *listOfMatches;  {   struct symbolMatch *temp;   while (listOfMatches != NULL)

⌨️ 快捷键说明

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