Program language conversion method and device, equipment, storage medium and program product

By automatically converting Basic program code to Pascal program code, the problems of low efficiency and error-proneness of manual conversion are solved, achieving efficient and reliable program migration and improving the migration efficiency of industrial robot programs to standardized PLC control platforms.

CN121680862APending Publication Date: 2026-03-17MIDEA GRP (SHANGHAI) CO LTD +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511836095.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-05
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

In the existing technology, the conversion of Basic program code to Pascal program code mainly relies on manual work, which has problems such as low efficiency, easy error and difficulty in maintenance. Moreover, the conversion results of different engineers are inconsistent, resulting in low efficiency in migrating industrial robot programs to standardized PLC control platforms and chaotic version management.

Method used

This paper provides a programming language conversion method that converts Basic language variable definitions to Pascal language variable definitions, generates a target syntax tree structure, and generates state machine code based on the tree structure to achieve automatic conversion, ensuring that the data semantics are not distorted and improving conversion efficiency and reliability.

Benefits of technology

It enables automatic conversion of Basic program code to Pascal program code, improves the efficiency of migrating industrial robot programs to standardized PLC control platforms, avoids logical errors and data distortion in manual conversion, and shortens the project development and debugging cycle.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121680862A_ABST
    Figure CN121680862A_ABST
Patent Text Reader

Abstract

The invention provides a program language conversion method and device, computing equipment, a computer readable storage medium and a computer program product, and relates to the technical field of computer software, the method comprises the following steps: converting a variable definition in a to-be-converted program file written based on a first programming language into a variable definition about a second programming language; generating a target grammar structure tree according to the to-be-converted program file, wherein the target grammar structure tree is an abstract grammar tree which represents a grammar structure of the first programming language and carries semantics; based on the target grammar structure tree, generating a state machine code of a second programming language; and according to the variable definition related to the second programming language and the state machine code of the second programming language, generating a target program file related to the second programming language. According to the application, automatic conversion from the Basic program code to the Pascal program code can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer software technology, and more specifically, to a programming language conversion method, apparatus, computing device, computer-readable storage medium, and computer program product in the field of computer software technology. Background Technology

[0002] In the context of the rapid advancement of industry and intelligent manufacturing, achieving efficient collaboration between industrial robot control systems and programmable logic controller (PLC) systems has become crucial for the digital transformation of the manufacturing industry. Industrial robots generally employ the dedicated structured Basic language, with programs consisting of two files: .src and .dat. They support high-precision motion commands such as PTP (Point-to-Point), LIN (Linear), and CIRC (Circular), as well as E6POS (Extended 6-axis Position, six-degree-of-freedom pose data including position and orientation), FDAT (Frame Data, tool coordinate system / base coordinate system definition), PDAT (Point Motion Data, point-to-point motion parameters), and LDAT (Linear Motion). Basic programs use complex robot-specific data types such as `Data` (linear motion parameters) and possess rich control structures and industrial-specific instructions. PLC systems, on the other hand, widely adopt the Pascal language conforming to the international standard IEC 61131-3, based on strong typing, structured syntax, and function block calls (such as `Ind_MoveDirectAbsolute`), emphasizing program reliability and portability. Automatically converting Basic programs to Pascal not only helps break down technical barriers between heterogeneous systems, enabling unified development and integrated operation and maintenance, but also promotes the adoption of standardized and international programming specifications by enterprises, improving the compatibility, maintainability, and intelligence level of automation systems. Therefore, the efficient and accurate conversion of Basic program code to Pascal program code has significant engineering value and strategic importance.

[0003] However, the conversion process from Basic to Pascal code primarily relies on manual work by engineers, which has significant drawbacks. Due to fundamental differences in instruction semantics, data models, and execution mechanisms—basic code is based on implicit sequential execution, while Pascal code requires explicit state machine construction; the former uses specialized composite data types, while the latter relies on standard structure mappings—manual conversion necessitates parsing the source code line by line, redesigning state logic, and manually reconstructing data structures. For a medium-sized Basic program (such as PICK_jju1 with 103 lines of logic code and 48 lines of data declarations), manual conversion can take tens of hours, severely slowing down project progress. More importantly, the conversion quality is highly dependent on individual experience; inconsistent conversion results from different engineers can easily introduce hidden errors in motion control or timing logic. Furthermore, every time the original Basic program is updated, the entire manual process must be repeated, leading to high maintenance costs and chaotic version management. In the rapidly iterating industrial environment, this inefficient, error-prone, and difficult-to-reproduce manual conversion mode has become a bottleneck restricting system upgrades and large-scale applications. Summary of the Invention

[0004] This application provides a programming language conversion method, apparatus, computing device, computer-readable storage medium, and computer program product. This application can realize the automatic conversion of Basic program code to Pascal program code, which not only improves the efficiency of migrating industrial robot programs to standardized PLC control platforms and greatly shortens the project development and debugging cycle, but also effectively avoids logical errors and data distortion caused by misunderstandings or omissions in the program code during manual conversion.

[0005] Firstly, a programming language conversion method is provided, comprising: converting variable definitions in a program file to be converted, written in a first programming language, into variable definitions in a second programming language; generating a target syntax tree structure based on the program file to be converted, wherein the target syntax tree structure is an abstract syntax tree representing the syntax structure of the first programming language and carrying semantics; generating state machine code in the second programming language based on the target syntax tree structure; and generating a target program file in the second programming language based on the variable definitions in the second programming language and the state machine code in the second programming language.

[0006] Based on the above technical solution, this application ensures that the data semantics are not distorted by converting the variable definitions in the program file to be converted from the Basic language to the variable definitions conforming to the Pascal language. Then, a target syntax structure tree representing the syntax structure of the first programming language and carrying complete semantics is generated according to the program file to be converted. After obtaining the target syntax structure tree, the sequentially executed Basic program code is automatically converted into state machine code conforming to the Pascal language specification based on the target syntax structure tree, realizing the conversion of the implicit sequential execution logic of Basic into the explicit finite state machine control logic of Pascal. Then, the variable definitions of Pascal language and the state machine code conforming to the Pascal language specification are assembled according to the Pascal language syntax specification to obtain the target program file of Pascal language. Thus, the automatic conversion of Basic program code to Pascal program code is realized, which not only solves the problems of low efficiency, error-proneness and difficult maintenance of manual program code conversion, but also improves the efficiency of migrating industrial robot programs to standardized PLC control platforms, as well as the reliability and engineering implementation efficiency of cross-platform migration of industrial programs.

[0007] In one possible implementation, converting variable definitions in a program file to be converted, written in a first programming language, into variable definitions in a second programming language includes: obtaining multiple file pairs from the program file to be converted, each file pair including a variable declaration file and a source code file, with the variable declaration file and source code file having the same filename; mapping each variable declaration in the variable declaration file to the corresponding data type in the second programming language based on the data type of the variable declarations, and adjusting the original variable names in the variable declaration file to new variable names conforming to the second programming language based on the semantic features of the original variable names in the variable declaration file and the naming conventions of the second programming language, to generate a variable declaration list in the second programming language; generating corresponding control variables in the second programming language from the control instructions appearing in the source code file; and generating corresponding function block instances in the second programming language for each specific instruction type in the source code file that needs to be implemented through function blocks.

[0008] In one possible implementation, when generating control variables in a second programming language from control instructions appearing in the source code file, the programming language conversion method further includes: generating variable names with serial numbers for the same type of control instructions that appear multiple times in the source code file.

