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

📄 scanner.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   while ( (inchar != '<') && (inchar != '"') &&           (inchar != '(') && (inchar != ')') &&           (inchar != '&') && (inchar != '|') && (inchar != '~') &&           (inchar != ' ') && (inchar != ';') &&           isprint(inchar) )     {      GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);      count++;      inchar = GetcCLIPS(logicalName);     }   /*===================================================*/   /* Return the last character scanned (the delimiter) */   /* to the input stream so it will be scanned as part */   /* of the next token.                                */   /*===================================================*/   UngetcCLIPS(inchar,logicalName);   /*====================================================*/   /* Add the symbol to the symbol table and return the  */   /* symbol table address of the symbol. Symbols of the */   /* form [<symbol>] are instance names, so the type    */   /* returned is INSTANCE_NAME rather than SYMBOL.      */   /*====================================================*/#if OBJECT_SYSTEM   if (count > 2)     {      if ((GlobalString[0] == '[') ? (GlobalString[count-1] == ']') : CLIPS_FALSE)        {         *type = INSTANCE_NAME;         inchar = ']';        }      else        {         *type = SYMBOL;         return(AddSymbol(GlobalString));        }      GlobalString[count-1] = EOS;      symbol = AddSymbol(GlobalString+1);      GlobalString[count-1] = (char) inchar;      return(symbol);     }   else     {      *type = SYMBOL;      return(AddSymbol(GlobalString));     }#else   *type = SYMBOL;   return(AddSymbol(GlobalString));#endif  }/*************************************//* ScanString: Scans a string token. *//*************************************/static VOID *ScanString(logicalName)  char *logicalName;  {   int inchar;   int pos = 0, max = 0;   char *theString = NULL;   VOID *thePtr;      /*============================================*/   /* Scan characters and add them to the string */   /* until the " delimiter is found.            */   /*============================================*/   inchar = GetcCLIPS(logicalName);   while ((inchar != '"') && (inchar != EOF))     {      if (inchar == '\\')        { inchar = GetcCLIPS(logicalName); }      theString = ExpandStringWithChar(inchar,theString,&pos,&max,max+80);      inchar = GetcCLIPS(logicalName);     }   if ((inchar == EOF) && (IgnoreCompletionErrors == CLIPS_FALSE))     { PrintCLIPS(WERROR,"\nEncountered End-Of-File while scanning a string\n"); }   /*===============================================*/   /* Add the string to the symbol table and return */   /* the symbol table address of the string.       */   /*===============================================*/      if (theString == NULL)     { thePtr = AddSymbol(""); }   else     {      thePtr = AddSymbol(theString);      rm(theString,max);     }   return(thePtr);  }/**************************************//* ScanNumber: Scans a numeric token. *//**************************************/static VOID ScanNumber(logicalName,theToken)  char *logicalName;  struct token *theToken;  {   int count = 0;   int inchar, phase;   int digitFound = CLIPS_FALSE;   int processFloat = CLIPS_FALSE;   double fvalue;   long lvalue;   int type;   /* Phases:              */   /*  -1 = sign           */   /*   0 = integral       */   /*   1 = decimal        */   /*   2 = exponent-begin */   /*   3 = exponent-value */   /*   5 = done           */   /*   9 = error          */   inchar = GetcCLIPS(logicalName);   phase = -1;   while ((phase != 5) && (phase != 9))     {      if (phase == -1)        {         if (isdigit(inchar))           {            phase = 0;            digitFound = CLIPS_TRUE;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }         else if ((inchar == '+') || (inchar == '-'))           {            phase = 0;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }         else if (inchar == '.')           {            processFloat = CLIPS_TRUE;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;            phase = 1;           }         else if ((inchar == 'E') || (inchar == 'e'))           {            processFloat = CLIPS_TRUE;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;            phase = 2;           }         else if ( (inchar == '<') || (inchar == '"') ||                   (inchar == '(') || (inchar == ')') ||                   (inchar == '&') || (inchar == '|') || (inchar == '~') ||                   (inchar == ' ') || (inchar == ';') ||                   (isprint(inchar) == 0) )           { phase = 5; }         else           {            phase = 9;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }        }      else if (phase == 0)        {         if (isdigit(inchar))           {            digitFound = CLIPS_TRUE;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }         else if (inchar == '.')           {            processFloat = CLIPS_TRUE;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;            phase = 1;           }         else if ((inchar == 'E') || (inchar == 'e'))           {            processFloat = CLIPS_TRUE;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;            phase = 2;           }         else if ( (inchar == '<') || (inchar == '"') ||                   (inchar == '(') || (inchar == ')') ||                   (inchar == '&') || (inchar == '|') || (inchar == '~') ||                   (inchar == ' ') || (inchar == ';') ||                   (isprint(inchar) == 0) )           { phase = 5; }         else           {            phase = 9;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }        }      else if (phase == 1)        {         if (isdigit(inchar))           {            digitFound = CLIPS_TRUE;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }         else if ((inchar == 'E') || (inchar == 'e'))           {            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;            phase = 2;           }         else if ( (inchar == '<') || (inchar == '"') ||                   (inchar == '(') || (inchar == ')') ||                   (inchar == '&') || (inchar == '|') || (inchar == '~') ||                   (inchar == ' ') || (inchar == ';') ||                   (isprint(inchar) == 0) )           { phase = 5; }         else           {            phase = 9;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }        }      else if (phase == 2)        {         if (isdigit(inchar))           {            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;            phase = 3;           }         else if ((inchar == '+') || (inchar == '-'))           {            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;            phase = 3;           }         else if ( (inchar == '<') || (inchar == '"') ||                   (inchar == '(') || (inchar == ')') ||                   (inchar == '&') || (inchar == '|') || (inchar == '~') ||                   (inchar == ' ') || (inchar == ';') ||                   (isprint(inchar) == 0) )           {            digitFound = CLIPS_FALSE;            phase = 5;           }         else           {            phase = 9;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }        }      else if (phase == 3)        {         if (isdigit(inchar))           {            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }         else if ( (inchar == '<') || (inchar == '"') ||                   (inchar == '(') || (inchar == ')') ||                   (inchar == '&') || (inchar == '|') || (inchar == '~') ||                   (inchar == ' ') || (inchar == ';') ||                   (isprint(inchar) == 0) )           {            if ((GlobalString[count-1] == '+') || (GlobalString[count-1] == '-'))              { digitFound = CLIPS_FALSE; }            phase = 5;           }         else           {            phase = 9;            GlobalString = ExpandStringWithChar(inchar,GlobalString,&GlobalPos,&GlobalMax,GlobalMax+80);            count++;           }        }      if ((phase != 5) && (phase != 9))        { inchar = GetcCLIPS(logicalName); }     }   if (phase == 9)     {      theToken->value = (VOID *) ScanSymbol(logicalName,count,&type);      theToken->type = type;      theToken->printForm = ValueToString(theToken->value);      return;     }   /*=======================================*/   /* Stuff last character back into buffer */   /* and return the number.                */   /*=======================================*/   UngetcCLIPS(inchar,logicalName);   if (! digitFound)     {      theToken->type = SYMBOL;      theToken->value = (VOID *) AddSymbol(GlobalString);      theToken->printForm = ValueToString(theToken->value);      return;     }   if (processFloat)     {      fvalue = atof(GlobalString);      theToken->type = FLOAT;      theToken->value = (VOID *) AddDouble(fvalue);      theToken->printForm = FloatToString(ValueToDouble(theToken->value));     }   else     {      lvalue = atol(GlobalString);      if ((lvalue == LONG_MAX) || (lvalue == LONG_MIN))        {         PrintWarningID("SCANNER",1,CLIPS_FALSE);         PrintCLIPS(WWARNING,"Over or underflow of long integer.\n");        }      theToken->type = INTEGER;      theToken->value = (VOID *) AddLong(lvalue);      theToken->printForm = LongIntegerToString(ValueToLong(theToken->value));     }   return;  }/***********************************************************//* CopyToken: Copies values of one token to another token. *//***********************************************************/globle VOID CopyToken(destination,source)  struct token *destination, *source;  {   destination->type = source->type;   destination->value = source->value;   destination->printForm = source->printForm;  }/****************************************//* ResetLineCount: Resets the scanner's *//*   line count to zero.                *//****************************************/globle VOID ResetLineCount()  {   LineCount = 0;  }/****************************************************//* GettLineCount: Returns the scanner's line count. *//****************************************************/globle long GetLineCount()  {   return(LineCount);  }/**********************************//* IncrementLineCount: Increments *//*   the scanner's line count.    *//**********************************/globle VOID IncrementLineCount()  {   LineCount++;  }/**********************************//* DecrementLineCount: Decrements *//*   the scanner's line count.    *//**********************************/globle VOID DecrementLineCount()  {   LineCount--;  }

⌨️ 快捷键说明

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