Interpreter inheritance
The inheritance mechanism is intended for reusing already developed interpreters to translate and interpret NC programs with a similar but different syntax. How much an NC program must differ from the original one to justify a descendant rather than a new interpreter is up to the developer.
The purpose of a descendant interpreter is to translate and interpret the differences in the NC program and to pass control to the parent interpreter for translating and interpreting the similar parts of the NC program text.
A descendant interpreter is implemented differently from an ordinary interpreter in the following:
- The ParentID and ParentFileName fields are filled in the interpreter settings file (SNCI).
- If necessary, existing registers are overridden or new ones are added. This can be done by adding the changes to the list of registers of the SNCI file or to the list of registers returned by the INCT_Interpreter.GetRegisters function of the descendant interpreter library.
- The descendant interpreter library is implemented. In the library, the descendant calls or does not call the functions and methods of the parent interpreter library, depending on the algorithms it uses to translate and interpret the NC program text. The parent interpreter interface (INCT_Interpreter) is passed to the descendant during initialization.
An interpreter can inherit from only one parent. The number of descendant interpreters of one parent and the depth of inheritance are not limited.
An interpreter with its own parameters (its object implements the INCT_CustomInterpreter interface; see List of used types) cannot be a parent: the CAM system stops loading the descendant with an error.
Register inheritance.
The registers of descendant interpreters override the registers of parent interpreters. Register inheritance is implemented so that the resulting list (the list of base registers) is filled in the following order:
- The list of registers is loaded from the settings file of the descendant interpreter.
- The list of registers is loaded from the library of the descendant interpreter (INCT_Interpreter.GetRegisters). If a register with the same name already exists in the list of base registers, it is not loaded.
- The list of registers is loaded from the settings file of the parent interpreter. If a register with the same name already exists in the list of base registers, it is not loaded.
- The list of registers is loaded from the library of the parent interpreter. If a register with the same name already exists in the list of base registers, it is not loaded.
- The list of registers is loaded from the settings file of the parent of the parent interpreter. If a register with the same name already exists in the list of base registers, it is not loaded.
- The list of registers is loaded from the library of the parent of the parent interpreter. If a register with the same name already exists in the list of base registers, it is not loaded.
- And so on, up to the very first parent.
Library inheritance.
When the parent interpreter library is initialized, a number of methods and functions are called by the CAM system kernel, so the descendant does not need to call them:
- INCT_Interpreter.GetIdentifier.
- INCT_Interpreter.GetRegisters.
- INCT_Interpreter.SetInterface.
- INCT_Interpreter.Initialize.
The descendant calls or does not call the other functions and methods of the parent interpreter library, depending on the algorithms it uses to translate and interpret the NC program text. To let the descendant call the parent methods, the parent interpreter interface is passed to it, among others, when the descendant interpreter library is initialized (the INCT_Interpreter.SetInterface function).
Below are recommendations for calling the functions and methods of the parent interpreter from a descendant interpreter.
- INCT_Interpreter.TransLine - call the parent TransLine if analyzing the NC program line did not shorten the original line. Pass all the parameters returned by the parent method (ProcessedChars, NextLine, BreakLine) to the output parameters of the descendant method.
- INCT_Interpreter.DefineRegister - call the parent DefineRegister if the descendant has not determined the register by its address. Pass the Index parameter and the result returned by the parent function to the output parameter and the result of the descendant function.
- INCT_Interpreter.BeforeInterprete - always call the parent BeforeInterprete.
- INCT_Interpreter.Interprete - call the parent Interprete if the descendant does not interpret the object to interpret.
- INCT_Interpreter.AfterInterprete - always call the parent AfterInterprete.
- INCT_Interpreter.EndOfProgram - always call the parent EndOfProgram if the descendant has not determined the end of the NC program. Return the result of the parent function as the result of the descendant function.
- INCT_Interpreter.NextOperation - the CAM system calls NextOperation only for the descendant, at the start of interpreting the next operation. Always call the parent NextOperation.
The page Examples of interpreters with source codes gives an example of the source code of a descendant interpreter library, the 'dll' built from it, and an example of the settings file.