[0009] In one possible implementation, generating the target syntax structure tree from the program file to be converted includes: constructing an abstract syntax tree representing the syntax structure of the first programming language based on the source code file in the program file to be converted; performing semantic analysis on the abstract syntax tree based on intermediate metadata to obtain the target syntax structure tree, wherein the intermediate metadata is a structured representation of the variable definitions in the program file to be converted.

[0010] In one possible implementation, constructing an abstract syntax tree representing the grammatical structure of the first programming language based on the source code file in the program file to be converted includes: performing word segmentation on the source code file to obtain a word sequence; and performing grammatical analysis on the word sequence to construct the abstract syntax tree.

[0011] In one possible implementation, semantic analysis of the abstract syntax tree based on intermediate metadata to obtain the target syntax structure tree includes: constructing a symbol table based on the intermediate metadata, whereby the symbol table records the definition information of variables and functions in the source code file; using the symbol table to mark type verification tags for nodes in the abstract syntax tree to obtain a first marked syntax tree; performing program execution dependency analysis on each node in the first marked syntax tree, and marking dependency tags on nodes that have mutual program execution dependencies to obtain a second marked syntax tree; performing structured parsing on each node in the first marked syntax tree, and marking the parsing results as parameter semantic tags on each node to obtain a third marked syntax tree; and merging the second marked syntax tree and the third marked syntax tree to obtain the target syntax structure tree.

[0012] In one possible implementation, using a symbol table to verify the type of node tags in the abstract syntax tree to obtain the first tag syntax tree includes: verifying the consistency between the declaration and usage type of each node in the abstract syntax tree using a symbol table; and verifying the type of node tags that pass the verification in the abstract syntax tree to obtain the first tag syntax tree.

[0013] In one possible implementation, generating state machine code for the second programming language based on the target syntax structure tree includes: for each instruction node in the target syntax structure tree, converting the instruction node into a function block instantiation call in the second programming language; assigning a corresponding state flag to the function block instantiation call based on the execution order of each instruction node in the target syntax structure tree in the source code file, and using the execution completion signal of the function block instance as a state transition condition to generate a state machine structure, thereby obtaining the state machine code for the second programming language. In another possible implementation, generating a target program file for the second programming language based on variable definitions and state machine code in the second programming language includes: combining variable definitions and state machine code in the second programming language to obtain multiple program blocks; and generating a target program file for the second programming language based on these multiple program blocks.

[0014] In one possible implementation, after generating a target program file for the second programming language based on variable definitions and state machine code of the second programming language, the programming language conversion method further includes: determining whether there are code statements based on the first programming language in the target program file; if there are code statements based on the first programming language in the target program file, marking the code statements based on the first programming language with a code conversion failure flag, and outputting the target program file.

[0015] In one possible implementation, the programming language conversion method further includes: performing conversion failure analysis on code statements in the target program file that carry conversion failure markers to obtain analysis results; generating code modification suggestion information based on the analysis results, the code modification suggestion information including the position of the code statement in the program file to be converted, the reason for the conversion failure, and modification suggestions.

[0016] Secondly, a programming language conversion apparatus is provided, the programming language conversion apparatus comprising: The first processing module is used to convert variable definitions in a program file to be converted, which is written in the first programming language, into variable definitions in the second programming language. The second processing module is used to generate a target syntax tree structure based on the program file to be converted. The target syntax tree structure is an abstract syntax tree that represents the syntax structure of the first programming language and carries semantics. The third processing module is used to generate state machine code for the second programming language based on the target syntax tree structure. The fourth processing module is used to generate a target program file for the second programming language based on the variable definitions and state machine code of the second programming language.

[0017] Thirdly, a computing device is provided, including a memory and a processor. The memory is used to store executable program code, and the processor is used to call and run the executable program code from the memory, causing the computing device to perform the program language conversion method in the first aspect or any possible implementation thereof.

[0018] Fourthly, a computer program product is provided, comprising: computer program code, which, when run on a computer, causes the computer to execute the programming language conversion method described in the first aspect or any possible implementation thereof.

[0019] Fifthly, a computer-readable storage medium is provided that stores computer program code, which, when run on a computer, causes the computer to perform the programming language conversion method described in the first aspect or any possible implementation thereof. Attached Figure Description

[0020] Figure 1 A schematic flowchart of a programming language conversion method provided in an embodiment of this application is shown; Figure 2 A flowchart illustrating the program code conversion process provided in this application is shown; Figure 3 This illustration shows a schematic diagram of the structure of a programming language conversion device provided in an embodiment of this application; Figure 4 A schematic diagram of the structure of a computing device provided in an embodiment of this application is shown. Detailed Implementation

[0021] The technical solutions in this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. "And / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.

[0022] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.

[0023] In the context of the rapid advancement of industry and intelligent manufacturing, achieving efficient collaboration between industrial robot control systems and PLC systems has become crucial for the digital transformation of the manufacturing industry. Industrial robots generally use the dedicated structured Basic language, with programs consisting of two files: .src and .dat. They support high-precision motion instructions such as PTP and LIN, as well as complex robot-specific data types such as E6POS, FDAT, PDAT, and LDAT, and possess rich control structures and industry-specific instructions. PLC systems, on the other hand, widely adopt the Pascal language conforming to the international standard IEC 61131-3. Based on strong typing, structured syntax, and function block calls (such as Ind_MoveDirectAbsolute), Pascal emphasizes program reliability and portability. Automatically converting Basic programs to Pascal not only helps break down technical barriers between heterogeneous systems, enabling unified development and integrated operation and maintenance, but also promotes the adoption of standardized and international programming standards by enterprises, improving the compatibility, maintainability, and intelligence level of automation systems. Therefore, the efficient and accurate conversion of Basic program code to Pascal program code has significant engineering value and strategic importance.

[0024] However, the conversion process from Basic to Pascal code primarily relies on manual work by engineers, which has significant drawbacks. Due to fundamental differences in instruction semantics, data models, and execution mechanisms—basic code is based on implicit sequential execution, while Pascal code requires explicit state machine construction; the former uses specialized composite data types, while the latter relies on standard structure mappings—manual conversion necessitates parsing the source code line by line, redesigning state logic, and manually reconstructing data structures. For a medium-sized Basic program (such as PICK_jju1 with 103 lines of logic code and 48 lines of data declarations), manual conversion can take tens of hours, severely slowing down project progress. More importantly, the conversion quality is highly dependent on individual experience; inconsistent conversion results from different engineers can easily introduce hidden errors in motion control or timing logic. Furthermore, every time the original Basic program is updated, the entire manual process must be repeated, leading to high maintenance costs and chaotic version management. In the rapidly iterating industrial environment, this inefficient, error-prone, and difficult-to-reproduce manual conversion mode has become a bottleneck restricting system upgrades and large-scale applications.

[0025] To address the aforementioned issues, this application provides a programming language conversion method, apparatus, computing device, computer-readable storage medium, and computer program product. These technologies enable automatic conversion from Basic to Pascal program code, improving the efficiency of migrating industrial robot programs to standardized PLC control platforms and significantly shortening project development and debugging cycles. Furthermore, they effectively avoid logical errors and data distortion caused by misunderstandings or oversights in the program code during manual conversion.

[0026] The following is an embodiment of a programming language conversion method provided in this application specification.

