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

📄 objrtgen.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*               CLIPS Version 6.05  04/09/97          */   /*                                                     */   /*    INFERENCE ENGINE OBJECT PARSING ROUTINES MODULE  */   /*******************************************************//**************************************************************//* Purpose: RETE Network Parsing Interface for Objects        *//*                                                            *//* Principal Programmer(s):                                   *//*      Brian L. Donnell                                      *//*                                                            *//* Contributing Programmer(s):                                *//*                                                            *//* Revision History:                                          *//*                                                            *//**************************************************************//* =========================================   *****************************************               EXTERNAL DEFINITIONS   =========================================   ***************************************** */#include "setup.h"#if INSTANCE_PATTERN_MATCHING && (! RUN_TIME) && (! BLOAD_ONLY)#ifndef _CLIPS_STDIO_#include <stdio.h>#define _CLIPS_STDIO_#endif#include "classfun.h"#include "objrtfnx.h"#define _OBJRTGEN_SOURCE_#include "objrtgen.h"/* =========================================   *****************************************                   CONSTANTS   =========================================   ***************************************** *//* =========================================   *****************************************                 MACROS AND TYPES   =========================================   ***************************************** *//* =========================================   *****************************************      INTERNALLY VISIBLE FUNCTION HEADERS   =========================================   ***************************************** */#if ANSI_COMPILERstatic VOID GenObjectGetVar(int,EXPRESSION *,struct lhsParseNode *);static BOOLEAN IsSimpleSlotVariable(struct lhsParseNode *);static EXPRESSION *GenerateSlotComparisonTest(int,struct lhsParseNode *,struct lhsParseNode *);#elsestatic VOID GenObjectGetVar();static BOOLEAN IsSimpleSlotVariable();static EXPRESSION *GenerateSlotComparisonTest();#endif/* =========================================   *****************************************      EXTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */   /* =========================================   *****************************************      INTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** *//* =========================================   *****************************************          EXTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** */   /**********************************************  Build functions used by AddPatternParser() to  provide object access to the join nertwork **********************************************/globle VOID ReplaceGetJNObjectValue(theItem,theNode)  EXPRESSION *theItem;  struct lhsParseNode *theNode;  {   GenObjectGetVar(CLIPS_TRUE,theItem,theNode);  }  globle EXPRESSION *GenGetJNObjectValue(theNode)  struct lhsParseNode *theNode;  {   EXPRESSION *theItem;      theItem = GenConstant(0,NULL);   GenObjectGetVar(CLIPS_TRUE,theItem,theNode);   return(theItem);  }  globle EXPRESSION *ObjectJNVariableComparison(selfNode,referringNode)  struct lhsParseNode *selfNode, *referringNode;  {   return(GenerateSlotComparisonTest(CLIPS_TRUE,selfNode,referringNode));  }  /**********************************************  Build functions used by AddPatternParser() to  provide object access to the pattern network **********************************************/globle EXPRESSION *GenObjectPNConstantCompare(theNode)  struct lhsParseNode *theNode;  {   struct ObjectCmpPNConstant hack;   EXPRESSION *exp;   int tmpType;      /* ===============================================================      If the value of a single field slot (or relation name) is being      compared against a constant, then use specialized routines for      doing the comparison.            If a constant comparison is being done within a multifield slot      and the constant's position has no multifields to the left or      no multifields to the right, then use the same routine used for      the single field slot case, but include the offset from either      the beginning or end of the slot.            Otherwise, use a general eq/neq test.      =============================================================== */   ClearBitString((VOID *) &hack,(int) sizeof(struct ObjectCmpPNConstant));   if (theNode->negated)     hack.fail = 1;   else     hack.pass = 1;   if (((theNode->withinMultifieldSlot == CLIPS_FALSE) ||        (theNode->multiFieldsAfter == 0) ||        (theNode->multiFieldsBefore == 0)) &&       (theNode->slotNumber != ISA_ID) && (theNode->slotNumber != NAME_ID))     {      if (theNode->withinMultifieldSlot == CLIPS_FALSE)        hack.fromBeginning = CLIPS_TRUE;      else if (theNode->multiFieldsBefore == 0)        {         hack.fromBeginning = CLIPS_TRUE;         hack.offset = theNode->singleFieldsBefore;        }      else        hack.offset = theNode->singleFieldsAfter;      exp = GenConstant(OBJ_PN_CONSTANT,AddBitMap((VOID *) &hack,                                        (int) sizeof(struct ObjectCmpPNConstant)));      exp->argList = GenConstant(theNode->type,theNode->value);     }   else     {      hack.general = 1;      exp = GenConstant(OBJ_PN_CONSTANT,AddBitMap((VOID *) &hack,                                        (int) sizeof(struct ObjectCmpPNConstant)));      exp->argList = GenConstant(0,NULL);      tmpType = theNode->type;      theNode->type = SF_VARIABLE;      GenObjectGetVar(CLIPS_FALSE,exp->argList,theNode);      theNode->type = tmpType;      exp->argList->nextArg = GenConstant(theNode->type,theNode->value);     }   return(exp);  }  globle VOID ReplaceGetPNObjectValue(theItem,theNode)  EXPRESSION *theItem;  struct lhsParseNode *theNode;  {   GenObjectGetVar(CLIPS_FALSE,theItem,theNode);  }  globle EXPRESSION *GenGetPNObjectValue(theNode)  struct lhsParseNode *theNode;  {   EXPRESSION *theItem;      theItem = GenConstant(0,NULL);   GenObjectGetVar(CLIPS_FALSE,theItem,theNode);   return(theItem);  }  globle EXPRESSION *ObjectPNVariableComparison(selfNode,referringNode)  struct lhsParseNode *selfNode, *referringNode;  {   return(GenerateSlotComparisonTest(CLIPS_FALSE,selfNode,referringNode));  }/****************************************************  NAME         : GenObjectLengthTest  DESCRIPTION  : Generates a test on the cardinality                 of a slot matching an object pattern  INPUTS       : The first lhsParseNode for a slot                 in an object pattern  RETURNS      : Nothing useful  SIDE EFFECTS : The lhsParseNode network test is                 modified to include the length test  NOTES        : None ****************************************************/globle VOID GenObjectLengthTest(theNode)  struct lhsParseNode *theNode;  {   struct ObjectMatchLength hack;   EXPRESSION *theTest;      if ((theNode->singleFieldsAfter == 0) &&        (theNode->type != SF_VARIABLE) &&        (theNode->type != SF_WILDCARD))     return;      ClearBitString((VOID *) &hack,(int) sizeof(struct ObjectMatchLength));      if ((theNode->type != MF_VARIABLE) &&       (theNode->type != MF_WILDCARD) &&       (theNode->multiFieldsAfter == 0))     hack.exactly = 1;   else     hack.exactly = 0;        if ((theNode->type == SF_VARIABLE) || (theNode->type == SF_WILDCARD))     hack.minLength = 1 + theNode->singleFieldsAfter;   else     hack.minLength = theNode->singleFieldsAfter;        theTest = GenConstant(OBJ_SLOT_LENGTH,AddBitMap((VOID *) &hack,                                         (int) sizeof(struct ObjectMatchLength)));   theNode->networkTest = CombineExpressions(theTest,theNode->networkTest);  }  /****************************************************  NAME         : GenObjectZeroLengthTest  DESCRIPTION  : Generates a test on the cardinality                 of a slot matching an object pattern  INPUTS       : The first lhsParseNode for a slot                 in an object pattern  RETURNS      : Nothing useful  SIDE EFFECTS : The lhsParseNode network test is                 modified to include the length test  NOTES        : None ****************************************************/globle VOID GenObjectZeroLengthTest(theNode)  struct lhsParseNode *theNode;  {   struct ObjectMatchLength hack;   EXPRESSION *theTest;      ClearBitString((VOID *) &hack,(int) sizeof(struct ObjectMatchLength));   hack.exactly = 1;   hack.minLength = 0;   theTest = GenConstant(OBJ_SLOT_LENGTH,AddBitMap((VOID *) &hack,                                         (int) sizeof(struct ObjectMatchLength)));   theNode->networkTest = CombineExpressions(theTest,theNode->networkTest);  }  /* =========================================   *****************************************          INTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** *//***************************************************  NAME         : GenObjectGetVar  DESCRIPTION  : Generates the expressions necessary                 to access object pattern variables  INPUTS       : 1) An integer code indicating if                    this is a join network reference                    or a pattern network reference                 2) The expression for which to set                    the type and value                 3) The lhsParseNode for the                    variable reference  RETURNS      : Nothing useful  SIDE EFFECTS : The value is a packed long holding                 pattern index, slot number,                 field index, etc.  NOTES        : None ***************************************************/static VOID GenObjectGetVar(joinReference,theItem,theNode)  int joinReference;  EXPRESSION *theItem;  struct lhsParseNode *theNode;  {   struct ObjectMatchVar1 hack1;   struct ObjectMatchVar2 hack2;      ClearBitString((VOID *) &hack1,(int) sizeof(struct ObjectMatchVar1));   ClearBitString((VOID *) &hack2,(int) sizeof(struct ObjectMatchVar2));      if (joinReference)     {      hack1.whichPattern = (unsigned) theNode->pattern;      hack2.whichPattern = (unsigned) theNode->pattern;     }        /* ========================      Access an object address

⌨️ 快捷键说明

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