EtherCAT is a high performance fieldbus protocol and has become one of the major protocols in motion control. This paper presents a study of machine tool CNC program compiler theory to facilitate the development of CNC machine tools. To validate the accuracy of the method, input digital controls are set to be the same as these made by CNC program. In this study, a compiler system is developed according to the method of hybrid compiler. The compiler system analyzes CNC programs according the order of lexical analysis, syntax analysis and semantic analysis and to generates intermediate code. In the last phase of the compiler system, intermediate code is interpreted to motion control code.