[0027] Figure 1 A schematic flowchart of a programming language conversion method provided in an embodiment of this application is shown, such as... Figure 1 As shown, the programming language conversion method provided in this application is applied to the conversion of Basic program code to Pascal program code. The execution subject of this programming language conversion method is a computing device with computing power, such as a computer. This programming language conversion method includes the following schemes: S110: Convert the variable definitions in the program file to be converted, which is written in the first programming language, into variable definitions in the second programming language.

[0028] The first programming language mentioned in this application refers to Basic, and the second programming language refers to Pascal. The program file to be converted, written in the first programming language, is a program code file written in Basic, i.e., a Basic program code file. Converting variable definitions in the Basic-based program file to Pascal-based variable definitions can be understood as automatically converting the variables declared in the Basic-based program file to equivalent Pascal variable declarations according to Pascal's syntax rules and data type system.

[0029] S120: Generate the target syntax structure tree based on the program file to be converted.

[0030] After obtaining the variable definitions for the second programming language, a target syntax tree structure is constructed based on the program file to be converted and the lexical and grammatical rules of the first programming language. This target syntax tree structure is essentially an abstract syntax tree representing the grammatical structure of the first programming language and carrying complete semantics. It not only accurately reflects the hierarchical structure of the first programming language (such as nested relationships between expressions, statements, functions, and classes), but also embeds semantic elements such as the scope, data type, initialization state, and mapping relationship with the second programming language of variables into corresponding nodes through symbol table integration, type inference, and context analysis. This provides a clear and complete intermediate representation foundation for subsequent semantic equivalence conversion. The nodes in the target syntax tree structure include instruction nodes, control nodes, expression nodes, and identifier nodes.

[0031] S130: Generate state machine code for the second programming language based on the target syntax structure tree.

[0032] After obtaining the target syntax structure tree, each node in the target syntax structure tree has clear semantic information. Then, based on the target syntax structure tree, the instruction sequence of the sequentially executed Basic program code is automatically converted into state machine code that conforms to the Pascal language specification. The Pascal language state machine code obtained through the conversion can execute the Basic program code equivalently.

[0033] S140: Generate a target program file for the second programming language based on the variable definitions and state machine code of the second programming language.

[0034] After obtaining the state machine code conforming to the Pascal language specification, the Pascal language variable definitions and the Pascal language-compliant state machine code are assembled according to the Pascal language syntax specification to obtain the Pascal language target program file, thereby realizing the automatic conversion from Basic program code to Pascal program code.

[0035] Based on the above technical solution, this application ensures that the data semantics are not distorted by converting the variable definitions in the program file to be converted from the Basic language to the variable definitions conforming to the Pascal language. Then, a target syntax structure tree representing the syntax structure of the first programming language and carrying complete semantics is generated according to the program file to be converted. After obtaining the target syntax structure tree, the sequentially executed Basic program code is automatically converted into state machine code conforming to the Pascal language specification based on the target syntax structure tree, realizing the conversion of the implicit sequential execution logic of Basic into the explicit finite state machine control logic of Pascal. Then, the variable definitions of Pascal language and the state machine code conforming to the Pascal language specification are assembled according to the Pascal language syntax specification to obtain the target program file of Pascal language. Thus, the automatic conversion of Basic program code to Pascal program code is realized, which not only solves the problems of low efficiency, error-proneness and difficult maintenance of manual program code conversion, but also improves the efficiency of migrating industrial robot programs to standardized PLC control platforms, as well as the reliability and engineering implementation efficiency of cross-platform migration of industrial programs.

[0036] In one possible implementation, converting variable definitions in a program file written in a first programming language into variable definitions in a second programming language includes the following steps: Obtain multiple file pairs from the program file to be converted. Each file pair includes a variable declaration file and a source code file. The variable declaration file and the source code file have the same filename. Based on the data type of the variable declarations, each variable declaration in the variable declaration file is mapped to the corresponding data type of the second programming language. Based on the semantic features of the original variable names in the variable declaration file and the naming conventions of the second programming language, the original variable names in the variable declaration file are adjusted to new variable names that conform to the second programming language, so as to generate a variable declaration list under the second programming language. Generate corresponding control variables in the second programming language from the control instructions appearing in the source code file; Generate a corresponding function block instance in the second programming language for each specific instruction of the instruction type that needs to be implemented through function blocks in the source code file.

[0037] In the case of generating corresponding control variables in the second programming language from control instructions appearing in the source code file, the programming language conversion method also includes: generating variable names with serial numbers for the same type of control instructions that appear multiple times in the source code file.

[0038] Figure 2 The flowchart of the program code conversion provided in this application is shown, as follows: Figure 2 As shown, the generation of variable definitions in the second programming language can be understood as obtaining the standard variable definition area of ​​the Pascal program code. The specific steps are as follows: Step A1: File reading, which involves reading multiple file pairs from the program file to be converted. For each file pair Di, Di includes a .dat file and a .rsc file. The .dat and .rsc files in Di have the same filename. For example, if the .dat file in Di is named JOB1 and the .rsc file is named JOB1, then the file names are JOB1.dat and JOB1.rsc. When reading the .dat and .src files from the program file to be converted, the system uses multiple character encoding methods to ensure compatibility with file content under different naming conventions or locale settings. These encoding methods include UTF-8 (Unicode Transformation Format - 8-bit, a variable-length Unicode encoding format) and Latin-1 (ISO / IEC 8859-1, a single-byte Western European language character encoding standard). Specifically, the system first attempts to read the file using UTF-8 encoding. If decoding fails due to character set incompatibility (e.g., an illegal byte sequence), it automatically reverts and attempts to reread using Latin-1 encoding. Conversely, it can first attempt Latin-1 reading, and switch to UTF-8 only if that fails. Through this encoding adaptive mechanism, the system can effectively handle source files generated under different development environments or operating systems, ensuring that variable names, comments, and instruction text are parsed completely and accurately. This avoids syntax analysis failures or semantic loss due to encoding errors, thereby improving the robustness and compatibility of program conversion.

[0039] Step A2: Data type extraction and mapping. This involves mapping the variable declarations in the .src file to their corresponding Pascal language data types based on their declared data types. Additionally, based on the semantic features of the original variable names in the .src file and Pascal's naming conventions, the original variable names are adjusted to conform to Pascal language naming rules, generating a Pascal variable declaration list. For example, the variable declarations in the .src file might include DECL E6POS, DECL FDAT, DECL PDAT, DECL LDAT, etc. Taking a DECL E6POS type variable declaration (e.g., DECL E6POSXpick={X XXXX, Y YYYYY, ......}) as an example, the system will precisely parse the X, Y, Z coordinate values, A, B, C attitude angle values, S state value, and T steering value in DECL E6POS, converting them into the Pascal language's E6POS structure format to obtain the corresponding Pascal language data type. Simultaneously, it adopts Pascal's naming conventions, automatically removing prefixes (such as "X") from the Xpick variable name to generate semantically clear Pascal variable names (e.g., converting Xpick to Pos_pick). This maintains the association with the original variable while conforming to Pascal's naming conventions. The mapping process for DECL FDAT, DECL PDAT, DECL LDAT, etc., is the same as that for DECL E6POS. The final variable declaration list includes the corresponding data types in Pascal for each of DECL E6POS, DECL FDAT, DECL PDAT, and DECL LDAT.

