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

📄 int_expr.c

📁 LastWave
💻 C
📖 第 1 页 / 共 5 页
字号:
/*..........................................................................*//*                                                                          *//*      L a s t W a v e   K e r n e l   2 . 1                           *//*                                                                          *//*      Copyright (C) 1998-2003 Emmanuel Bacry.                             *//*      email : lastwave@cmap.polytechnique.fr                              *//*                                                                          *//*..........................................................................*//*                                                                          *//*      Note : This file implements a small expression evaluator. It is     *//*             based on an evaluator written by Kittiphan Techakittiroj at  *//*             Ball State University (16 Dec 1994).                         *//*                                                                          *//*..........................................................................*//*                                                                          *//*      This program is a free software, you can redistribute it and/or     *//*      modify it under the terms of the GNU General Public License as      *//*      published by the Free Software Foundation; either version 2 of the  *//*      License, or (at your option) any later version                      *//*                                                                          *//*      This program is distributed in the hope that it will be useful,     *//*      but WITHOUT ANY WARRANTY; without even the implied warranty of      *//*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *//*      GNU General Public License for more details.                        *//*                                                                          *//*      You should have received a copy of the GNU General Public License   *//*      along with this program (in a file named COPYRIGHT);                *//*      if not, write to the Free Software Foundation, Inc.,                *//*      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             *//*                                                                          *//*..........................................................................*/#include "lastwave.h"#include "signals.h"#include "images.h"#include "int_fsilist.h"#define Clean(val)  if ((val) != NULL) {(val) = NULL;}unsigned char TTExpr1(char* begin, char** left, LWFLOAT *resFlt,VALUE *resVC, unsigned char flagType,ExprDefParam *defParam); /* * The default values */int _theSignalSize;double _theSignalDx,_theSignalX0;int _theImageNRow;int _theImageNCol;LWFLOAT _vmin,_vmax,_vdx; /* The level everything is evaluated at */LEVEL _theLevel;/* * TermExpr -> .... * */extern unsigned char TGetVariableContentLevelExpr(LEVEL level, char *begin, char **left, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType, unsigned char flagSimple, ExprDefParam *defParam);extern unsigned char TGetFieldOrExtractContentExpr(LEVEL level, VALUE theCont, char *begin, char **left, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType, ExprDefParam *defParam);#define MaxStrLength 10000static unsigned char TermExpr(char* begin, char** left, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType, ExprDefParam *defParam){  static char str[MaxStrLength+10];  char *str1,*begin1;  char *end,*type;  unsigned char r;  unsigned char answer;  FSIList *list;  int n;  VALUE value;  char flagStop,c;  char quote;  LISTV lv;  char oldFlagSpace;  int ds,di;  RANGE rg;  char oldFlagEmptySI;    answer = 0;     *left = begin;   /************************************   *   * A number written as a sequence of digits    *   ************************************/         if (flagType & FloatType ) {        *resFlt = strtod(begin,&end);     /* If it is of the form 10.dx, 10a or 10[] then it is not a number */     if (end != begin && !IsValidSymbolChar1(*end) && *end!= '[') {       ParamSkipSpace(end);       (*left) = end;       Clean(*resVC);       return(FloatType);     }   }    /************************************   *   * Test the strings 'string'   *   ************************************/  if (*begin == '\'' || *begin == '\"') {    if (!(flagType & StringType)) {      Clean(*resVC);      SetErrorf("Do not expect a string");      return(0);    }    quote = *begin;    begin++;    str1 = str;    n = 0;    flagStop = NO;        while (1) {           switch(*begin) {            case '\0' : flagStop = YES; break;      case '\'' :         if (quote != '\'') c = '\'';        else flagStop = YES;        break;      case '"' :         if (quote != '"') c = '"';        else flagStop = YES;        break;      case '\\' :        switch(begin[1]) {          case '\n' : begin+=2; if (*begin == '\r') begin++; continue;        case '\r' : begin+=2; if (*begin == '\n') begin++; continue;        case 'n' : c ='\n'; begin++; break;        case 't' : c ='\t'; begin++; break;        case 'r' : c ='\r'; begin++; break;        case '\'' : c ='\''; begin++; break;        case '"' : c ='"'; begin++; break;        case '$' : c ='$'; begin++; break;        case '\\' : c ='\\'; begin++; break;        case 'G' :           begin+=2;           if (!strncmp(begin,"Alpha",5)) {c = 193; begin+= 5;}          else if (!strncmp(begin,"Beta",4)) {c = 194; begin+= 4;}          else if (!strncmp(begin,"Gamma",5)) {c = 195; begin+= 4;}          else if (!strncmp(begin,"Delta",5)) {c = 196; begin+= 5;}          else if (!strncmp(begin,"Epsilon",7)) {c = 197; begin+= 7;}          else if (!strncmp(begin,"Zeta",4)) {c = 198; begin+= 4;}          else if (!strncmp(begin,"Eta",3)) {c = 199; begin+= 3;}          else if (!strncmp(begin,"Theta",5)) {c = 200; begin+= 5;}          else if (!strncmp(begin,"Iota",4)) {c = 201; begin+= 4;}          else if (!strncmp(begin,"Kappa",5)) {c = 202; begin+= 5;}          else if (!strncmp(begin,"Lambda",6)) {c = 203; begin+= 6;}          else if (!strncmp(begin,"Mu",2)) {c = 204; begin+= 2;}          else if (!strncmp(begin,"Nu",2)) {c = 205; begin+= 2;}          else if (!strncmp(begin,"Xi",2)) {c = 206; begin+= 2;}          else if (!strncmp(begin,"Omicron",7)) {c = 207; begin+= 7;}          else if (!strncmp(begin,"Pi",2)) {c = 208; begin+= 2;}          else if (!strncmp(begin,"Rho",3)) {c = 209; begin+= 3;}          else if (!strncmp(begin,"Sigma",5)) {c = 211; begin+= 5;}          else if (!strncmp(begin,"Tau",3)) {c = 212; begin+= 3;}          else if (!strncmp(begin,"Upsilon",7)) {c = 213; begin+= 7;}          else if (!strncmp(begin,"Phi",3)) {c = 214; begin+= 3;}          else if (!strncmp(begin,"Chi",3)) {c = 215; begin+= 3;}          else if (!strncmp(begin,"Psi",3)) {c = 216; begin+= 3;}          else if (!strncmp(begin,"Omega",5)) {c = 217; begin+= 5;}          else if (!strncmp(begin,"alpha",5)) {c = 225; begin+= 5;}          else if (!strncmp(begin,"beta",4)) {c = 226; begin+= 4;}          else if (!strncmp(begin,"gamma",5)) {c = 227; begin+= 5;}          else if (!strncmp(begin,"delta",5)) {c = 228; begin+= 5;}          else if (!strncmp(begin,"epsilon",7)) {c = 229; begin+= 7;}          else if (!strncmp(begin,"zeta",4)) {c = 230; begin+= 4;}          else if (!strncmp(begin,"eta",3)) {c = 231; begin+= 3;}          else if (!strncmp(begin,"theta",5)) {c = 232; begin+= 5;}          else if (!strncmp(begin,"iota",4)) {c = 233; begin+= 4;}          else if (!strncmp(begin,"kappa",5)) {c = 234; begin+= 5;}          else if (!strncmp(begin,"lambda",6)) {c = 235; begin+= 6;}          else if (!strncmp(begin,"mu",2)) {c = 236; begin+= 2;}          else if (!strncmp(begin,"nu",2)) {c = 237; begin+= 2;}          else if (!strncmp(begin,"xi",2)) {c = 238; begin+= 2;}          else if (!strncmp(begin,"omicron",7)) {c = 239; begin+= 7;}          else if (!strncmp(begin,"pi",2)) {c = 240; begin+= 2;}          else if (!strncmp(begin,"rho",3)) {c = 241; begin+= 3;}          else if (!strncmp(begin,"sigma",5)) {c = 243; begin+= 5;}          else if (!strncmp(begin,"tau",3)) {c = 244; begin+= 3;}          else if (!strncmp(begin,"upsilon",7)) {c = 245; begin+= 7;}          else if (!strncmp(begin,"phi",3)) {c = 246; begin+= 3;}          else if (!strncmp(begin,"chi",3)) {c = 247; begin+= 3;}          else if (!strncmp(begin,"psi",3)) {c = 248; begin+= 3;}          else if (!strncmp(begin,"omega",5)) {c = 249; begin+= 5;}            else  {*left = begin; SetErrorf("Bad Greek character"); return(0);}            begin--;                      break;        default : Clean(*resVC); *left = begin; SetErrorf("Bad Escaped character"); return(0);        }        break;             default :        c = *begin;        break;      }            if (flagStop) break;                            *str1 = c;      n++;      if (n>=MaxStrLength) {        Clean(*resVC);        Errorf("TermExpr() : Sorry, string is too long, Max length is %d",MaxStrLength);      }      str1++;      begin++;    }        if (*begin != '\'' && *begin != '\"') {      Clean(*resVC);      SetErrorf("Can't find the corresponding quote %c ",quote);      return(0);    }    *str1 = '\0';            Clean(*resVC);    *resVC = (VALUE) NewStrValue();    TempValue( *resVC);    SetStrValue((STRVALUE) *resVC,str);    begin++;    ParamSkipSpace(begin);    *left = begin;     answer=StringType;  }         /************************************   *   * Test the listv {}   *   ************************************/   else if (*begin == '{') {    if (!(flagType & ListvType)) {      Clean(*resVC);      SetErrorf("Do not expect a listv");      return(0);    }    if (begin[1] == '}') {      *resVC = (VALUE) TNewListv();      *left = begin+2;      ParamSkipSpace(*left);      answer = ListvType;    }    else {          oldFlagSpace = defParam->flagSpace;      defParam->flagSpace = NO;          lv = TNewListv();      begin++;           while (1) {        Clean(*resVC);        r = TTExpr1(begin,left,resFlt,resVC,defParam->listvElemType,defParam);        if (r == 0) return(0);        begin = *left;        while (*begin == ' ' || *begin == '\t' || *begin == '\n' || *begin == '\r') begin++;        if (*begin == '}') {          *left = begin+1;          if (r==FloatType) AppendFloat2Listv(lv,*resFlt);          else AppendValue2Listv(lv,*resVC);          *resVC = (VALUE) lv;          defParam->flagSpace = oldFlagSpace;          ParamSkipSpace(*left);          answer = ListvType;          break;        }        if (begin == *left) {                Clean(*resVC);          SetErrorf("Expecting '}', i.e., the end of the listv");          return(0);        }        if (r==FloatType) AppendFloat2Listv(lv,*resFlt);        else AppendValue2Listv(lv,*resVC);        *left = begin;      }    }      }   /************************************   *   * Test the constants   *   ************************************/  /* @<, @> and @+ */     else if (!strncmp(begin,"@<",2) || !strncmp(begin,"@>",2) || !strncmp(begin,"@+",2)) {    if (!(flagType & FloatType)) {      SetErrorf("Not expecting a number");      Clean(*resVC);      return(0);    }    if (NoDefaultVector(defParam)) {      if (NoDefaultSig(defParam)) {        if (begin[1] != '>') SetErrorf("Cannot infer range parameter '@>'");        else if (begin[1] != '>') SetErrorf("Cannot infer range parameter '@>'");        else SetErrorf("Cannot infer range parameter '@+'");        Clean(*resVC);        *left = begin;        return(0);      }      if (begin[1] == '<') *resFlt = DefaultSigX0(defParam);      else if (begin[1] == '+') *resFlt = DefaultSigDx(defParam);      else *resFlt = DefaultSigSize(defParam);    }    else {      if (begin[1] == '<') *resFlt = DefaultVMin(defParam);      else if (begin[1] == '>') *resFlt = DefaultVMax(defParam);      else *resFlt = DefaultVDx(defParam);    }    *left = begin+2;    ParamSkipSpace(*left);    answer = FloatType;  }      /* pi */     else if (!strncmp(begin,"pi",2) && !IsValidSymbolChar1(begin[2]) && begin[2] != '.') {    if (!(flagType & FloatType)) {      SetErrorf("Not expecting a number");      Clean(*resVC);      return(0);    }    (*left) = begin+2;    *resFlt = M_PI;    ParamSkipSpace(*left);    return(FloatType);  }      /* urand */     else if (!strncmp(begin,"urand",5) && !IsValidSymbolChar1(begin[5]) && begin[5] != '.') {    if (!(flagType & FloatType)) {      SetErrorf("Not expecting a number");      Clean(*resVC);      return(0);    }    (*left) = begin+5;    *resFlt = Urand();    ParamSkipSpace(*left);    return(FloatType);  }  /* grand */     else if (!strncmp(begin,"grand",5) && !IsValidSymbolChar1(begin[5]) && begin[5] != '.') {    if (!(flagType & FloatType)) {      SetErrorf("I am not expecting a number");      Clean(*resVC);      return(0);    }    (*left) = begin+5;    *resFlt = Grand(1);    ParamSkipSpace(*left);    return(FloatType);  }  /* null */     else if (!strncmp(begin,"null",4) && !IsValidSymbolChar1(begin[4]) && begin[4] != '.') {    if (!(flagType & NullType)) {      SetErrorf("I am not expecting 'null' value");      Clean(*resVC);      return(0);    }    (*left) = begin+4;    *resVC = nullValue;    ParamSkipSpace(*left);    return(NullType);  }  /************************************   *   * A LWFLOAT/signal/image <...>   *   ************************************/     else if (*begin == '<') {    begin1 = begin;    begin++;        ds = NoDefaultSig(defParam);    di = NoDefaultIm(defParam);   /* test for empty signal */    if (*begin == '>') {      if (flagType & SignalType && (defParam->flagEmptySI || begin[1] == '.')) {        *resVC = (VALUE) TNewSignal();         answer = SignalType;        *left = begin+1;      }      else if (defParam->flagEmptySI) {        SetErrorf("Do not expect a signal");        Clean(*resVC);        *left = begin1;        return(0);      }      else {        SetErrorf("Do not expect an empty signal");        Clean(*resVC);        *left = begin1;        return(0);      }          }    /* test for empty image */    else if (begin[0] == ';' && begin[1] == '>' ) {      if (flagType & ImageType  && (defParam->flagEmptySI  || begin[1] == '.')) {        *resVC = (VALUE) TNewImage();         answer = ImageType;        *left = begin+2;      }      else if (defParam->flagEmptySI) {        SetErrorf("Do not expect an image");        Clean(*resVC);        *left = begin1;        return(0);      }      else {        SetErrorf("Do not expect an empty image");        Clean(*resVC);        *left = begin1;        return(0);      }          }    else {          /*      oldFlagSpace = defParam->flagSpace;      defParam->flagSpace = YES; deconne pour {<0,0> <0,0>} */      list = SFIListExpr(begin,left, NULL,defParam); /*      defParam->flagSpace = oldFlagSpace; */           if (list == NULL) {        Clean(*resVC);        return(0);      }      if ((**left)!='>') {        SetErrorf("Expecting a bracket '>'"); 

⌨️ 快捷键说明

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