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

📄 rulepsr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
      /* Perform entity dependent post analysis. */      /*=========================================*/           if (PostPatternAnalysis(tempNode))        {         ReturnDefrule(topDisjunct);         return(NULL);        }              /*========================================================*/      /* Print out developer information if it's being watched. */      /*========================================================*/#if DEVELOPER      if (GetWatchItem("rule-analysis"))        {               struct lhsParseNode *traceNode;         char buffer[20];                  PrintCLIPS(WDISPLAY,"\n");         for (traceNode = tempNode; traceNode != NULL; traceNode = traceNode->bottom)           {            if (traceNode->userCE)              {               sprintf(buffer,"CE %2d: ",traceNode->whichCE);               PrintCLIPS(WDISPLAY,buffer);               PrintExpression(WDISPLAY,traceNode->networkTest);               PrintCLIPS(WDISPLAY,"\n");              }           }        }#endif          /*========================================*/      /* Check to see that logical CEs are used */      /* appropriately in the LHS of the rule.  */      /*========================================*/#if LOGICAL_DEPENDENCIES      if ((logicalJoin = LogicalAnalysis(tempNode)) < 0)         {         ReturnDefrule(topDisjunct);         return(NULL);        }#else      logicalJoin = 0;#endif            /*======================================================*/      /* Check to see if there are any RHS constraint errors. */      /*======================================================*/            if (CheckRHSForConstraintErrors(actions,tempNode))        {         ReturnDefrule(topDisjunct);         return(NULL);        }            /*=================================================*/      /* Replace variable references in the RHS with the */      /* appropriate variable retrieval functions.       */      /*=================================================*/            newActions = CopyExpression(actions);      if (ReplaceProcVars("RHS of defrule",newActions,NULL,NULL,                          ReplaceRHSVariable,(VOID *) tempNode))        {         ReturnDefrule(topDisjunct);         ReturnExpression(newActions);         return(NULL);        }              ExpressionInstall(newActions);      packPtr = PackExpression(newActions);      ReturnExpression(newActions);                 /*===============================================================*/      /* Create the pattern and join data structures for the new rule. */      /*===============================================================*/            lastJoin = ConstructJoins(logicalJoin,tempNode);            /*===================================================================*/      /* Determine the rule's complexity for use with conflict resolution. */      /*===================================================================*/            complexity = RuleComplexity(tempNode);            /*=====================================================*/      /* Create the defrule data structure for this disjunct */      /* and put it in the list of disjuncts for this rule.  */      /*=====================================================*/            currentDisjunct = CreateNewDisjunct(ruleName,localVarCnt,packPtr,complexity,                                          logicalJoin,lastJoin);                                                /*============================================================*/      /* Place the disjunct in the list of disjuncts for this rule. */      /* If the disjunct is the first disjunct, then increment the  */      /* reference counts for the dynamic salience (the expression  */      /* for the dynamic salience is only stored with the first     */      /* disjuncts and the other disjuncts refer back to the first  */      /* disjunct for their dynamic salience value.                 */      /*============================================================*/                                           if (topDisjunct == NULL)         {         topDisjunct = currentDisjunct;#if DYNAMIC_SALIENCE         ExpressionInstall(topDisjunct->dynamicSalience);#endif        }      else lastDisjunct->disjunct = currentDisjunct;      /*===========================================*/      /* Move on to the next disjunct of the rule. */      /*===========================================*/            theLHS = theLHS->bottom;      lastDisjunct = currentDisjunct;     }   return(topDisjunct);  }  /************************************************************************//* CreateNewDisjunct: Creates and initializes a defrule data structure. *//************************************************************************/static struct defrule *CreateNewDisjunct(ruleName,localVarCnt,theActions,complexity,                                         logicalJoin,lastJoin)  SYMBOL_HN *ruleName;  int localVarCnt;  struct expr *theActions;  int complexity;  int logicalJoin;  struct joinNode *lastJoin;  {   struct defrule *newDisjunct;#if LOGICAL_DEPENDENCIES   struct joinNode *tempJoin;#endif   /*===================================================*/   /* Create and initialize the defrule data structure. */   /*===================================================*/      newDisjunct = get_struct(defrule);   newDisjunct->header.ppForm = NULL;   newDisjunct->header.next = NULL;#if LOGICAL_DEPENDENCIES   newDisjunct->logicalJoin = NULL;#endif   newDisjunct->disjunct = NULL;   newDisjunct->header.name = ruleName;   IncrementSymbolCount(newDisjunct->header.name);   newDisjunct->actions = theActions;   newDisjunct->salience = GlobalSalience;   newDisjunct->afterBreakpoint = 0;   newDisjunct->watchActivation = 0;   newDisjunct->watchFiring = 0;   newDisjunct->executing = 0;   newDisjunct->complexity = complexity;   newDisjunct->autoFocus = GlobalAutoFocus;#if DYNAMIC_SALIENCE   newDisjunct->dynamicSalience = SalienceExpression;#endif   newDisjunct->localVarCnt = localVarCnt;   /*=====================================*/   /* Add a pointer to the rule's module. */   /*=====================================*/      newDisjunct->header.whichModule =       (struct defmoduleItemHeader *)      GetModuleItem(NULL,FindModuleItem("defrule")->moduleIndex);      /*============================================================*/   /* Attach the rule's last join to the defrule data structure. */   /*============================================================*/      lastJoin->ruleToActivate = newDisjunct;   newDisjunct->lastJoin = lastJoin;      /*=================================================*/   /* Determine the rule's logical join if it exists. */   /*=================================================*/   #if LOGICAL_DEPENDENCIES   tempJoin = lastJoin;   while (tempJoin != NULL)     {      if (tempJoin->depth == logicalJoin)        {         newDisjunct->logicalJoin = tempJoin;         tempJoin->logicalJoin = CLIPS_TRUE;        }      tempJoin = tempJoin->lastLevel;     }#endif   /*==================================================*/   /* Return the newly created defrule data structure. */   /*==================================================*/      return(newDisjunct);  }/*****************************************************************************//* ReplaceExpressionVariables: Replaces all symbolic references to variables *//*   (local and global) found in an expression on the RHS of a rule with     *//*   expressions containing function calls to retrieve the variable's value. *//*   Makes the final modifications necessary for handling the modify and     *//*   duplicate commands.                                                     *//*****************************************************************************/static int ReplaceRHSVariable(list,VtheLHS)  struct expr *list;  VOID *VtheLHS;  {   struct lhsParseNode *theVariable;   /*=======================================*/   /* Handle modify and duplicate commands. */   /*=======================================*/   #if DEFTEMPLATE_CONSTRUCT   if (list->type == FCALL)     {      if (list->value == (VOID *) FindFunction("modify"))        {         if (UpdateModifyDuplicate(list,"modify",VtheLHS) == CLIPS_FALSE)           return(-1);        }      else if (list->value == (VOID *) FindFunction("duplicate"))        {         if (UpdateModifyDuplicate(list,"duplicate",VtheLHS) == CLIPS_FALSE)           return(-1);        }              return(0);     }     #endif   if ((list->type != SF_VARIABLE) && (list->type != MF_VARIABLE))     { return(CLIPS_FALSE); }      /*===============================================================*/   /* Check to see if the variable is bound on the LHS of the rule. */   /*===============================================================*/   theVariable = FindVariable((SYMBOL_HN *) list->value,(struct lhsParseNode *) VtheLHS);   if (theVariable == NULL) return(CLIPS_FALSE);        /*================================================*/   /* Replace the variable reference with a function */   /* call to retrieve the variable.                 */   /*================================================*/      if (theVariable->patternType != NULL)      { (*theVariable->patternType->replaceGetJNValueFunction)(list,theVariable); }   else     { return(CLIPS_FALSE); }      /*=================================================================*/   /* Return TRUE to indicate the variable was successfully replaced. */   /*=================================================================*/      return(CLIPS_TRUE);  }  /*******************************************************//* ParseRuleRHS: Coordinates all the actions necessary *//*   for parsing the RHS of a rule.                    *//*******************************************************/static struct expr *ParseRuleRHS(readSource)  char *readSource;  {   struct expr *actions;   struct token theToken;   /*=========================================================*/   /* Process the actions on the right hand side of the rule. */   /*=========================================================*/   SavePPBuffer("\n   ");   SetIndentDepth(3);   actions = GroupActions(readSource,&theToken,CLIPS_TRUE,NULL);   if (actions == NULL) return(NULL);   /*=============================*/   /* Reformat the closing token. */   /*=============================*/   PPBackup();   PPBackup();   SavePPBuffer(theToken.printForm);   /*======================================================*/   /* Check for the closing right parenthesis of the rule. */   /*======================================================*/   if (theToken.type != RPAREN)     {      SyntaxErrorMessage("defrule");      ReturnExpression(actions);      return(NULL);     }

⌨️ 快捷键说明

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