[0040] Step A3: Control Variable Generation. This involves the system analyzing the usage of instructions in the .src file to obtain the control instructions appearing in the .src file, and then generating corresponding Pascal language control variables based on these instructions. For example, for the WAIT FOR IN instruction in the .src file, a wait condition variable in Pascal language format Step_Wait_x is generated; for the $OUT [x] instruction in the .src file, an output control variable in Pascal language format Step_OUT_x is generated; for the PULSE instruction in the .src file, a pulse control variable in Pascal language format Step_PULSE_x is generated, and so on. Furthermore, for control instructions of the same type appearing multiple times in the .src file, variable names with serial numbers are generated. For example, if the .src file contains three PULSE instructions, the generated pulse control variables are Step_PULSE_1, Step_PULSE_2, and Step_PULSE_3.

[0041] Step A4: Automatic generation of function block instances. This involves the system analyzing the instruction types in the .src file that require function blocks for implementation, and generating corresponding Pascal language function block instances for each specific instruction under each instruction type. For example, for motion control instructions in the .src file, Pascal language function block instances such as Ind_MoveDirectAbsolute, Ind_MoveLinearAbsolute, and Ind_MoveCircAbsolute are generated; for timing control instructions in the .src file, a Pascal language TON timer instance is generated; and for pulse control instructions in the .src file, a Pascal language TP pulse generator instance is generated.

[0042] After completing steps A1 to A4, the variable definitions for the second programming language are obtained, including data types, control variables, and function block instances in the Pascal language.

[0043] In one possible implementation, generating the target syntax structure tree from the program file to be converted includes the following steps: Based on the source code files in the program file to be converted, construct an abstract syntax tree representing the syntax structure of the first programming language; Semantic analysis of the abstract syntax tree is performed based on intermediate metadata to obtain the target syntax tree structure. The intermediate metadata is a structured representation of the variable definitions in the program file to be converted.

[0044] The specific construction process of the target syntax tree includes: constructing an abstract syntax tree representing the syntax structure of the first programming language based on the source code file in the program file to be converted. The source code file in the program file to be converted refers to the .src file. The source code file in the program file to be converted is read, and then its syntax is analyzed to convert it into an abstract syntax tree. This abstract syntax tree can fully reflect the syntax structure of the Basic program in the program file to be converted (such as what instructions are in the program file, how the control flow is organized, how variables are used, etc.), providing a foundation for subsequent automatic conversion to Pascal program code.

[0045] The variable definition information is parsed from the variable declaration file (i.e., the .dat file) in the program file to be converted, generating structured intermediate metadata. Then, based on this intermediate metadata, semantic filling is performed on the abstract syntax tree, which only contains syntactic structure. This ensures that each type of node in the abstract syntax tree is associated with its corresponding data type, scope, and other key semantic information, thereby generating an abstract syntax tree carrying complete semantics. The nodes in the abstract syntax tree include instruction nodes, control nodes, expression nodes, identifier nodes, etc.

[0046] In one possible implementation, constructing an abstract syntax tree representing the grammatical structure of the first programming language based on the source code file in the program file to be converted includes the following steps: The source code file is segmented to obtain a word sequence; Perform syntactic analysis on the lexical sequence to construct an abstract syntax tree.

[0047] like Figure 2 As shown, in the case of variable definitions related to the second programming language, intelligent syntax parsing is performed on the .src file. First, the intelligent syntax parsing engine performs a deep understanding of the characteristics of the Basic language. The specific process is as follows: Data preprocessing involves preprocessing the source code in the .src file to remove irrelevant information such as comment lines starting with semicolons and blank lines, resulting in a preprocessed .src file.

[0048] Lexical analysis involves using regular expression pattern matching to segment the source code in the preprocessed .src file, resulting in a word sequence (i.e., the segmentation result). The word sequence includes keywords (e.g., DEF, PTP, LIN, CIRC, WAIT, OUT, PULSE, IF, SWITCH, CASE, etc.), identifiers (e.g., variable names and function names starting with a letter), constants (e.g., numeric constants, string constants, Boolean constants, etc., supporting integer, floating-point, scientific notation, etc.), and operators (e.g., arithmetic operators, logical operators, comparison operators, covering +, -, *, / , =, <>, >, <, >=, <=, etc.).

[0049] Syntax analysis employs a top-down recursive descent parsing method to analyze lexical sequences and construct an abstract syntax tree representing the syntactic structure of the Basic language. Specifically, function definition parsing can identify function definitions in the format DEF function_name(), extract the function name and parameter list, and parse the instruction sequence in the function body line by line. Control structure parsing can identify conditional statement structures such as IF condition THEN, ELSE, and ENDIF (analyzing logical operators, comparison operators, and variable references in conditional expressions), as well as selection statement structures such as SWITCH variable, CASE value, DEFAULT, and ENDSWITCH (analyzing the selection variable type and the syntactic structure of each branch).

[0050] In one possible implementation, the above-mentioned semantic analysis of the abstract syntax tree based on intermediate metadata to obtain the target syntax tree structure includes the following steps: The first tag syntax tree is obtained by using a symbol table to validate the node tag type in the abstract syntax tree. Perform program execution dependency analysis on each node in the first tag syntax tree, and mark the nodes that have program execution dependencies on each other with dependency tags to obtain the second tag syntax tree; The first tag syntax tree is structured and parsed, and the parsing results are used as semantic tags to mark each node to obtain the third tag syntax tree. The second and third tag syntax trees are merged to obtain the target syntax structure tree.

[0051] The process of using a symbol table as a type verification marker for node tags in the abstract syntax tree to obtain the first tag syntax tree includes: verifying the consistency between the declaration and usage types of each node in the abstract syntax tree using a symbol table, and verifying the type of node tags that pass the verification in the abstract syntax tree to obtain the first tag syntax tree.

[0052] After obtaining the abstract syntax tree, semantic analysis is performed to imbue it with semantic information. The specific process includes: During the semantic analysis phase, the system first constructs a structured symbol table based on intermediate metadata to record the definition information of all variables and functions in the .src file. Then, the system traverses each node in the abstract syntax tree (AST), using the symbol table to perform existence checks and type consistency verification on the identifiers referenced in the nodes. If a node passes the verification, a type verification mark is added to the AST, resulting in an AST with type verification marks, called the first-marked AST. Specifically, the symbol table is used to verify the consistency between the declared and used types of nodes. At nodes in the AST involving identifier references, the symbol table is queried to verify whether the identifier has been correctly defined and to check whether its usage in the current context is consistent with its declared data type, structural composition, and semantic constraints.

[0053] After obtaining the first tag syntax tree, the system further performs program execution dependency analysis on each node in the first tag syntax tree, identifies the sequential execution dependency relationship and trajectory approximation dependency relationship between instructions, marks the nodes that have mutual program execution dependencies with dependency tags, and obtains the first tag syntax tree with dependency tags, which is called the second tag syntax tree. Specifically, for linearly arranged instruction sequences (e.g., PTP XHOME → PLC_Wait_Pick_JiaJu(1, true) → SLIN XPICKUP), the system determines, based on the implicit sequential execution semantics of the Basic program, that the next instruction must wait for the previous instruction to be fully executed (e.g., the movement is in place, the signal is triggered) before it can be started, thus establishing an explicit blocking state transition dependency. For motion instructions containing CONT (Continuous) parameters (e.g., SPTP XGD CONT Vel=100), the system further analyzes the trajectory smooth connection semantics between it and subsequent motion instructions, identifying the non-blocking execution dependency formed by enabling the continuous path mode. That is, before the current instruction has been fully completed, the subsequent instruction can be planned in advance and enter the trajectory, only needing to meet the approximation accuracy (e.g., CP or DIS parameters) constraints.

