Algorithm for determining the register and values in the G-code block
At the stage of recognition of NC code frame, the SprutCAM X core operates with lexemes — sequences of valid language symbols that make sense to the translator.
Algorithm for determining the register and value:
To determine the register, the kernel reads the token from the line of the G-code (the order of reading the token is given below).
If the token is not a register, then the algorithm is terminated. The lexeme received from the text of the G-code will be considered processed and unrecognized.
If the token is a register with no value (i.e. the INCT_Register.ValueAvail register field is vatOnlyAddr), then the algorithm is terminated. The lexeme received from the NC code will be considered processed, the register is defined.
Otherwise, the kernel reads the tokens sequentially, expecting to meet a number (signed or not) or '=' characters (if allowed by the INCT_Analyzer.CanUseEqualToAssignRegister setting) and brackets (if the options for the brackets used are specified in the INCT_Analyzer.Brackets setting). Reading tokens is performed until the kernel determines the value of the register or encounters an invalid token. In both cases, the algorithm is completed, the tokens will be considered as processed. In the first case: successfully - the register is found, the value is determined. In the second: unsuccessfully - tokens are considered unrecognized.
The tokens reading order:
The first character of the string is read from the G-code;
If the character is a number or a dot, it is considered that the token to be read is a number, then characters are read from the text of the G-code as long as they are numbers. Reading tokens completed successfully;
If the character is in the list: '+', '-', '=', ','. A token consists of one character, its reading is completed successfully.
If the character is a quotation mark (i.e. it is included in the INCT_Analyzer.Quotes list), then the kernel searches for the second quotation mark in the current G-code frame. When it is found, it considers the token as string, the reading of which is completed successfully. If the second quote is not found, all the text to the end of the frame is considered processed, and the reading of the token is considered unsuccessful.
If the character is the first comment character (i.e., included in the INCT_Analyzer.Comments list), then the kernel looks for a closing comment character. When it is found, it considers the token as comment, the reading of which is completed successfully. If the closing character is not found, all the text to the end of the frame is considered processed and unrecognized, and the reading of the token is considered unsuccessful.
f the character is a lowercase or uppercase letter of the Latin alphabet, then the kernel will try to determine the register. The algorithm for reading the following characters from the control program frame is affected by the following settings: INCT_Analyzer.RegistersContainSpaces (register can contain spaces), INCT_Analyzer.RegistersCanEndWithPlusOrMinus (register may end with '+' or '-'), INCT_Analyzer.RegistersCanEndWithNumber (register may end with numbers). The kernel tries to recognize the token by reading characters from the frame sequentially, taking into account the settings. Reading continues until the kernel encounters a symbol that does not match the settings template or the G-code frame is completed. The resulting character set is sent to the interpreter to determine the register (INCT_Interpreter.DefineRegister function). If the interpreter returns a negative response (the register is not defined), the kernel looks for the register in the resulting list of registers (base) for the field Address. If the register is found in the list or at the previous step, the interpreter returned a positive response (the register was found), then the token is considered defined - this is the register. The reading of the token was successful; otherwise, the read characters are considered to be processed, and the reading of the token is considered unsuccessful.
Note.
When implementing the function (INCT_Interpreter.DefineRegister), it is recommended to search for only those registers that cannot be uniquely identified by the SprutCAM X kernel. In other cases, the search does not perform, return a negative result.