The invention discloses a method and a device for converting a universal code based on a macroprogram. The method comprises the following steps of: a, reading the current section of the current machining code backward, and converting the current section into internal unified data; b, acquiring a statement tree according to the internal unified data; c, judging whether the backward reading of the current macroprogram machining code is finished or not, if so, executing the step d, otherwise, executing the step a; and d, converting the statement tree into a target machining code according to a control parameter in a configuration file of a target numerical control machine. By the method and the device, code conversion time is saved, efficiency is improved, errors which easily occur in manual code conversion are avoided, and the qualification rate of a product is improved.