[0054] Meanwhile, the system performs structured parsing on the nodes in the first tag syntax tree and marks the parsing results as parameter semantic tags to the corresponding nodes. Taking the complex safe motion instruction SPTP XGD CONT Vel=100 PDAT11 Tool[1]Base[0] as an example: First, the basic instruction type is identified as "Safe Point-to-Point Motion" (SPTP); then, its parameter components are parsed layer by layer, including target position variable (XGD), trajectory approximation mode (CONT), velocity parameter (Vel=100), motion data block (PDAT11), tool configuration (Tool[1]), and reference coordinate system (Base[0]). For the Tool[x] and Base[y] parameters, the system extracts the specific tool number (x) and reference coordinate system number (y), and combines them with the corresponding FDAT tool / base definition in the symbol table to generate a standardized Coord configuration structure. Meanwhile, the system performs validity checks on each parameter, including: Vel must be a positive real number; PDAT11 must be a valid identifier declared in the .dat file and of type PDAT; XGD must be a position variable of type E6POS; and the tool number and reference coordinate system number must be within the range supported by the device.

[0055] All the above parsing results include instruction category, parameter semantic role, configuration value, reference relationship and verification status. The parsing results are all encapsulated as structured parameter semantic tags, and the parameter semantic tags are marked on the corresponding nodes in the first tag syntax tree to obtain the first tag syntax tree with parameter semantic tags, which is called the third tag syntax tree.

[0056] After obtaining the second and third tag syntax trees, the second and third tag syntax trees are merged to obtain the target syntax tree structure. That is, the nodes in the target syntax tree structure carry node tag type verification tags, dependency tags, and parameter semantic tags.

[0057] By marking the nodes in the abstract syntax tree with type validation tags, dependency tags (recording execution order and trajectory dependencies), and parameter semantic tags (recording instruction types, parameter structures, tool / base configurations, etc.) to generate the target syntax tree structure, multiple semantic enhancements are achieved to the abstract syntax tree. This transforms the original abstract syntax tree, which only reflected the grammatical structure, into an abstract syntax tree carrying complete semantics. This abstract syntax tree carrying complete semantics not only accurately expresses "what the program wrote," but also precisely depicts deeper semantics such as "what type each element is," "how it is used," "which other instructions it depends on," and "how the parameters are configured," providing a high-fidelity semantic foundation for the subsequent automatic generation of Pascal-compliant state machine code.

[0058] In one possible implementation, generating state machine code for the second programming language based on the target syntax tree structure includes the following steps: For each instruction node in the target syntax structure tree, the instruction node is converted into a function block instantiation call in the second programming language; Based on the execution order of each instruction node in the target syntax structure tree in the source code file, a corresponding state flag is assigned to the instantiation call of the function block, and the execution completion signal of the function block instance is used as the state transition condition to generate a state machine structure, so as to obtain the state machine code of the second programming language.

[0059] After obtaining the target syntax structure tree, the instruction mapping transformation step and the state machine structure automatic construction step are executed sequentially.

[0060] like Figure 2 As shown, during the instruction mapping and conversion step, the system performs precise cross-language semantic mapping for each instruction node based on the target syntax structure tree. Specifically, for motion control instructions, a complete correspondence between Basic and Pascal function block calls is established. For example, PTP and SPTP instructions are converted into Ind_MoveDirectAbsolute function block instantiation calls, LIN and SLIN instructions are converted into Ind_MoveLinearAbsolute function block instantiation calls, and CIRC and SCIRC instructions are converted into Ind_MoveCircAbsolute function block instantiation calls. All conversion results retain all parameters and configuration information in the original instructions, such as target position variables (e.g., XGD), velocity parameters (Vel), motion data blocks (PDAT11), trajectory approximation mode (CONT), tool configuration (Tool[1]), and reference coordinate system (Base[0]), and their specific values ​​and types are parsed through a symbol table. For control logic instructions, WAIT SEC t is converted to a TON timer function block instantiation call (automatically converting time t from seconds to milliseconds), WAIT FOR IN[x]==val is converted to conditional judgment logic based on input signal x, $OUT[x]= val is converted to a function block instantiation call of a digital output assignment statement, PULSE $OUT[x], and duration generates a function block instantiation call of pulse output logic with duration control. All conversion results strictly follow the timing characteristics and control semantics of the original instructions to ensure equivalent conversion behavior.

[0061] During the automatic state machine structure construction phase, the system assigns a unique state identifier (e.g., STATE_1, STATE_2, ...) to each function block instantiation call based on the execution order of instructions in the .src file within the target syntax tree. It uses the completion signal of the function block instance as the state transition condition to jump to the next state, thus automatically generating a state machine structure conforming to the IEC 61131-3 standard. This state machine structure comprises three parts: first, state variable definitions, used to record the current execution step; second, state execution branches, activating the corresponding function block call in each state; and third, state transition logic, dynamically updating current_state based on the Busy / Done / Error states of the function blocks to ensure instructions are executed strictly in sequence (e.g., only when ptp_inst1.Done = TRUE is the state switched to execute the next LIN instruction). Through this mechanism, the system transforms the originally implicitly sequentially executed Basic program code into explicit, monitorable, and interruptible Pascal-based state machine code, laying a solid foundation for the migration of industrial robot programs to standardized PLC platforms.

[0062] In one possible implementation, generating the target program file for the second programming language based on the variable definitions and state machine code of the second programming language includes the following steps: By combining the variable definitions in the second programming language with the state machine code in the second programming language, multiple program blocks are obtained; Generate a target program file for a second programming language based on multiple program blocks.

[0063] By combining the variable definitions related to the second programming language with the state machine code of the second programming language, we obtain the program header, program body, and program tail. Based on the program header, program body, and program tail, generate a target program file for the second programming language.

[0064] After obtaining the variable definitions and state machine code in Pascal, the two are combined according to the Pascal language specification to generate multiple program blocks. These blocks are ordered according to the execution order of the program code, and then a target program file for the second programming language is generated based on these blocks. For example, the multiple program blocks may be a program header (including function block definitions, variable declarations, etc.), a program body (including state machine structure, instruction execution logic, etc.), and a program tail (including necessary end markers or resource release logic). That is, the program header is generated first, then the program body, and finally the program tail, ensuring syntactic validity and logical closure. Based on the program header, program body, and program tail, a target program file for Pascal is generated, thus automatically completing the conversion of Basic program code to Pascal program code.

[0065] In one possible implementation, after generating a target program file for the second programming language based on variable definitions and state machine code in the second programming language, the language conversion method further includes the following steps: Determine whether the target program file contains code statements based on the first programming language; If the target program file contains code statements based on the first programming language, mark the code statements based on the first programming language with a code conversion failure flag, and output the target program file.

[0066] After generating the target program file, the system performs a code conversion integrity verification step. This involves automatically scanning the target program file to determine if it still contains any original Basic language code statements. If so, it indicates the presence of unconverted code statements, which are marked with a conversion failure flag (e.g., a `(* translate fail! *)` comment) and accompanied by comments explaining the conversion status and the reason for manual intervention. Ultimately, even if some code statements in the target program file fail to convert, the system will still output a complete target program file, ensuring that the remaining valid code can be compiled and used, and providing engineers with clear and actionable debugging guidance. After outputting the target program file, users can check the code statements in the target program file based on the conversion failure flags and manually convert any unconverted code statements, thereby ensuring the integrity and executability of the Pascal program code. In addition, the output target program file can be saved to a specified directory and is compatible with multiple encoding methods (such as UTF-8, Latin-1, etc.), ensuring that the target program file can be read correctly in different operating systems or development environments. At the same time, the system will automatically create an output directory structure, maintain the hierarchical relationship with the input directory, and facilitate users to manage and find the conversion results.

