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

📄 globlpsr.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.24  06/05/06            */   /*                                                     */   /*              DEFGLOBAL PARSER MODULE                */   /*******************************************************//*************************************************************//* Purpose: Parses the defglobal construct.                  *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*      6.24: Renamed BOOLEAN macro type to intBool.         *//*                                                           *//*            Made the construct redefinition message more   *//*            prominent.                                     *//*                                                           *//*************************************************************/#define _GLOBLPSR_SOURCE_#include "setup.h"#if DEFGLOBAL_CONSTRUCT#include <string.h>#include "pprint.h"#include "router.h"#include "memalloc.h"#include "scanner.h"#include "evaluatn.h"#include "exprnpsr.h"#include "constrct.h"#include "multifld.h"#include "watch.h"#include "modulutl.h"#include "modulpsr.h"#include "cstrcpsr.h"#include "globldef.h"#include "globlbsc.h"#include "envrnmnt.h"#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE#include "bload.h"#endif#include "globlpsr.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if (! RUN_TIME) && (! BLOAD_ONLY)   static intBool                 GetVariableDefinition(void *,char *,int *,int,struct token *);   static void                    AddDefglobal(void *,SYMBOL_HN *,DATA_OBJECT_PTR,struct expr *);#endif/*********************************************************************//* ParseDefglobal: Coordinates all actions necessary for the parsing *//*   and creation of a defglobal into the current environment.       *//*********************************************************************/globle intBool ParseDefglobal(  void *theEnv,  char *readSource)  {   int defglobalError = FALSE;#if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(theEnv,readSource)#endif#if (! RUN_TIME) && (! BLOAD_ONLY)   struct token theToken;   int tokenRead = TRUE;   struct defmodule *theModule;   /*=====================================*/   /* Pretty print buffer initialization. */   /*=====================================*/   SetPPBufferStatus(theEnv,ON);   FlushPPBuffer(theEnv);   SetIndentDepth(theEnv,3);   SavePPBuffer(theEnv,"(defglobal ");   /*=================================================*/   /* Individual defglobal constructs can't be parsed */   /* while a binary load is in effect.               */   /*=================================================*/#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE   if ((Bloaded(theEnv) == TRUE) && (! ConstructData(theEnv)->CheckSyntaxMode))     {      CannotLoadWithBloadMessage(theEnv,"defglobal");      return(TRUE);     }#endif   /*===========================*/   /* Look for the module name. */   /*===========================*/   GetToken(theEnv,readSource,&theToken);   if (theToken.type == SYMBOL)     {      /*=================================================*/      /* The optional module name can't contain a module */      /* separator like other constructs. For example,   */      /* (defrule X::foo is OK for rules, but the right  */      /* syntax for defglobals is (defglobal X ?*foo*.   */      /*=================================================*/      tokenRead = FALSE;      if (FindModuleSeparator(ValueToString(theToken.value)))        {         SyntaxErrorMessage(theEnv,"defglobal");         return(TRUE);        }      /*=================================*/      /* Determine if the module exists. */      /*=================================*/      theModule = (struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(theToken.value));      if (theModule == NULL)        {         CantFindItemErrorMessage(theEnv,"defmodule",ValueToString(theToken.value));         return(TRUE);        }      /*=========================================*/      /* If the module name was OK, then set the */      /* current module to the specified module. */      /*=========================================*/      SavePPBuffer(theEnv," ");      EnvSetCurrentModule(theEnv,(void *) theModule);     }   /*===========================================*/   /* If the module name wasn't specified, then */   /* use the current module's name in the      */   /* defglobal's pretty print representation.  */   /*===========================================*/   else     {      PPBackup(theEnv);      SavePPBuffer(theEnv,EnvGetDefmoduleName(theEnv,((struct defmodule *) EnvGetCurrentModule(theEnv))));      SavePPBuffer(theEnv," ");      SavePPBuffer(theEnv,theToken.printForm);     }   /*======================*/   /* Parse the variables. */   /*======================*/   while (GetVariableDefinition(theEnv,readSource,&defglobalError,tokenRead,&theToken))     {      tokenRead = FALSE;      FlushPPBuffer(theEnv);      SavePPBuffer(theEnv,"(defglobal ");      SavePPBuffer(theEnv,EnvGetDefmoduleName(theEnv,((struct defmodule *) EnvGetCurrentModule(theEnv))));      SavePPBuffer(theEnv," ");     }#endif   /*==================================*/   /* Return the parsing error status. */   /*==================================*/   return(defglobalError);  }#if (! RUN_TIME) && (! BLOAD_ONLY)/***************************************************************//* GetVariableDefinition: Parses and evaluates a single global *//*   variable in a defglobal construct. Returns TRUE if the    *//*   variable was successfully parsed and FALSE if a right     *//*   parenthesis is encountered (signifying the end of the     *//*   defglobal construct) or an error occurs. The error status *//*   flag is also set if an error occurs.                      *//***************************************************************/static intBool GetVariableDefinition(  void *theEnv,  char *readSource,  int *defglobalError,  int tokenRead,  struct token *theToken)  {   SYMBOL_HN *variableName;   struct expr *assignPtr;   DATA_OBJECT assignValue;   /*========================================*/   /* Get next token, which should either be */   /* a closing parenthesis or a variable.   */   /*========================================*/   if (! tokenRead) GetToken(theEnv,readSource,theToken);   if (theToken->type == RPAREN) return(FALSE);   if (theToken->type == SF_VARIABLE)     {      SyntaxErrorMessage(theEnv,"defglobal");      *defglobalError = TRUE;      return(FALSE);     }   else if (theToken->type != GBL_VARIABLE)     {      SyntaxErrorMessage(theEnv,"defglobal");      *defglobalError = TRUE;      return(FALSE);     }   variableName = (SYMBOL_HN *) theToken->value;   SavePPBuffer(theEnv," ");   /*================================*/   /* Print out compilation message. */   /*================================*/#if DEBUGGING_FUNCTIONS   if ((EnvGetWatchItem(theEnv,"compilations") == ON) && GetPrintWhileLoading(theEnv))     {      if (QFindDefglobal(theEnv,variableName) != NULL)         {         PrintWarningID(theEnv,"CSTRCPSR",1,TRUE);         EnvPrintRouter(theEnv,WDIALOG,"Redefining defglobal: ");        }      else EnvPrintRouter(theEnv,WDIALOG,"Defining defglobal: ");      EnvPrintRouter(theEnv,WDIALOG,ValueToString(variableName));      EnvPrintRouter(theEnv,WDIALOG,"\n");     }   else#endif     { if (GetPrintWhileLoading(theEnv)) EnvPrintRouter(theEnv,WDIALOG,":"); }   /*==================================================================*/   /* Check for import/export conflicts from the construct definition. */

⌨️ 快捷键说明

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