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

📄 interp_read.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 5 页
字号:
int Interp::read_operation(char *line,   //!< string: line of RS274/NGC code being processed                          int *counter, //!< pointer to a counter for position on the line                           int *operation)       //!< pointer to operation to be read               {  static char name[] = "read_operation";  char c;  c = line[*counter];  *counter = (*counter + 1);  switch (c) {  case '+':    *operation = PLUS;    break;  case '-':    *operation = MINUS;    break;  case '/':    *operation = DIVIDED_BY;    break;  case '*':    if (line[*counter] == '*') {      *operation = POWER;      *counter = (*counter + 1);    } else      *operation = TIMES;    break;  case ']':    *operation = RIGHT_BRACKET;    break;  case 'a':    if ((line[*counter] == 'n') && (line[(*counter) + 1] == 'd')) {      *operation = AND2;      *counter = (*counter + 2);    } else      ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_A);    break;  case 'm':    if ((line[*counter] == 'o') && (line[(*counter) + 1] == 'd')) {      *operation = MODULO;      *counter = (*counter + 2);    } else      ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_M);    break;  case 'o':    if (line[*counter] == 'r') {      *operation = NON_EXCLUSIVE_OR;      *counter = (*counter + 1);    } else      ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_O);    break;  case 'x':    if ((line[*counter] == 'o') && (line[(*counter) + 1] == 'r')) {      *operation = EXCLUSIVE_OR;      *counter = (*counter + 2);    } else      ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_X);    break;      /* relational operators */    case 'e':      if(line[*counter] == 'q')	{	  *operation = EQ;	  *counter = (*counter + 1);	}      else        ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_E);      break;    case 'n':      if(line[*counter] == 'e')	{	  *operation = NE;	  *counter = (*counter + 1);	}      else        ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_N);      break;    case 'g':      if(line[*counter] == 'e')	{	  *operation = GE;	  *counter = (*counter + 1);	}      else if(line[*counter] == 't')	{	  *operation = GT;	  *counter = (*counter + 1);	}      else        ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_G);      break;    case 'l':      if(line[*counter] == 'e')	{	  *operation = LE;	  *counter = (*counter + 1);	}      else if(line[*counter] == 't')	{	  *operation = LT;	  *counter = (*counter + 1);	}      else        ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_L);      break;  case 0:    ERM(NCE_UNCLOSED_EXPRESSION);  default:    ERM(NCE_UNKNOWN_OPERATION);  }  return INTERP_OK;}/****************************************************************************//*! read_operation_unaryReturned Value: int   If the operation is not a known unary operation, this returns one of   the following error codes:   NCE_UNKNOWN_WORD_STARTING_WITH_A   NCE_UNKNOWN_WORD_STARTING_WITH_C   NCE_UNKNOWN_WORD_STARTING_WITH_E   NCE_UNKNOWN_WORD_STARTING_WITH_F   NCE_UNKNOWN_WORD_STARTING_WITH_L   NCE_UNKNOWN_WORD_STARTING_WITH_R   NCE_UNKNOWN_WORD_STARTING_WITH_S   NCE_UNKNOWN_WORD_STARTING_WITH_T   NCE_UNKNOWN_WORD_WHERE_UNARY_OPERATION_COULD_BE   Otherwise, this returns INTERP_OK.Side effects:   An integer code for the name of the operation read from the   line is put into what operation points at.   The counter is reset to point to the first character after the   characters which make up the operation name.Called by:   read_unaryThis attempts to read the name of a unary operation out of the line,starting at the index given by the counter. Known operations are:abs, acos, asin, atan, cos, exp, fix, fup, ln, round, sin, sqrt, tan.*/int Interp::read_operation_unary(char *line,     //!< string: line of RS274/NGC code being processed                                int *counter,   //!< pointer to a counter for position on the line                                 int *operation) //!< pointer to operation to be read               {  static char name[] = "read_operation_unary";  char c;  c = line[*counter];  *counter = (*counter + 1);  switch (c) {  case 'a':    if ((line[*counter] == 'b') && (line[(*counter) + 1] == 's')) {      *operation = ABS;      *counter = (*counter + 2);    } else if (strncmp((line + *counter), "cos", 3) == 0) {      *operation = ACOS;      *counter = (*counter + 3);    } else if (strncmp((line + *counter), "sin", 3) == 0) {      *operation = ASIN;      *counter = (*counter + 3);    } else if (strncmp((line + *counter), "tan", 3) == 0) {      *operation = ATAN;      *counter = (*counter + 3);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_A);    break;  case 'c':    if ((line[*counter] == 'o') && (line[(*counter) + 1] == 's')) {      *operation = COS;      *counter = (*counter + 2);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_C);    break;  case 'e':    if ((line[*counter] == 'x') && (line[(*counter) + 1] == 'p')) {      *operation = EXP;      *counter = (*counter + 2);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_E);    break;  case 'f':    if ((line[*counter] == 'i') && (line[(*counter) + 1] == 'x')) {      *operation = FIX;      *counter = (*counter + 2);    } else if ((line[*counter] == 'u') && (line[(*counter) + 1] == 'p')) {      *operation = FUP;      *counter = (*counter + 2);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_F);    break;  case 'l':    if (line[*counter] == 'n') {      *operation = LN;      *counter = (*counter + 1);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_L);    break;  case 'r':    if (strncmp((line + *counter), "ound", 4) == 0) {      *operation = ROUND;      *counter = (*counter + 4);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_R);    break;  case 's':    if ((line[*counter] == 'i') && (line[(*counter) + 1] == 'n')) {      *operation = SIN;      *counter = (*counter + 2);    } else if (strncmp((line + *counter), "qrt", 3) == 0) {      *operation = SQRT;      *counter = (*counter + 3);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_S);    break;  case 't':    if ((line[*counter] == 'a') && (line[(*counter) + 1] == 'n')) {      *operation = TAN;      *counter = (*counter + 2);    } else      ERM(NCE_UNKNOWN_WORD_STARTING_WITH_T);    break;  default:    ERM(NCE_UNKNOWN_WORD_WHERE_UNARY_OPERATION_COULD_BE);  }  return INTERP_OK;}/****************************************************************************//* read_oReturned Value: int   If read_real_value returns an error code, this returns that code.   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns RS274NGC_OK.   1. The first character read is not o:      NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLEDSide effects:   counter is reset to point to the first character following the p value.   The p value setting is inserted in block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'o', indicating a o valuesetting. The function reads characters which tell how to set the ovalue, up to the start of the next item or the end of the line. Thisinformation is inserted in the block.O codes are used for:1.  sub2.  endsub3.  call4.  do5.  while6.  if7.  elseif8.  else9.  endif10. break11. continue12. endwhile13. return*/int Interp::read_o(    /* ARGUMENTS                                     */ char * line,         /* string: line of RS274/NGC code being processed */ int * counter,       /* pointer to a counter for position on the line  */ block_pointer block, /* pointer to a block being filled from the line  */ double * parameters) /* array of system parameters                     */{  static char name[] = "read_o";  double value;  int status;  int param_cnt;  CHK((line[*counter] != 'o'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);  // changed spec so we now read an expression  // so... we can have a parameter contain a function pointer!  *counter += 1;  CHP(read_integer_value(line, counter, &(block->line_number), parameters));  logDebug("In: %s line:%d |%s|", name, block->line_number, line);  block->o_number = block->line_number;#define CMP(txt) (strncmp(line+*counter, txt, strlen(txt)) == 0)  if(CMP("sub"))    {      block->o_type = O_sub;    }  else if(CMP("endsub"))    {      block->o_type = O_endsub;    }  else if(_setup.defining_sub == 1)    {      // we can not evaluate expressions -- so just skip on out      block->o_type = O_none;    }  else if(CMP("call"))    {      *counter += strlen("call");      block->o_type = O_call;      for(param_cnt=0;line[*counter] == '[';param_cnt++)	{	  logDebug("counter[%d] rest of line:|%s|", *counter,		   line+*counter);	  CHK((param_cnt >= INTERP_SUB_PARAMS),	      NCE_TOO_MANY_SUBROUTINE_PARAMETERS);	  CHP(read_real_expression(line, counter, &value, parameters));	  block->params[param_cnt] = value;	}      logDebug("set arg params:%d", param_cnt);      // zero the remaining params      for(;param_cnt < INTERP_SUB_PARAMS; param_cnt++)	{	  block->params[param_cnt] = 0.0;	}    }  else if(CMP("do"))    {      block->o_type = O_do;    }  else if(CMP("while"))    {      *counter += strlen("while");      block->o_type = O_while;      CHP(read_real_expression(line, counter, &value, parameters));      _setup.test_value = value;    }  else if(CMP("if"))    {      *counter += strlen("if");      block->o_type = O_if;      CHP(read_real_expression(line, counter, &value, parameters));      _setup.test_value = value;    }  else if(CMP("elseif"))    {      *counter += strlen("elseif");      block->o_type = O_elseif;      CHP(read_real_expression(line, counter, &value, parameters));      _setup.test_value = value;    }  else if(CMP("else"))    {      block->o_type = O_else;    }  else if(CMP("endif"))    {      block->o_type = O_endif;    }  else if(CMP("break"))    {      block->o_type = O_break;

⌨️ 快捷键说明

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