With the constant development of numerical control technology, the development cycle and efficiency of CNC (computer numerical control) system is restricted with NC code compiler insufficient in Rapid Development and efficiency. In order to solve this problem, a compiler developed with Lex&Yacc for CNC system based on PC is put forward. This compiler is consisted of a lexical analysis module, a syntax analysis module and an object-storage module. With designed in modules, parameter-driven programming and assisted by Lex&Yacc which is an efficient language for compiler development, this compiler has great advantages such as high efficiency and short development cycle, which mean realistic significance to engineering application. The main principal and design process of every module was expatiated and at last a test of compiling a NC file was executed successfully, which verified the validity of this proposed method.