📄 interp_read.cc
字号:
} else if(CMP("continue")) { block->o_type = O_continue; } else if(CMP("endwhile")) { block->o_type = O_endwhile; } else if(CMP("return")) { block->o_type = O_return; } else { // not legal block->o_type = O_none; ERP(NCE_UNKNOWN_COMMAND_IN_O_LINE); } return INTERP_OK;}/****************************************************************************//*! read_pReturned 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 INTERP_OK. 1. The first character read is not p: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. A p value has already been inserted in the block: NCE_MULTIPLE_P_WORDS_ON_ONE_LINE 3. The p value is negative: NCE_NEGATIVE_P_WORD_USEDSide 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 'p', indicating a p valuesetting. The function reads characters which tell how to set the pvalue, up to the start of the next item or the end of the line. Thisinformation is inserted in the block.P codes are used for:1. Dwell time in canned cycles g82, G86, G88, G89 [NCMS pages 98 - 100].2. A key with G10 [NCMS, pages 9, 10].*/int Interp::read_p(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_p"; double value; int status; CHK((line[*counter] != 'p'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHK((block->p_number > -1.0), NCE_MULTIPLE_P_WORDS_ON_ONE_LINE); CHP(read_real_value(line, counter, &value, parameters)); // FMP removed check for negatives, since we may want them for // user-defined codes // CHK((value < 0.0), NCE_NEGATIVE_P_WORD_USED); block->p_number = value; return INTERP_OK;}/****************************************************************************//*! read_parameterReturned Value: int If read_integer_value returns an error code, this returns that code. If any of the following errors occur, this returns the error code shown. Otherwise, this returns INTERP_OK. 1. The first character read is not # : NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. The parameter number is out of bounds: NCE_PARAMETER_NUMBER_OUT_OF_RANGESide effects: The value of the given parameter is put into what double_ptr points at. The counter is reset to point to the first character after the characters which make up the value.Called by: read_real_valueThis attempts to read the value of a parameter out of the line,starting at the index given by the counter.According to the RS274/NGC manual [NCMS, p. 62], the characters following# may be any "parameter expression". Thus, the following are legaland mean the same thing (the value of the parameter whose number isstored in parameter 2): ##2 #[#2]Parameter setting is done in parallel, not sequentially. For exampleif #1 is 5 before the line "#1=10 #2=#1" is read, then after the lineis is executed, #1 is 10 and #2 is 5. If parameter setting were donesequentially, the value of #2 would be 10 after the line was executed.*/int Interp::read_parameter(char *line, //!< string: line of RS274/NGC code being processed int *counter, //!< pointer to a counter for position on the line double *double_ptr, //!< pointer to double to be read double *parameters) //!< array of system parameters { static char name[] = "read_parameter"; int index; int status; CHK((line[*counter] != '#'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHP(read_integer_value(line, counter, &index, parameters)); CHK(((index < 1) || (index >= RS274NGC_MAX_PARAMETERS)), NCE_PARAMETER_NUMBER_OUT_OF_RANGE); *double_ptr = parameters[index]; return INTERP_OK;}/****************************************************************************//*! read_parameter_settingReturned Value: int If read_real_value or read_integer_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 INTERP_OK. 1. The first character read is not # : NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. The parameter index is out of range: PARAMETER_NUMBER_OUT_OF_RANGE 3. An equal sign does not follow the parameter expression: NCE_EQUAL_SIGN_MISSING_IN_PARAMETER_SETTINGSide effects: counter is reset to the character following the end of the parameter setting. The parameter whose index follows "#" is set to the real value following "=".Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character '#', indicating a parametersetting when found by read_one_item. The function reads characterswhich tell how to set the parameter.Any number of parameters may be set on a line. If parameters set earlyon the line are used in expressions farther down the line, theparameters have their old values, not their new values. This isusually called setting parameters in parallel.Parameter setting is not clearly described in [NCMS, pp. 51 - 62]: it isnot clear if more than one parameter setting per line is allowed (anynumber is OK in this implementation). The characters immediately followingthe "#" must constitute a "parameter expression", but it is not clearwhat that is. Here we allow any expression as long as it evaluates toan integer.Parameters are handled in the interpreter by having a parameter tableand a parameter buffer as part of the machine settings. The parametertable is passed to the reading functions which need it. The parameterbuffer is used directly by functions that need it. Reading functionsmay set parameter values in the parameter buffer. Reading functionsmay obtain parameter values; these come from parameter table.The parameter buffer has three parts: (i) a counter for how manyparameters have been set while reading the current line (ii) an arrayof the indexes of parameters that have been set while reading thecurrent line, and (iii) an array of the values for the parameters thathave been set while reading the current line; the nth valuecorresponds to the nth index. Any given index will appear once in theindex number array for each time the parameter with that index is seton a line. There is no point in setting the same parameter more thanone on a line because only the last setting of that parameter willtake effect.The syntax recognized by this this function is # followed by aninteger expression (explicit integer or expression evaluating to aninteger) followed by = followed by a real value (number orexpression).Note that # also starts a bunch of characters which represent a parameterto be evaluated. That situation is handled by read_parameter.*/int Interp::read_parameter_setting(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_parameter_setting"; int index; double value; int status; CHK((line[*counter] != '#'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHP(read_integer_value(line, counter, &index, parameters)); CHK(((index < 1) || (index >= RS274NGC_MAX_PARAMETERS)), NCE_PARAMETER_NUMBER_OUT_OF_RANGE); CHK((line[*counter] != '='), NCE_EQUAL_SIGN_MISSING_IN_PARAMETER_SETTING); *counter = (*counter + 1); CHP(read_real_value(line, counter, &value, parameters)); _setup.parameter_numbers[_setup.parameter_occurrence] = index; _setup.parameter_values[_setup.parameter_occurrence] = value; _setup.parameter_occurrence++; return INTERP_OK;}/****************************************************************************//*! read_qReturned 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 INTERP_OK. 1. The first character read is not q: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. A q value has already been inserted in the block: NCE_MULTIPLE_Q_WORDS_ON_ONE_LINE 3. The q value is negative or zero: NCE_NEGATIVE_OR_ZERO_Q_VALUE_USEDSide effects: counter is reset to point to the first character following the q value. The q 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 'q', indicating a q valuesetting. The function reads characters which tell how to set the qvalue, up to the start of the next item or the end of the line. Thisinformation is inserted in the block.Q is used only in the G87 canned cycle [NCMS, page 98], where it mustbe positive.*/int Interp::read_q(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_q"; double value; int status; CHK((line[*counter] != 'q'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHK((block->q_number > -1.0), NCE_MULTIPLE_Q_WORDS_ON_ONE_LINE); CHP(read_real_value(line, counter, &value, parameters)); // FMP removed check for negatives, since we may want them for // user-defined codes // CHK((value <= 0.0), NCE_NEGATIVE_OR_ZERO_Q_VALUE_USED); block->q_number = value; return INTERP_OK;}/****************************************************************************//*! read_rReturned 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 INTERP_OK. 1. The first character read is not r: NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 2. An r_number has already been inserted in the block: NCE_MULTIPLE_R_WORDS_ON_ONE_LINESide effects: counter is reset. The r_flag in the block is turned on. The r_number is inserted in the block.Called by: read_one_itemWhen this function is called, counter is pointing at an item on theline that starts with the character 'r'. The function reads characterswhich tell how to set the coordinate, up to the start of the next itemor the end of the line. This information is inserted in the block. Thecounter is then set to point to the character following.An r number indicates the clearance plane in canned cycles.An r number may also be the radius of an arc.The value may be a real number or something that evaluates to areal number, so read_real_value is used to read it. Parametersmay be involved.*/int Interp::read_r(char *line, //!< string: line of RS274 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_r"; double value; int status; CHK((line[*counter] != 'r'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED); *counter = (*counter + 1); CHK((block->r_flag != OFF), NCE_MULTIPLE_R_WORDS_ON_ONE_LINE); CHP(read_real_value(line, counter, &value, parameters)); block->r_flag = ON; block->r_number = value; return INTERP_OK;}/****************************************************************************//*! read_real_expressionReturned Value: int If any of the following functions returns an error code, this returns that code. read_real_value read_operation execute_binary If any of the following errors occur, this returns the error shown. Otherwise, it returns INTERP_OK. 1. The first character is not [ : NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLEDSide effects: The number read from the line is put into what value_ptr points at. The counter is reset to point to the first character after the real expression.Called by: read_atan read_real_value read_unaryExample 1: [2 - 3 * 4 / 5] means [2 - [[3 * 4] / 5]] and equals -0.4.Segmenting Expressions -The RS274/NGC manual, section 3.5.1.1 [NCMS, page 50], provides forusing square brackets to segment expressions.Binary Operations -The RS274/NGC manual, section 3.5.1.1, discusses expression evaluation.The manual provides for eight binary operations: the four basicmathematical operations (addition, subtraction, multiplication,division), three logical operations (non-exclusive ||, exclusive ||,and AND2) and the modulus operation. The manual does not explicitly callthese "binary" operations, but implicitly recognizes that they arebinary. We hav
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -