Algorithm for determining the register and values in the G-code block
At the stage of recognizing a block of the NC program text, the CAM system kernel operates with tokens — sequences of valid characters of the language that make sense to the translator.
Algorithm for determining the register and value:
- To determine a register, the kernel reads a token from the NC program line (the order of reading a token is given below).
- If the token is not a register, the algorithm ends. The token read from the NC program text is considered processed and unrecognized.
- If the token is a register without a value (i.e. the INCT_Register.Get_ValueAvail function of the register returns vatOnlyAddr), the algorithm ends. The token read from the NC program text is considered processed, the register is determined.
- Otherwise the kernel reads tokens one after another, expecting to meet a number (signed or unsigned), or the '=' character (if it is allowed by the INCT_Analyzer.CanUseEqualToAssignRegister setting) followed by a number or a string in quotes. Brackets (the INCT_Analyzer.Brackets setting) are not used when determining the register value. Tokens are read until the kernel determines the register value or meets an invalid token. In both cases the algorithm ends and the tokens are considered processed. In the first case it ends successfully — the register is found, the value is determined. In the second case it ends unsuccessfully — the tokens are considered unrecognized.
Order of reading a token:
- The first character of the line is read from the NC program text;
- If the character is a digit or a dot, the token being read is considered a number, and then characters are read from the NC program text as long as they are digits. Reading of the token is completed successfully;
- If the character is one of the list: '+', '-', '=', ',' (and, when the INCT_Analyzer.CanUseEqualToAssignRegister setting is on, one of the brackets specified in the INCT_Analyzer.Brackets setting), the token is considered to consist of one character. Reading of the token is completed successfully.
- If the character is a quotation mark (i.e. it is included in the INCT_Analyzer.Quotes list), the kernel searches for the second quotation mark in the current NC program block. If it is found, the token is considered a string, and reading of it is completed successfully. If the second quotation mark is not found, all the text up to the end of the block is considered processed, and reading of the token is considered unsuccessful.
- If the character is the first character of a comment (i.e. it is included in the INCT_Analyzer.Comments list), the kernel searches for the closing character of the comment. If it is found, the token is considered a comment, and reading of it is completed successfully. If the closing character is not found, all the text up to the end of the block is considered processed and unrecognized, and reading of the token is considered unsuccessful.
- If the character is a lowercase or uppercase letter of the Latin alphabet, the kernel tries to determine a register. The kernel reads consecutive letters. If the formed (base) list of registers contains compound addresses (for example, 'TOOL CALL', 'DL+', 'DR2'), the kernel continues reading the next parts of the block (letters, digits, '+' or '-', spaces) while they match the parts of these addresses. The INCT_Analyzer.RegistersContainSpaces, INCT_Analyzer.RegistersCanEndWithPlusOrMinus and INCT_Analyzer.RegistersCanEndWithNumber settings are obsolete and do not affect reading of the token. The resulting set of characters is passed to the interpreter to determine the register (the INCT_Interpreter.DefineRegister function). If the interpreter returns a negative answer (the register is not determined), the kernel searches for the register in the formed (base) list of registers by the "Address" field. If the register is found in the list, or the interpreter returned a positive answer at the previous step (the register is found), the token is considered determined — it is a register, and reading of the token is completed successfully. Otherwise the read characters are considered processed, and reading of the token is considered unsuccessful.
Note.
When implementing the function (INCT_Interpreter.DefineRegister), it is recommended to search only for those registers that the CAM system kernel cannot determine unambiguously. In other cases do not search and return a negative result.