Tasks of Aspect-Based Sentiment Analysis (ABSA) are receiving increasing attention from people. An ABSA method based on code generation was proposed to address the limitations of current mainstream ABSA methods that cannot fully utilize semantic relationships and learn connections among various emotional elements. Firstly, each emotional element was correspond to the Programming Language (PL). Secondly, the experimental dataset was constructed into data patterns of code generation task which can better express relationships among various emotional elements according to the principle of correspondence. Finally, the powerful performance of current Large Language Models (LLMs) and the excellent performance of code generation methods were utilized in event extraction tasks to obtain more accurate results. To verify the effectiveness of the proposed method, comparison experiments were conducted using Paraphrase, Seq2Path, and Opinion Tree Generation (OTG) methods. Experimental results show that the proposed method achieves F1 score improvement of 2.82 percentage points compared to OTG method on the restaurant dataset in ABSA tasks, which meaning better results.