[0067] In one possible implementation, the programming language conversion method further includes the following steps: Perform conversion failure analysis on the code statements in the target program file that carry conversion failure flags, and obtain the analysis results; Based on the analysis results, code modification suggestions are generated, including the location of the code statements in the program file to be converted, the reason for the conversion failure, and modification suggestions.

[0068] This application supports conversion failure analysis of code statements. When conversion failure occurs in the target program file, the system automatically identifies the code statements marked with conversion failure and performs in-depth analysis. First, it parses the syntactic structure and semantic features of the code statement in the first programming language. Then, it combines this with information such as the syntax rules and standard library support of the second programming language to compare compatibility differences between the two languages, thereby accurately locating the root cause of the conversion failure and obtaining the analysis results. Based on these results, the system generates structured code modification suggestions, including: the specific location of the conversion failure code statement in the program file to be converted (e.g., filename, line number); the technical reason for the conversion failure and its contextual dependencies; and targeted modification suggestions, such as replacing the first programming language with a functionally equivalent and compatible implementation in the second programming language. Generating code modification suggestions helps users efficiently locate problems and complete manual intervention, effectively improving the efficiency of manual intervention and the success rate of code conversion.

[0069] This application achieves high-fidelity and high-efficiency conversion of industrial robot Basic program code to Pascal program code conforming to the IEC 61131-3 standard by constructing an automated program code conversion mechanism based on semantically enhanced abstract syntax trees, and has the following significant technical effects: (1) The efficiency of program code conversion has been greatly improved. This application achieves automated conversion of Basic program code to Pascal program code, requiring only simple manual verification of the conversion results. Conversion time is reduced from tens of hours using traditional manual methods to minutes for machine conversion (manual verification takes about half an hour), improving efficiency by tens of times. It supports batch conversion of multiple Basic program files and can process all program files in an entire directory or project simultaneously, significantly improving the efficiency of large-scale program migration. It can respond to user conversion requests in real time, providing instant conversion results and feedback, supporting iterative development and rapid prototype verification.

[0070] (2) The quality of program code conversion has been significantly improved. Based on intelligent syntax parsing and precise instruction mapping, the conversion accuracy of this application is far higher than that of traditional manual conversion; especially when dealing with complex motion control logic and timing control, the conversion quality is significantly better than manual conversion. At the same time, it maintains the logical consistency between the converted Pascal program code and the original Basic program code, ensuring consistent program execution results; through automatic state machine generation and intelligent control logic conversion, it avoids common logical errors in traditional conversions; the final generated Pascal program code has a clear structure, high readability, and conforms to Pascal language programming standards, facilitating subsequent maintenance and expansion.

[0071] (3) Enhanced system compatibility and integration capabilities The Pascal program code generated by this application fully complies with the IEC 61131-3 international standard and can be directly compiled and run on mainstream PLC platforms such as Siemens (TIA Portal), Rockwell (Studio 5000), and Schneider (EcoStruxure). At the same time, the program interface is standardized and naturally supports industrial communication protocols such as OPC UA (Open Platform Communications Unified Architecture), Modbus (Modbus Protocol), and Profinet (Process Field Net), which facilitates seamless integration with host computers, manufacturing execution systems (MES), and other automation equipment, helping enterprises build a unified control architecture.

[0072] (4) Outstanding economic benefits and strategic value This application significantly reduces the development cost of converting Basic programs to Pascal programs, reduces enterprises' reliance on professional engineers proficient in both languages, and lowers talent training and recruitment costs; the unified programming environment reduces system maintenance complexity, reduces maintenance errors and downtime, and improves system reliability and availability; at the same time, it shortens the project implementation cycle, enhances enterprises' market responsiveness and competitiveness; and by promoting the standardization of programming languages ​​for industrial automation systems, it provides technical support for enterprises' digital transformation and international development.

[0073] Based on the automatic conversion scheme from Basic to Pascal provided in this application, the following five extended implementation schemes can be derived, significantly expanding the application boundaries and technical value of this application: Extension Solution 1: Multi-language Support Extension Solution. The core architecture of this application provides a solid foundation for multi-language support. Besides the conversion from Basic to Pascal programs, it can be extended to support the conversion of other robot programming languages ​​to PLC programming languages, such as the conversion from ABB (Asea Brown Boveri Ltd) robot's RAPID (Robotics Application Programming Interface for Development) language to Pascal. The implementation includes building a general robot language parsing framework, abstracting the syntax rules of different robot languages ​​into a unified syntax tree structure; establishing multi-target language code generation templates that support multiple PLC programming languages ​​such as Pascal; and implementing language conversion through configurable mapping rules.

[0074] Extension Option 2: Deep Learning-Enhanced Conversion Solution. Existing conversion systems primarily rely on rule matching and pattern recognition. This can be further extended into a deep learning-based intelligent conversion system. Specific implementation involves: collecting a large number of Basic-Pascal program pairs as training data to build a deep learning model; using neural network architectures such as Transformer or LSTM (Long Short-Term Memory) to learn the mapping relationship between the two languages; and combining this with an existing rule engine to implement a hybrid rule-driven and data-driven conversion strategy. The advantage of this solution is its ability to handle more complex and diverse Basic program structures (especially complex grammatical patterns that are difficult to describe with rules), and the deep learning model can learn more accurate conversion rules from a large number of samples, improving conversion accuracy and robustness.

[0075] Extended Solution 3: Cloud-based Collaborative Conversion Solution. Considering the network limitations and security requirements of industrial environments, a scalable cloud-based collaborative conversion solution can be implemented. Specific implementation methods include: deploying a lightweight conversion engine locally for basic syntax parsing and code generation; deploying a powerful AI model and knowledge base in the cloud for complex semantic analysis and optimization suggestions; and enabling collaborative work between local and cloud environments through a secure API (Application Programming Interface). The advantage of this solution is that it leverages the powerful computing capabilities and rich knowledge resources of the cloud while maintaining the real-time performance and security of local conversion. The cloud provides value-added services such as intelligent code optimization suggestions, accurate error diagnosis, and rich conversion templates.

[0076] Extended Solution 4: Incremental Conversion and Version Management Solution. Existing conversion systems primarily support full program conversion, but can be expanded to include incremental conversion and version management capabilities. Implementation involves: establishing a version control system for the Basic program to record its modification history; implementing an incremental parsing algorithm that only re-parses and converts the modified parts; and providing version comparison and rollback functions to support iterative development and debugging. This solution is particularly suitable for the practical needs of industrial environments (where programs often require frequent modification and optimization). Incremental conversion significantly improves development efficiency and reduces repetitive conversion work, while version management ensures the traceability and security of program modifications.

[0077] Extended Solution 5: Conversion Result Verification Solution. This solution can be extended to a PLC language compilation system to verify the syntactic correctness of the converted Pascal program; it can also be connected to a robot actuator to verify the consistency of the motion path between the converted program and the original Basic program, further ensuring the reliability of the conversion result.

