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

📄 tmpltpsr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
  /*=======================*/  /* Return the slot list. */  /*=======================*/  return(slotList); }/*****************************************************//* ParseSlot: Parses a single slot of a deftemplate. *//*****************************************************/static struct templateSlot *ParseSlot(readSource,inputToken,slotList)  char *readSource;  struct token *inputToken;  struct templateSlot *slotList;  {   int parsingMultislot;   SYMBOL_HN *slotName;   struct templateSlot *newSlot;   int rv;   /*=====================================================*/   /* Slots must  begin with keyword field or multifield. */   /*=====================================================*/   if ((strcmp(ValueToString(inputToken->value),"field") != 0) &&       (strcmp(ValueToString(inputToken->value),"multifield") != 0) &&       (strcmp(ValueToString(inputToken->value),"slot") != 0) &&       (strcmp(ValueToString(inputToken->value),"multislot") != 0))     {      SyntaxErrorMessage("deftemplate");      DeftemplateError = CLIPS_TRUE;      return(NULL);     }   /*===============================================*/   /* Determine if multifield slot is being parsed. */   /*===============================================*/   if ((strcmp(ValueToString(inputToken->value),"multifield") == 0) ||       (strcmp(ValueToString(inputToken->value),"multislot") == 0))     { parsingMultislot = CLIPS_TRUE; }   else     { parsingMultislot = CLIPS_FALSE; }   /*========================================*/   /* The name of the slot must be a symbol. */   /*========================================*/   SavePPBuffer(" ");   GetToken(readSource,inputToken);   if (inputToken->type != SYMBOL)     {      SyntaxErrorMessage("deftemplate");      DeftemplateError = CLIPS_TRUE;      return(NULL);     }   slotName = (SYMBOL_HN *) inputToken->value;   /*================================================*/   /* Determine if the slot has already been parsed. */   /*================================================*/      while (slotList != NULL)     {      if (slotList->slotName == slotName)        {         AlreadyParsedErrorMessage("slot ",ValueToString(slotList->slotName));         DeftemplateError = CLIPS_TRUE;         return(NULL);        }              slotList = slotList->next;     }        /*===================================*/   /* Parse the attributes of the slot. */   /*===================================*/   newSlot = DefinedSlots(readSource,slotName,parsingMultislot,inputToken);   if (newSlot == NULL)     {      DeftemplateError = CLIPS_TRUE;      return(NULL);     }   /*=================================*/   /* Check for slot conflict errors. */   /*=================================*/   if (CheckConstraintParseConflicts(newSlot->constraints) == CLIPS_FALSE)     {      ReturnSlots(newSlot);      DeftemplateError = CLIPS_TRUE;      return(NULL);     }            if ((newSlot->defaultPresent) || (newSlot->defaultDynamic))     { rv = ConstraintCheckExpressionChain(newSlot->defaultList,newSlot->constraints); }   else     { rv = NO_VIOLATION; }        if ((rv != NO_VIOLATION) && GetStaticConstraintChecking())     {      char *temp;      if (newSlot->defaultDynamic) temp = "the default-dynamic attribute";      else temp = "the default attribute";      ConstraintViolationErrorMessage("An expression",temp,CLIPS_FALSE,0,                                      newSlot->slotName,0,rv,newSlot->constraints,CLIPS_TRUE);      ReturnSlots(newSlot);      DeftemplateError = CLIPS_TRUE;      return(NULL);     }   /*==================*/   /* Return the slot. */   /*==================*/   return(newSlot);  }/**************************************************************//* DefinedSlots: Parses a field or multifield slot attribute. *//**************************************************************/static struct templateSlot *DefinedSlots(readSource,slotName,multifieldSlot,inputToken)  char *readSource;  SYMBOL_HN *slotName;  int multifieldSlot;  struct token *inputToken;  {   struct templateSlot *newSlot;   struct expr *defaultList;   int defaultFound = CLIPS_FALSE;   int noneSpecified, deriveSpecified;   CONSTRAINT_PARSE_RECORD parsedConstraints;   /*===========================*/   /* Build the slot container. */   /*===========================*/   newSlot = get_struct(templateSlot);   newSlot->slotName = slotName;   newSlot->defaultList = NULL;   newSlot->constraints = GetConstraintRecord();   if (multifieldSlot)     { newSlot->constraints->multifieldsAllowed = CLIPS_TRUE; }   newSlot->multislot = multifieldSlot;   newSlot->noDefault = CLIPS_FALSE;   newSlot->defaultPresent = CLIPS_FALSE;   newSlot->defaultDynamic = CLIPS_FALSE;   newSlot->next = NULL;      /*========================================*/   /* Parse the primitive slot if it exists. */   /*========================================*/   InitializeConstraintParseRecord(&parsedConstraints);   GetToken(readSource,inputToken);   while (inputToken->type != RPAREN)     {      PPBackup();      SavePPBuffer(" ");      SavePPBuffer(inputToken->printForm);      /*================================================*/      /* Slot attributes begin with a left parenthesis. */      /*================================================*/      if (inputToken->type != LPAREN)        {         SyntaxErrorMessage("deftemplate");         ReturnSlots(newSlot);         DeftemplateError = CLIPS_TRUE;         return(NULL);        }      /*=============================================*/      /* The name of the attribute must be a symbol. */      /*=============================================*/      GetToken(readSource,inputToken);      if (inputToken->type != SYMBOL)        {         SyntaxErrorMessage("deftemplate");         ReturnSlots(newSlot);         DeftemplateError = CLIPS_TRUE;         return(NULL);        }      /*================================================================*/      /* Determine if the attribute is one of the standard constraints. */      /*================================================================*/      if (StandardConstraint(ValueToString(inputToken->value)))        {         if (ParseStandardConstraint(readSource,(ValueToString(inputToken->value)),                                     newSlot->constraints,&parsedConstraints,                                     multifieldSlot) == CLIPS_FALSE)           {            DeftemplateError = CLIPS_TRUE;            ReturnSlots(newSlot);            return(NULL);           }        }      /*=================================================*/      /* else if the attribute is the default attribute, */      /* then get the default list for this slot.        */      /*=================================================*/      else if ((strcmp(ValueToString(inputToken->value),"default") == 0) ||               (strcmp(ValueToString(inputToken->value),"default-dynamic") == 0))         {         /*======================================================*/         /* Check to see if the default has already been parsed. */         /*======================================================*/                  if (defaultFound)           {            AlreadyParsedErrorMessage("default attribute",NULL);            DeftemplateError = CLIPS_TRUE;            ReturnSlots(newSlot);            return(NULL);           }                  newSlot->noDefault = CLIPS_FALSE;                    /*=====================================================*/         /* Determine whether the default is dynamic or static. */         /*=====================================================*/                  if (strcmp(ValueToString(inputToken->value),"default") == 0)            {             newSlot->defaultPresent = CLIPS_TRUE;            newSlot->defaultDynamic = CLIPS_FALSE;           }         else            {             newSlot->defaultPresent = CLIPS_FALSE;            newSlot->defaultDynamic = CLIPS_TRUE;           }                  /*===================================*/         /* Parse the list of default values. */         /*===================================*/                  defaultList = ParseDefault(readSource,multifieldSlot,(int) newSlot->defaultDynamic,                                  CLIPS_TRUE,&noneSpecified,&deriveSpecified,&DeftemplateError);         if (DeftemplateError == CLIPS_TRUE)           {            ReturnSlots(newSlot);            return(NULL);           }                  /*==================================*/         /* Store the default with the slot. */         /*==================================*/                  defaultFound = CLIPS_TRUE;         if (deriveSpecified) newSlot->defaultPresent = CLIPS_FALSE;         else if (noneSpecified)           {            newSlot->noDefault = CLIPS_TRUE;            newSlot->defaultPresent = CLIPS_FALSE;           }         newSlot->defaultList = defaultList;        }      /*============================================*/      /* Otherwise the attribute is an invalid one. */      /*============================================*/      else        {         SyntaxErrorMessage("slot attributes");         ReturnSlots(newSlot);         DeftemplateError = CLIPS_TRUE;         return(NULL);        }      /*===================================*/      /* Begin parsing the next attribute. */      /*===================================*/      GetToken(readSource,inputToken);     }   /*============================*/   /* Return the attribute list. */   /*============================*/   return(newSlot);  }#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */#endif /* DEFTEMPLATE_CONSTRUCT */

⌨️ 快捷键说明

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