• 中国计算机学会会刊
  • 中国科技核心期刊
  • 中文核心期刊

Computer Engineering & Science ›› 2025, Vol. 47 ›› Issue (06): 1041-1049.

• Software Engineering • Previous Articles     Next Articles

MATLAB-to-Python code converter based on AST

GUO Rui1,XU Wenhao1,XIE Pengzhi2,YANG Wei2,SONG You1   

  1. (1.School of Software,Beihang University,Beijing 100191;
    2.AVIC Manufacturing Technology Institute,Beijing 100024,China)
  • Received:2024-04-01 Revised:2024-07-30 Online:2025-06-25 Published:2025-06-26

Abstract: MATLAB is widely used in various stages of industrial product development. However, in practical engineering applications, the mechanistic models built in MATLAB often need to be decoupled from the MATLAB runtime environment and integrated into real-world engineering systems. Thus, a tool  for rapidly converting MATLAB models into deployable engineering solutions is required. To address this, this paper proposes M2P (MATLAB-to-Python), a  converter based on abstract syntax tree (AST). The converter  involves transforming source code into an AST structure, analyzing it, and applying substitution rules to generate equivalent Python code. Comparative experiments demonstrate that the proposed converter  achieves superior conversion  performance compared to existing MATLAB-to-Python converters.

Key words: code conversion, MATLAB-to-Python, abstract syntax tree (AST)