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

📄 tmpltpsr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*              DEFTEMPLATE PARSER MODULE              */   /*******************************************************//*************************************************************//* Purpose: Parses the deftemplate construct.                *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _TMPLTPSR_SOURCE_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "constant.h"#include "clipsmem.h"#include "symbol.h"#include "scanner.h"#include "exprnpsr.h"#include "router.h"#include "constrct.h"#include "factmngr.h"#include "cstrnchk.h"#include "cstrnpsr.h"#include "cstrcpsr.h"#if BLOAD || BLOAD_AND_BSAVE#include "bload.h"#endif#include "default.h"#include "pattern.h" #include "watch.h"#include "cstrnutl.h"#include "tmpltdef.h"#include "tmpltbsc.h"#include "tmpltpsr.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if (! RUN_TIME) && (! BLOAD_ONLY)#if ANSI_COMPILER   static struct templateSlot    *SlotDeclarations(char *,struct token *);   static struct templateSlot    *ParseSlot(char *,struct token *,struct templateSlot *);   static struct templateSlot    *DefinedSlots(char *,SYMBOL_HN *,int,struct token *);#else   static struct templateSlot    *SlotDeclarations();   static struct templateSlot    *ParseSlot();   static struct templateSlot    *DefinedSlots();#endif#endif/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/#if (! RUN_TIME) && (! BLOAD_ONLY)   static int              DeftemplateError;#endif/*******************************************************//* ParseDeftemplate: Parses the deftemplate construct. *//*******************************************************/globle int ParseDeftemplate(readSource)  char *readSource;  {#if (MAC_MPW || MAC_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(readSource)#endif#if (! RUN_TIME) && (! BLOAD_ONLY)   SYMBOL_HN *deftemplateName;   struct deftemplate *newDeftemplate;   struct templateSlot *slots;   struct token inputToken;   /*================================================*/   /* Initialize pretty print and error information. */   /*================================================*/   DeftemplateError = CLIPS_FALSE;   SetPPBufferStatus(ON);   FlushPPBuffer();   SavePPBuffer("(deftemplate ");      /*==============================================================*/   /* Deftemplates can not be added when a binary image is loaded. */   /*==============================================================*/   #if BLOAD || BLOAD_AND_BSAVE   if (Bloaded() == CLIPS_TRUE)     {      CannotLoadWithBloadMessage("deftemplate");      return(CLIPS_TRUE);     }#endif   /*=======================================================*/   /* Parse the name and comment fields of the deftemplate. */   /*=======================================================*/#if DEBUGGING_FUNCTIONS   DeletedTemplateDebugFlags = 0;#endif    deftemplateName = GetConstructNameAndComment(readSource,&inputToken,"deftemplate",                                                FindDeftemplate,Undeftemplate,"%",                                                CLIPS_TRUE,CLIPS_TRUE,CLIPS_TRUE);   if (deftemplateName == NULL) return(CLIPS_TRUE);         if (ReservedPatternSymbol(ValueToString(deftemplateName),"deftemplate"))     {      ReservedPatternSymbolErrorMsg(ValueToString(deftemplateName),"a deftemplate name");      return(CLIPS_TRUE);     }        /*===========================================*/   /* Parse the slot fields of the deftemplate. */   /*===========================================*/   slots = SlotDeclarations(readSource,&inputToken);   if (DeftemplateError == CLIPS_TRUE) return(CLIPS_TRUE);   /*=====================================*/   /* Create a new deftemplate structure. */   /*=====================================*/   newDeftemplate = get_struct(deftemplate);   newDeftemplate->header.name =  deftemplateName;   newDeftemplate->header.next = NULL;   newDeftemplate->slotList = slots;   newDeftemplate->implied = CLIPS_FALSE;   newDeftemplate->numberOfSlots = 0;   newDeftemplate->busyCount = 0;   newDeftemplate->watch = 0;   newDeftemplate->inScope = CLIPS_TRUE;   newDeftemplate->patternNetwork = NULL;   newDeftemplate->header.whichModule = (struct defmoduleItemHeader *)                                        GetModuleItem(NULL,DeftemplateModuleIndex);   /*================================*/   /* Determine the number of slots. */   /*================================*/      while (slots != NULL)     {      newDeftemplate->numberOfSlots++;      slots = slots->next;     }   /*====================================*/   /* Store pretty print representation. */   /*====================================*/   if (GetConserveMemory() == CLIPS_TRUE)     { newDeftemplate->header.ppForm = NULL; }   else     { newDeftemplate->header.ppForm = CopyPPBuffer(); }      /*=======================================================================*/   /* If a template is redefined, then we want to restore its watch status. */   /*=======================================================================*/#if DEBUGGING_FUNCTIONS   if ((BitwiseTest(DeletedTemplateDebugFlags,0)) || GetWatchItem("facts"))     { SetDeftemplateWatch(ON,(VOID *) newDeftemplate); }#endif   /*==============================================*/   /* Add deftemplate to the list of deftemplates. */   /*==============================================*/   AddConstructToModule(&newDeftemplate->header);   InstallDeftemplate(newDeftemplate);   #endif   return(CLIPS_FALSE);  }  #if (! RUN_TIME) && (! BLOAD_ONLY)  /**************************************************************//* InstallDeftemplate: Increments all occurrences in the hash *//*   table of symbols found in an deftemplate and adds it to  *//*   the hash table.                                          *//**************************************************************/globle VOID InstallDeftemplate(theDeftemplate)  struct deftemplate *theDeftemplate;  {   struct templateSlot *slotPtr;   struct expr *tempExpr;      IncrementSymbolCount(theDeftemplate->header.name);   for (slotPtr = theDeftemplate->slotList;        slotPtr != NULL;        slotPtr = slotPtr->next)     {      IncrementSymbolCount(slotPtr->slotName);      tempExpr = AddHashedExpression(slotPtr->defaultList);      ReturnExpression(slotPtr->defaultList);      slotPtr->defaultList = tempExpr;      slotPtr->constraints = AddConstraint(slotPtr->constraints);     }  }  /********************************************************************//* SlotDeclarations: Parses the slot declarations of a deftemplate. *//********************************************************************/static struct templateSlot *SlotDeclarations(readSource,inputToken)  char *readSource;  struct token *inputToken;  {   struct templateSlot *newSlot, *slotList = NULL, *lastSlot = NULL;   struct templateSlot *multiSlot = NULL;   while (inputToken->type != RPAREN)     {      /*====================================================*/      /* Slots begin with a '(' followed by a slot keyword. */      /*====================================================*/      if (inputToken->type != LPAREN)        {         SyntaxErrorMessage("deftemplate");         ReturnSlots(slotList);         ReturnSlots(multiSlot);         DeftemplateError = CLIPS_TRUE;         return(NULL);        }      GetToken(readSource,inputToken);      if (inputToken->type != SYMBOL)        {         SyntaxErrorMessage("deftemplate");         ReturnSlots(slotList);         ReturnSlots(multiSlot);         DeftemplateError = CLIPS_TRUE;         return(NULL);        }      /*=================*/      /* Parse the slot. */      /*=================*/      newSlot = ParseSlot(readSource,inputToken,slotList);      if (DeftemplateError == CLIPS_TRUE)        {         ReturnSlots(newSlot);         ReturnSlots(slotList);         ReturnSlots(multiSlot);         return(NULL);        }      /*===========================================*/      /* Attach the new slot to the list of slots. */      /*===========================================*/      if (newSlot != NULL)        {         if (lastSlot == NULL)           { slotList = newSlot; }         else           { lastSlot->next = newSlot; }         lastSlot = newSlot;        }      /*================================*/      /* Check for closing parenthesis. */      /*================================*/      GetToken(readSource,inputToken);      if (inputToken->type != RPAREN)        {         PPBackup();         SavePPBuffer("\n   ");         SavePPBuffer(inputToken->printForm);        }     }  SavePPBuffer("\n");

⌨️ 快捷键说明

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