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

📄 rulecmp.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*            DEFRULE CONSTRUCTS-TO-C MODULE           */   /*******************************************************//*************************************************************//* Purpose: Implements the constructs-to-c feature for the   *//*    defrule construct.                                     *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _RULECMP_SOURCE_#include "setup.h"#if DEFRULE_CONSTRUCT && (! RUN_TIME) && CONSTRUCT_COMPILER#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "factbld.h" #include "reteutil.h"#include "rulecmp.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER   static int                     ConstructToCode(char *,int,FILE *,int,int);   static VOID                    JoinToCode(FILE *,struct joinNode *,int,int);   static VOID                    DefruleModuleToCode(FILE *,struct defmodule *,int,int,int);   static VOID                    DefruleToCode(FILE *,struct defrule *,int,int,int);   static VOID                    CloseDefruleFiles(FILE *,FILE *,FILE *,int);   static VOID                    BeforeDefrulesCode(void);#else   static int                     ConstructToCode();   static VOID                    JoinToCode();   static VOID                    DefruleModuleToCode();   static VOID                    DefruleToCode();   static VOID                    CloseDefruleFiles();   static VOID                    BeforeDefrulesCode();#endif/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/   globle struct CodeGeneratorItem *DefruleCodeItem;/***********************************************************//* DefruleCompilerSetup: Initializes the defrule construct *//*   for use with the constructs-to-c command.             *//***********************************************************/globle VOID DefruleCompilerSetup()  {   DefruleCodeItem = AddCodeGeneratorItem("defrules",0,BeforeDefrulesCode,                                          NULL,ConstructToCode,3);  }/**************************************************************//* BeforeDefrulesCode: Assigns each defrule and join with a   *//*   unique ID which will be used for pointer references when *//*   the data structures are written to a file as C code      *//**************************************************************/static VOID BeforeDefrulesCode()  {   long int moduleCount, ruleCount, joinCount;   TagRuleNetwork(&moduleCount,&ruleCount,&joinCount);  }/*********************************************************//* ConstructToCode: Produces defrule code for a run-time *//*   module created using the constructs-to-c function.  *//*********************************************************/static int ConstructToCode(fileName,fileID,headerFP,imageID,maxIndices)  char *fileName;  int fileID;  FILE *headerFP;  int imageID;  int maxIndices;  {   int fileCount = 1;   struct defmodule *theModule;   struct defrule *theDefrule;   struct joinNode *theJoin;   int joinArrayCount = 0, joinArrayVersion = 1;   int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1;     int defruleArrayCount = 0, defruleArrayVersion = 1;   FILE *joinFile = NULL, *moduleFile = NULL, *defruleFile = NULL;   /*==============================================*/   /* Include the appropriate defrule header file. */   /*==============================================*/      fprintf(headerFP,"#include \"ruledef.h\"\n");   /*=========================================================*/   /* Loop through all the modules, all the defrules, and all */   /* the join nodes writing their C code representation to   */   /* the file as they are traversed.                         */   /*=========================================================*/      for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {        /*=========================*/      /* Set the current module. */      /*=========================*/               SetCurrentModule((VOID *) theModule);                  /*==========================*/      /* Save the defrule module. */      /*==========================*/            moduleFile = OpenFileIfNeeded(moduleFile,fileName,fileID,imageID,&fileCount,                                    moduleArrayVersion,headerFP,                                    "struct defruleModule",ModulePrefix(DefruleCodeItem),                                    CLIPS_FALSE,NULL);                                          if (moduleFile == NULL)        {         CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices);         return(0);        }              DefruleModuleToCode(moduleFile,theModule,imageID,maxIndices,moduleCount);      moduleFile = CloseFileIfNeeded(moduleFile,&moduleArrayCount,&moduleArrayVersion,                                     maxIndices,NULL,NULL);      /*=========================================*/      /* Loop through all of the defrules (and   */      /* their disjuncts) in the current module. */      /*=========================================*/            theDefrule = (struct defrule *) GetNextDefrule(NULL);            while (theDefrule != NULL)        {         /*===================================*/         /* Save the defrule data structures. */         /*===================================*/                  defruleFile = OpenFileIfNeeded(defruleFile,fileName,fileID,imageID,&fileCount,                                        defruleArrayVersion,headerFP,                                        "struct defrule",ConstructPrefix(DefruleCodeItem),                                        CLIPS_FALSE,NULL);         if (defruleFile == NULL)           {            CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices);            return(0);           }                    DefruleToCode(defruleFile,theDefrule,imageID,maxIndices,                        moduleCount);         defruleArrayCount++;         defruleFile = CloseFileIfNeeded(defruleFile,&defruleArrayCount,&defruleArrayVersion,                                         maxIndices,NULL,NULL);                                          /*================================*/         /* Save the join data structures. */         /*================================*/                  for (theJoin = theDefrule->lastJoin;              theJoin != NULL;              theJoin = GetPreviousJoin(theJoin))           {              if (theJoin->marked)              {               joinFile = OpenFileIfNeeded(joinFile,fileName,fileID,imageID,&fileCount,                                        joinArrayVersion,headerFP,                                       "struct joinNode",JoinPrefix(),CLIPS_FALSE,NULL);               if (joinFile == NULL)                  {                  CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices);                  return(0);                 }                             JoinToCode(joinFile,theJoin,imageID,maxIndices);               joinArrayCount++;               joinFile = CloseFileIfNeeded(joinFile,&joinArrayCount,&joinArrayVersion,                                            maxIndices,NULL,NULL);              }           }                    /*==========================================*/         /* Move on to the next disjunct or defrule. */         /*==========================================*/                  if (theDefrule->disjunct != NULL) theDefrule = theDefrule->disjunct;         else theDefrule = (struct defrule *) GetNextDefrule(theDefrule);        }              moduleCount++;      moduleArrayCount++;     }           CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices);        return(1);  }/********************************************************//* CloseDefruleFiles: Closes all of the C files created *//*   for defrule. Called when an error occurs or when   *//*   the defrules have all been written to the files.   *//********************************************************/static VOID CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices)  FILE *moduleFile, *defruleFile, *joinFile;   int maxIndices;    {   int count = maxIndices;   int arrayVersion = 0;      if (joinFile != NULL)      {      count = maxIndices;      CloseFileIfNeeded(joinFile,&count,&arrayVersion,maxIndices,NULL,NULL);     }        if (defruleFile != NULL)      {      count = maxIndices;      CloseFileIfNeeded(defruleFile,&count,&arrayVersion,maxIndices,NULL,NULL);     }        if (moduleFile != NULL)      {      count = maxIndices;      CloseFileIfNeeded(moduleFile,&count,&arrayVersion,maxIndices,NULL,NULL);     }  }  /*********************************************************//* DefruleModuleToCode: Writes the C code representation *//*   of a single defrule module to the specified file.   *//*********************************************************/#if IBM_TBC#pragma argsused#endifstatic VOID DefruleModuleToCode(theFile,theModule,imageID,maxIndices,moduleCount)

⌨️ 快捷键说明

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