In order to solve the problem of “testable results but difficult to describe semantics” in automatic scoring of data structure course, this paper constructs a method for semantic understanding and automatic scoring of program code based on Transformer architecture. In this study, student submitted code, problem constraints, test results and structural features are integrated into the unified processing flow. Through code preprocessing, semantic coding, reference semantic alignment and multidimensional score aggregation, the joint evaluation of program correctness, implementation quality and structural rationality is realized. In the system design, a test set organization mechanism and a scoring feedback link for data structure questions are established, so that the automatic evaluation is no longer limited to input-output comparison, but can further identify the implementation differences in typical tasks such as linked lists, trees, and graphs. The experimental results based on 1184 valid program samples show that the Accuracy of the proposed method reaches 0.907, Macro-F1 is 0.889, QWK is 0.926, and RMSE is reduced to 3.84. The overall performance is better than that of rule scoring and multiple comparison models. The research shows that the introduction of Transformer code semantic modeling into the course evaluation process can effectively improve the accuracy, stability and teaching adaptability of automatic scoring.