[0078] Due to long-standing technological barriers and closed ecosystems in the industrial automation field, equipment and systems from different manufacturers often employ proprietary technical standards and programming environments. This necessitates application development engineers mastering multiple technology stacks, increasing learning costs and workload. The automatic conversion solution from Basic to Pascal programs provided in this application creates a conversion tool that meets industrial standardization requirements, applicable to various industrial automation scenarios, and providing crucial support for building an open and interoperable automation application ecosystem. For example, applicable industrial automation scenarios include: Application Scenario 1: Multi-vendor device integration application scenario In large-scale industrial projects, it is often necessary to integrate equipment from different manufacturers (including industrial robots running Basic programs, Siemens PLCs, etc.). Traditionally, application development engineers need to learn various proprietary technologies separately, resulting in low development efficiency and a high risk of errors. With the conversion system of this invention, the Basic program of an industrial robot can be converted into a Pascal program conforming to the IEC61131-3 standard, achieving seamless integration with PLC systems from manufacturers such as Siemens and Rockwell, significantly simplifying the integration of multi-vendor equipment.

[0079] Application Scenario 2: System Upgrade and Transformation Application Scenario Many industrial enterprises face the need for equipment upgrades, requiring the replacement of outdated robot control systems (running Basic programs) with modern PLC control systems. Traditionally, this upgrade necessitates the redevelopment of all control programs, resulting in a large workload and high risk. By applying the conversion system of this invention, existing Basic programs can be automatically converted to Pascal programs, preserving the original control logic and process parameters, significantly reducing the risks and costs of upgrades.

[0080] Application Scenario 3: Promotion and Application of Technology Standardization With the advancement of Industry 4.0 and intelligent manufacturing, the standardization of industrial automation systems is becoming increasingly urgent. The conversion scheme provided in this application offers a technical path for converting Basic program code to standard Pascal program code, contributing to the standardization process across the industry. Application development engineers can work in a standardized development environment, reducing the burden of technical learning and improving development efficiency.

[0081] Application Scenario 4: Cross-Platform Application Development In industrial automation software development, it is often necessary to support multiple hardware platforms and operating systems. Traditionally, a dedicated version needs to be developed for each platform, resulting in high maintenance costs and difficulty in ensuring functional consistency. With the conversion system of this invention, Basic programs can be converted into standard Pascal programs, which can run on various PLC systems conforming to the IEC 61131-3 standard, enabling cross-platform application development and significantly reducing software development and maintenance costs.

[0082] Application Scenario 5: PLC Application Takeover of Robot Application Scenario In complex industrial automation scenarios, traditional robot control systems often employ independent programming environments and control architectures, leading to difficulties in system integration and low development efficiency. The conversion system of this invention effectively solves this problem by converting Basic programs into standard Pascal programs, enabling PLC applications to completely take over robot applications, thereby improving system integration and development efficiency.

[0083] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.

[0084] Figure 3 This application provides a schematic diagram of the structure of a programming language conversion device according to an embodiment of the present application. Figure 3 As shown, the programming language conversion device 300 includes: The first processing module 310 is used to convert variable definitions in a program file to be converted based on a first programming language into variable definitions in a second programming language. The second processing module 320 is used to generate a target syntax tree structure based on the program file to be converted. The target syntax tree structure is an abstract syntax tree that represents the syntax structure of the first programming language and carries semantics. The third processing module 330 is used to generate state machine code for the second programming language based on the target syntax structure tree; The fourth processing module 340 is used to generate a target program file for the second programming language based on the variable definitions and state machine code of the second programming language.

[0085] In one possible implementation, the first processing module 310 is specifically used to obtain multiple file pairs from the program file to be converted, each file pair including a variable declaration file and a source code file, the variable declaration file and the source code file having the same filename; according to the data type of the variable declarations, mapping each variable declaration in the variable declaration file to the data type corresponding to the second programming language, and based on the semantic features of the original variable names in the variable declaration file and the naming convention of the second programming language, adjusting the original variable names in the variable declaration file to new variable names that conform to the second programming language, so as to generate a variable declaration list under the second programming language; generating control variables corresponding to the control instructions appearing in the source code file under the second programming language; and generating a corresponding function block instance under the second programming language for each specific instruction type of the instruction in the source code file that needs to be implemented through function blocks.

[0086] In one possible implementation, the first processing module 310 is specifically used to generate variable names with serial numbers for the same type of control instructions that appear multiple times in the source code file.

[0087] In one possible implementation, the second processing module 320 is specifically used to construct an abstract syntax tree representing the grammatical structure of the first programming language based on the source code file in the program file to be converted; and to perform semantic analysis on the abstract syntax tree based on intermediate metadata to obtain the target syntax structure tree, wherein the intermediate metadata is a structured representation of the variable definitions in the program file to be converted.

[0088] In one possible implementation, the second processing module 320 is specifically used to perform word segmentation on the source code file to obtain a word sequence; and to perform syntactic analysis on the word sequence to construct an abstract syntax tree.

[0089] In one possible implementation, the second processing module 320 is specifically used to construct a symbol table based on intermediate metadata. The symbol table is used to record the definition information of variables and functions in the source code file. The symbol table is used as the node type verification mark in the abstract syntax tree to obtain a first mark syntax tree. Program execution dependency analysis is performed on each node in the first mark syntax tree, and dependency marks are marked on nodes that have mutual program execution dependencies to obtain a second mark syntax tree. The structured parsing of each node in the first mark syntax tree is performed, and the parsing results are marked as parameter semantic marks on each node to obtain a third mark syntax tree. The second mark syntax tree and the third mark syntax tree are merged to obtain the target syntax structure tree.

[0090] In one possible implementation, the second processing module 320 is specifically used to verify the consistency between the declaration and usage type of each node in the abstract syntax tree using a symbol table; and to mark the type verification tags of the nodes that pass the verification in the abstract syntax tree to obtain the first marked syntax tree.

[0091] In one possible implementation, the third processing module 340 is specifically used to convert each instruction node in the target syntax structure tree into a function block instantiation call in the second programming language; based on the execution order of each instruction node in the target syntax structure tree in the source code file, assign a corresponding state flag to the function block instantiation call, and use the execution completion signal of the function block instance as a state transition condition to generate a state machine structure to obtain the state machine code of the second programming language.

[0092] In one possible implementation, the fourth processing module 340 is specifically used to combine the variable definitions of the second programming language with the state machine code of the second programming language to obtain multiple program blocks; and to generate a target program file of the second programming language based on the multiple program blocks.

[0093] In one possible implementation, the programming language conversion device 300 further includes: The code verification unit is used to determine whether there are code statements based on the first programming language in the target program file; if there are code statements based on the first programming language in the target program file, the code conversion failure flag is marked for the code statements based on the first programming language, and the target program file is output.

[0094] In one possible implementation, the programming language conversion device 300 further includes: The suggestion generation unit is used to perform conversion failure analysis on code statements in the target program file that carry conversion failure markers, and obtain analysis results; based on the analysis results, code modification suggestion information is generated, which includes the location of the code statement in the program file to be converted, the reason for the conversion failure, and modification suggestions.

[0095] It should be noted that the programming language conversion device provided in the above embodiments is only illustrated by the division of the above functional modules when executing the programming language conversion method. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the programming language conversion device and the programming language conversion method embodiments provided in the above embodiments belong to the same concept. Therefore, for details not disclosed in the device embodiments of this application, please refer to the above embodiments of the programming language conversion method of this application, which will not be repeated here.

[0096] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0097] Figure 4 This application provides a schematic diagram of the structure of a computing device according to an embodiment of the present application. Figure 4 As shown, the computing device 400 includes a memory 401 and a processor 402, wherein the memory 401 stores executable program code 4011, and the processor 402 is used to call and execute the executable program code 4011 to perform a programming language conversion method.

