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

📄 genrcpsr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*               CLIPS Version 6.05  04/09/97          */   /*                                                     */   /*                                                     */   /*******************************************************//*************************************************************//* Purpose: CLIPS Generic Functions Parsing Routines         *//*                                                           *//* Principal Programmer(s):                                  *//*      Brian L. Donnell                                     *//*                                                           *//* Contributing Programmer(s):                               *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/   /* =========================================   *****************************************               EXTERNAL DEFINITIONS   =========================================   ***************************************** */#include "setup.h"#if DEFGENERIC_CONSTRUCT && (! BLOAD_ONLY) && (! RUN_TIME)#if BLOAD || BLOAD_AND_BSAVE#include "bload.h"#endif#if DEFFUNCTION_CONSTRUCT#include "dffnxfun.h"#endif#if OBJECT_SYSTEM#include "classfun.h"#include "classcom.h"#endif#include "clipsmem.h"#include "cstrcpsr.h"#include "exprnpsr.h"#include "genrccom.h"#include "immthpsr.h"#include "modulutl.h"#include "prcdrpsr.h"#include "prccode.h"#include "router.h"#include "scanner.h"#define _GENRCPSR_SOURCE_#include "genrcpsr.h"/* =========================================   *****************************************                   CONSTANTS   =========================================   ***************************************** */#define HIGHER_PRECEDENCE -1#define IDENTICAL          0#define LOWER_PRECEDENCE   1#define CURR_ARG_VAR "current-argument"/* =========================================   *****************************************               MACROS AND TYPES   =========================================   ***************************************** */   /* =========================================   *****************************************      INTERNALLY VISIBLE FUNCTION HEADERS   =========================================   ***************************************** */#if ANSI_COMPILERstatic BOOLEAN ValidGenericName(char *);static SYMBOL_HN *ParseMethodNameAndIndex(char *,unsigned *);#if DEBUGGING_FUNCTIONSstatic VOID CreateDefaultGenericPPForm(DEFGENERIC *);#endifstatic int ParseMethodParameters(char *,EXPRESSION **,SYMBOL_HN **);static RESTRICTION *ParseRestriction(char *);static VOID ReplaceCurrentArgRefs(EXPRESSION *);static int DuplicateParameters(EXPRESSION *,EXPRESSION **,SYMBOL_HN *);static EXPRESSION *AddParameter(EXPRESSION *,EXPRESSION *,SYMBOL_HN *,RESTRICTION *);static EXPRESSION *ValidType(SYMBOL_HN *);static BOOLEAN RedundantClasses(VOID *,VOID *);static DEFGENERIC *AddGeneric(SYMBOL_HN *,int *);static DEFMETHOD *AddGenericMethod(DEFGENERIC *,int,unsigned);static int RestrictionsCompare(EXPRESSION *,int,int,int,DEFMETHOD *);static int TypeListCompare(RESTRICTION *,RESTRICTION *);static DEFGENERIC *NewGeneric(SYMBOL_HN *);#else /* ANSI_COMPILER */static BOOLEAN ValidGenericName();static SYMBOL_HN *ParseMethodNameAndIndex();#if DEBUGGING_FUNCTIONSstatic VOID CreateDefaultGenericPPForm();#endifstatic int ParseMethodParameters();static RESTRICTION *ParseRestriction();static VOID ReplaceCurrentArgRefs();static int DuplicateParameters();static EXPRESSION *AddParameter();static EXPRESSION *ValidType();static BOOLEAN RedundantClasses();static DEFGENERIC *AddGeneric();static DEFMETHOD *AddGenericMethod();static int RestrictionsCompare();static int TypeListCompare();static DEFGENERIC *NewGeneric();#endif /* ANSI_COMPILER */      /* =========================================   *****************************************      INTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */static struct token GenericInputToken;/* =========================================   *****************************************          EXTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** */   /***************************************************************************  NAME         : ParseDefgeneric  DESCRIPTION  : Parses the defgeneric construct  INPUTS       : The input logical name  RETURNS      : CLIPS_FALSE if successful parse, CLIPS_TRUE otherwise  SIDE EFFECTS : Inserts valid generic function defn into generic entry  NOTES        : CLIPS Syntax :                 (defgeneric <name> [<comment>]) ***************************************************************************/globle BOOLEAN ParseDefgeneric(readSource)  char *readSource;  {   SYMBOL_HN *gname;   DEFGENERIC *gfunc;   int new;      SetPPBufferStatus(ON);   FlushPPBuffer();   SavePPBuffer("(defgeneric ");   SetIndentDepth(3);  #if BLOAD || BLOAD_AND_BSAVE   if (Bloaded() == CLIPS_TRUE)      {      CannotLoadWithBloadMessage("defgeneric");      return(CLIPS_TRUE);     }#endif   gname = GetConstructNameAndComment(readSource,&GenericInputToken,"defgeneric",                                      FindDefgeneric,NULL,"^",CLIPS_TRUE,                                      CLIPS_TRUE,CLIPS_TRUE);   if (gname == NULL)     return(CLIPS_TRUE);   if (ValidGenericName(ValueToString(gname)) == CLIPS_FALSE)     return(CLIPS_TRUE);   if (GenericInputToken.type != RPAREN)     {      PrintErrorID("GENRCPSR",1,CLIPS_FALSE);      PrintCLIPS(WERROR,"Expected ')' to complete defgeneric.\n");      return(CLIPS_TRUE);     }   SavePPBuffer("\n");   gfunc = AddGeneric(gname,&new);#if DEBUGGING_FUNCTIONS   SetDefgenericPPForm((VOID *) gfunc,GetConserveMemory() ? NULL : CopyPPBuffer());#endif   return(CLIPS_FALSE);  }  /***************************************************************************  NAME         : ParseDefmethod  DESCRIPTION  : Parses the defmethod construct  INPUTS       : The input logical name  RETURNS      : CLIPS_FALSE if successful parse, CLIPS_TRUE otherwise  SIDE EFFECTS : Inserts valid method definition into generic entry  NOTES        : CLIPS Syntax :                 (defmethod <name> [<index>] [<comment>]                    (<restriction>* [<wildcard>])                    <action>*)                 <restriction> :== ?<name> |                                   (?<name> <type>* [<restriction-query>])                 <wildcard>    :== $?<name> |                                   ($?<name> <type>* [<restriction-query>]) ***************************************************************************/globle BOOLEAN ParseDefmethod(readSource)  char *readSource;  {   SYMBOL_HN *gname;   int rcnt,mposn,mi,new,mnew = CLIPS_FALSE,lvars,error;   EXPRESSION *params,*actions,*tmp;   SYMBOL_HN *wildcard;   DEFMETHOD *meth;   DEFGENERIC *gfunc;   unsigned index;      SetPPBufferStatus(ON);   FlushPPBuffer();   SetIndentDepth(3);       SavePPBuffer("(defmethod ");#if BLOAD || BLOAD_AND_BSAVE   if (Bloaded() == CLIPS_TRUE)      {            CannotLoadWithBloadMessage("defmethod");      return(CLIPS_TRUE);     }#endif   gname = ParseMethodNameAndIndex(readSource,&index);   if (gname == NULL)     return(CLIPS_TRUE);        if (ValidGenericName(ValueToString(gname)) == CLIPS_FALSE)     return(CLIPS_TRUE);        /* ========================================================      Go ahead and add the header so that the generic function      can be called recursively      ======================================================== */   gfunc = AddGeneric(gname,&new);#if DEBUGGING_FUNCTIONS   if (new)      CreateDefaultGenericPPForm(gfunc);#endif         IncrementIndentDepth(1);   rcnt = ParseMethodParameters(readSource,&params,&wildcard);   DecrementIndentDepth(1);   if (rcnt == -1)     goto DefmethodParseError;   PPCRAndIndent();   for (tmp = params ; tmp != NULL ; tmp = tmp->nextArg)     {      ReplaceCurrentArgRefs(((RESTRICTION *) tmp->argList)->query);      if (ReplaceProcVars("method",((RESTRICTION *) tmp->argList)->query,                                  params,wildcard,NULL,NULL))        {         DeleteTempRestricts(params);         goto DefmethodParseError;        }     }   meth = FindMethodByRestrictions(gfunc,params,rcnt,wildcard,&mposn);   error = CLIPS_FALSE;   if (meth != NULL)     {      if (meth->system)        {         PrintErrorID("GENRCPSR",17,CLIPS_FALSE);         PrintCLIPS(WERROR,"Cannot replace the implicit system method #");         PrintLongInteger(WERROR,(long) meth->index);         PrintCLIPS(WERROR,".\n");         error = CLIPS_TRUE;        }      else if ((index != 0) && (index != meth->index))        {         PrintErrorID("GENRCPSR",2,CLIPS_FALSE);         PrintCLIPS(WERROR,"New method #");         PrintLongInteger(WERROR,(long) index);         PrintCLIPS(WERROR," would be indistinguishable from method #");         PrintLongInteger(WERROR,(long) meth->index);         PrintCLIPS(WERROR,".\n");         error = CLIPS_TRUE;        }     }   else if (index != 0)     {      mi = FindMethodByIndex(gfunc,index);      if (mi == -1)        mnew = CLIPS_TRUE;      else if (gfunc->methods[mi].system)        {         PrintErrorID("GENRCPSR",17,CLIPS_FALSE);         PrintCLIPS(WERROR,"Cannot replace the implicit system method #");         PrintLongInteger(WERROR,(long) index);         PrintCLIPS(WERROR,".\n");         error = CLIPS_TRUE;        }     }   else     mnew = CLIPS_TRUE;   if (error)     {      DeleteTempRestricts(params);      goto DefmethodParseError;     }   ReturnContext = CLIPS_TRUE;   actions = ParseProcActions("method",readSource,                              &GenericInputToken,params,wildcard,                              NULL,NULL,&lvars,NULL);   if (actions == NULL)     {      DeleteTempRestricts(params);      goto DefmethodParseError;     }   PPBackup();   PPBackup();   SavePPBuffer(GenericInputToken.print_rep);   SavePPBuffer("\n");        #if DEBUGGING_FUNCTIONS   meth = AddMethod(gfunc,meth,mposn,index,params,rcnt,lvars,wildcard,actions,             GetConserveMemory() ? NULL : CopyPPBuffer(),CLIPS_FALSE);#else   meth = AddMethod(gfunc,meth,mposn,index,params,rcnt,lvars,wildcard,actions,NULL,CLIPS_FALSE);#endif   DeleteTempRestricts(params);   if (GetPrintWhileLoading() && GetCompilationsWatch())     {      PrintCLIPS(WDIALOG,"   Method #");      PrintLongInteger(WDIALOG,(long) meth->index);      PrintCLIPS(WDIALOG,mnew ? " defined.\n" : " redefined.\n");     }   return(CLIPS_FALSE);DefmethodParseError:   if (new)     {      RemoveConstructFromModule((VOID *) gfunc);      RemoveDefgeneric((VOID *) gfunc);     }   return(CLIPS_TRUE);  }   /************************************************************************  NAME         : AddMethod  DESCRIPTION  : (Re)defines a new method for a generic                 If method already exists, deletes old information                    before proceeding.  INPUTS       : 1) The generic address                 2) The old method address (can be NULL)                 3) The old method array position (can be -1)                 4) The method index to assign (0 if don't care)                 5) The parameter expression-list                    (restrictions attached to argList pointers)                 6) The number of restrictions                 7) The number of locals vars reqd                 8) The wildcard symbol (NULL if none)                 9) Method actions                 10) Method pretty-print form                 11) A flag indicating whether to copy the                     restriction types or just use the pointers  RETURNS      : The new (old) method address  SIDE EFFECTS : Method added to (or changed in) method array for generic                 Restrictions repacked into new method                 Actions and pretty-print form attached  NOTES        : Assumes if a method is being redefined, its busy                   count is 0!!                 IMPORTANT: Expects that FindMethodByRestrictions() has                   previously been called to determine if this method                   is already present or not.  Arguments #1 and #2                   should be the values obtained from FindMethod...(). ************************************************************************/

⌨️ 快捷键说明

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