[0098] This embodiment can divide the computing device into functional modules according to the above method example. For example, each module can correspond to a separate functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0099] When each functional module is divided according to its corresponding function, the computing device may include: a first processing module, a second processing module, a third processing module, a fourth processing module, etc. It should be noted that all relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here.

[0100] The computing device provided in this embodiment is used to execute the above-described programming language conversion method, and thus can achieve the same effect as the above-described implementation method.

[0101] When using integrated units, a computing device may include a processing module and a storage module. The processing module is used to control and manage the operations of the computing device. The storage module is used to support the execution of relevant program code and data by the computing device.

[0102] The processing module may be a processor or a controller, which can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor may also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc., and the storage module may be a memory.

[0103] This embodiment also provides a computer-readable storage medium storing computer program code. When the computer program code is run on a computer, the computer executes the above-described related method steps to implement a programming language conversion method in the above embodiment.

[0104] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement a programming language conversion method as described in the above embodiment.

[0105] In addition, the computing device provided in the embodiments of this application may specifically be a chip, component or module. The computing device may include a connected processor and a memory. The memory is used to store instructions. When the computing device is running, the processor may call and execute the instructions to make the chip execute a programming language conversion method in the above embodiments.

[0106] In this embodiment, the computing device, computer-readable storage medium, computer program product, or chip are all used to execute the corresponding program language conversion method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding program language conversion method provided above, and will not be repeated here.

[0107] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0108] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0109] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A programming language conversion method, characterized in that, The programming language conversion method includes: Convert the variable definitions in the program file to be converted, which is written in the first programming language, into variable definitions in the second programming language. A target syntax tree structure is generated based on the program file to be converted. The target syntax tree structure is an abstract syntax tree that represents the syntax structure of the first programming language and carries semantics. Based on the target syntax structure tree, generate the state machine code of the second programming language; Based on the variable definitions and state machine code of the second programming language, generate a target program file for the second programming language.

2. The programming language conversion method according to claim 1, characterized in that, The process of converting variable definitions in a program file written in the first programming language into variable definitions in the second programming language includes: Multiple file pairs are obtained from the program file to be converted. Each file pair includes a variable declaration file and a source code file, and the variable declaration file and the source code file have the same filename. Based on the data type of the variable declaration, each variable declaration in the variable declaration file is mapped to the data type corresponding to the second programming language. Based on the semantic features of the original variable names in the variable declaration file and the naming convention of the second programming language, the original variable names in the variable declaration file are adjusted to new variable names that conform to the second programming language, so as to generate a variable declaration list under the second programming language. The control instructions appearing in the source code file are used to generate corresponding control variables in the second programming language; For each specific instruction in the instruction type that needs to be implemented through function blocks in the source code file, generate a corresponding function block instance in the second programming language.

3. The programming language conversion method according to claim 2, characterized in that, When generating control variables corresponding to the control instructions appearing in the source code file in the second programming language, the programming language conversion method further includes: For the same type of control instruction that appears multiple times in the source code file, generate variable names with serial numbers to distinguish them.

4. The programming language conversion method according to claims 1 to 3, characterized in that, The step of generating a target syntax structure tree based on the program file to be converted includes: Based on the source code file in the program file to be converted, construct an abstract syntax tree representing the syntax structure of the first programming language; Semantic analysis is performed on the abstract syntax tree based on intermediate metadata to obtain the target syntax tree structure, wherein the intermediate metadata is a structured representation of the variable definitions in the program file to be converted.

5. The programming language conversion method according to claim 4, characterized in that, The step of constructing an abstract syntax tree representing the syntax structure of the first programming language based on the source code file in the program file to be converted includes: The source code file is segmented to obtain a word sequence; The lexical sequence is subjected to syntactic analysis to construct the abstract syntax tree.

6. The programming language conversion method according to claim 4, characterized in that, The semantic analysis of the abstract syntax tree based on intermediate metadata to obtain the target syntax tree structure includes: A symbol table is constructed based on the intermediate metadata, and the symbol table is used to record the definition information of variables and functions in the source code file; The symbol table is used as the node tag type verification tag in the abstract syntax tree to obtain the first tag syntax tree; Perform program execution dependency analysis on each node in the first tag syntax tree, and mark the nodes that have program execution dependencies on each other with dependency tags to obtain the second tag syntax tree; The first tag syntax tree is structured and parsed, and the parsing results are used as semantic tags to mark each node to obtain the third tag syntax tree. The target syntax tree is obtained by fusing the second and third tokenized syntax trees.

7. The programming language conversion method according to claim 6, characterized in that, The step of using the symbol table as the node tag type verification tag in the abstract syntax tree to obtain the first tag syntax tree includes: The symbol table is used to verify the consistency between the declaration and usage types of each node in the abstract syntax tree; The first tag syntax tree is obtained by validating the tag type of the nodes that pass the validation in the abstract syntax tree.

8. The programming language conversion method according to any one of claims 1 to 7, characterized in that, The step of generating the state machine code of the second programming language based on the target syntax structure tree includes: For each instruction node in the target syntax structure tree, the instruction node is converted into a function block instantiation call in the second programming language; Based on the execution order of each instruction node in the target syntax structure tree in the source code file, a corresponding state identifier is assigned to the instantiation call of the function block, and the execution completion signal of the function block instance is used as the state transition condition to generate a state machine structure, so as to obtain the state machine code of the second programming language.

9. The programming language conversion method according to any one of claims 1 to 8, characterized in that, The step of generating a target program file for the second programming language based on the variable definitions and state machine code of the second programming language includes: The variable definitions in the second programming language are combined with the state machine code in the second programming language to obtain multiple program blocks; The target program file for the second programming language is generated based on the multiple program blocks.

10. The programming language conversion method according to any one of claims 1 to 9, characterized in that, After generating the target program file for the second programming language based on the variable definitions and state machine code of the second programming language, the program language conversion method further includes: Determine whether the target program file contains code statements based on the first programming language; If the target program file contains code statements based on the first programming language, mark the code statements based on the first programming language with a code conversion failure flag, and output the target program file.

11. The programming language conversion method according to claim 10, characterized in that, The programming language conversion method also includes: Perform conversion failure analysis on the code statements in the target program file that carry conversion failure flags, and obtain the analysis results; Based on the analysis results, code modification suggestions are generated. These suggestions include the location of the code statements in the program file to be converted, the reason for the conversion failure, and modification recommendations.

12. A programming language conversion device, characterized in that, The programming language conversion device includes: The first processing module is used to convert variable definitions in a program file to be converted, which is written in the first programming language, into variable definitions in the second programming language. The second processing module is used to generate a target syntax tree structure based on the program file to be converted. The target syntax tree structure is an abstract syntax tree that represents the syntax structure of the first programming language and carries semantics. The third processing module is used to generate state machine code for the second programming language based on the target syntax structure tree. The fourth processing module is used to generate a target program file for the second programming language based on the variable definitions and state machine code of the second programming language.

13. A computing device, characterized in that, The computing device includes: Memory, used to store executable program code; A processor for calling and running the executable program code from the memory, causing the computing device to perform the program language conversion method as described in any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed, implements the programming language conversion method as described in any one of claims 1 to 11.

15. A computer program product, characterized in that, The computer program product includes: computer program code, which, when run on a computer, causes the computer to perform the programming language conversion method as described in any one of claims 1 to 11.

Citation Information

Cited By

  • Cross-language interface binding method, device and electronic equipment

    CN122261580A