1. Field of the Invention
The invention relates to a process of automatically translating high level programming language into an extended activity diagram, and more particularly, to a process of translating source codes coded by a high level programming language into a corresponding activity diagram and presenting programming logic and executing flow of the source codes in a visualization form.
2. Description of Related Art
Typically hardware description languages (HDL) such as VHDL are not suitable directly for describing programming logic and executing flow of a high level programming language. Accordingly, on a hardware description design, the hardware description conditions designed cannot be corresponded directly to the flows designed by the high level language, which leads to a trouble on design. In addition, the typically high level languages cannot be translated directly into an HDL such as VHDL, which is inconvenient on design. Further, the various high level languages, such as Java, C and C++, have different features that cannot be unified into a complete executing flow even the functions of the programs designed by the high level languages are the same.
Therefore, it is desirable to provide an improved process to mitigate and/or obviate the aforementioned problems.
The object of the invention is to provide a process of automatically translating a high level programming language into an activity diagram, which adds a translation rule in a compiler to accordingly translate source codes coded by the high level language into a corresponding activity diagram. The process includes the steps: (A) reading a source code; (B) translating the source code read in step (A) into a corresponding subgraph when the source code is not a statement instruction, and executing step (A); (C) translating a statement into a corresponding subgraph when the source code read in step (A) is the statement instruction and the statement is in front of a condition expression in the statement instruction; (D) generating a select node; (E) generating left and right curve points respectively linked to the select node; (F) translating a statement, which is not in front of the condition expression in the statement instruction, into a corresponding subgraph; (G) generating a merge node to merge the subgraphs; (H) linking up the subgraph generated in step (F) with the right curve point; (I) linking up the subgraph generated in step (F) with the merge node; and (J) determining if an instruction is not translated into a corresponding subgraph; if yes, executing step (A); and if not, completing and outputting the corresponding activity diagram. Accordingly, the invention modifies the activity diagram of UML to thus present the programming logic and executing flow of the source codes of the high level language in a visualization form and benefit a following simulation and requirement for a HDL translation.
In the process of automatically translating a high level programming language into an activity diagram according to the invention, the high level language can be Java, C or C++ language.
In the process of automatically translating a high level programming language into an activity diagram according to the invention, the activity diagram is an extended activity diagram defined by a UML language and indicates a flow control graph.
In the process of automatically translating a high level programming language into an activity diagram according to the invention, the activity diagram contains the nodes of start, end, curve point, micro-operation, fork, join, select and merge.
In the process of automatically translating a high level programming language into an activity diagram according to the invention, the statement instruction includes the instructions of for, while, do, if and switch.
Other objects, advantages, and novel features of the invention will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings.
a is a flowchart of an implementation of translating a statement “for” into an EAD according to the invention;
b is a flowchart of an implementation of translating a statement “while” into an EAD according to the invention;
c is a flowchart of an implementation of translating a statement “do” into an EAD according to the invention;
d is a flowchart of an implementation of translating a statement “if” into an EAD according to the invention;
e is a flowchart of an implementation of translating a statement “switch” into an EAD according to the invention;
a is a graph of a Java program according to the invention; and
b is a graph of an EAD corresponding to the Java program of
Since the prior process cannot translate a high level programming language into a hardware description language (HDL) directly, the high level programming language, such as Java, C, C++ and so on, is first translated into a temporal format called activity diagram (AD) when a user desires to translate the high level programming language into the HDL. The AD is a flow description graph, as shown in
Referring to
1. A start node indicates the start of a subgraph.
2. An end node indicates the end of a subgraph.
3. A curve point node indicates two directional edges for providing a convenience in a translation process, which have no practical affection on an operation.
4. A micro-operation node indicates a statement or expression processing.
5. A fork node indicates a parallel operation.
6. A join node indicates that an output signal is sent only when all micro-operations are arrived.
7. A select node indicates to select an appropriate output signal after decoding.
8. A merge node indicates to merge all input signals into an output signal to output.
Each node is regarded as an object in which two types of data are recorded to indicate an in-node connected to the node and an out-node connecting from the node to another node, and the node type is changed with the syntax. A corresponding subgraph is generated with each syntax segment analysis, and the in-nodes and out-nodes of the subgraph are recorded for other subgraphs to further link and use. Accordingly, a corresponding subgraph can be generated by such a linking for each syntax segment, and linking all subgraphs can achieve the purpose of translating source codes into a corresponding activity diagram and presenting the programming logic and executing flow of the source codes in a visualization form.
As cited, a complete EAD consists of plural subgraphs. The first subgraph records an information of class referred to as a class subgraph, and each other subgraph corresponds to a method. Each part of a subgraph consists of different nodes. The class subgraph is started with a start node referred to as a class start node, and the class start node contains various labels. The notations used in a subgraph are described as follows.
where C indicates a class, and className, modifier respectively indicate name, modifier of the class. The modifier is expressed by a number, including:
where G indicates a global variable, and type, size, variable Name respectively indicate type, size, and name of the global variable. The type and the size are defined the same as in Java.
where M indicates a method, and method Name, modifier respectively indicate name, modifier of the method. The modifier is expressed by a number, including:
The operation part of the class subgraph can be divided into left and right divisions: left referred to as a class variable division and right referred to as an instance variable division. A directional edge links between the start part and the class and instance variable divisions respectively, i.e., an arrow is directed from the start part to the class variable division and the instance variable division respectively labeled “class” and “instance”, which are referred as an edge label.
The class variable division and the instance variable division contain all micro-operation nodes except the first node to be the start node, and two nodes is linked by an edge in an arrow direction from up to down. The class variable division has a content “m=sinit, 0” of the start node, and the instant variable division has a content “m=init, 0”. In the two divisions, the content of a micro-operation node is an initial value declaration. The end parts of the two divisions are represented by an end node respectively with a content “return VOID sinit” and “return VOID init”.
The start part of a method subgraph is indicated by a start node, which contains plural labels described as follows.
M=method Name, modifier: where M indicates a method, and method Name, modifier respectively indicate name, modifier of the method. The modifier is expressed by a number, including:
As cited, the graph specification used in all subgraphs of an extended activity diagram is described.
Due to various types of tokens in the Java program, only representative statement instructions, condition expressions and statements, and their translation flows and rules are described. In this case, the statement instruction includes the types of for, while, do, if and switch, and associated translation flows and rules are described respectively as follows.
Translation of For Statement
The syntax is represented by for ([ForInit( )]; [Expression( )]; [ForUpdate( )]) Statement( ).
A translation description is given in the following example.
Referring to
Step 1 analyzes “for” and “(”;
Step 2 analyzes the content of For Init( ) to thereby draw a subgraph that is an oval node with a content of i=1 (notation {circumflex over (1)}), and forms the in-node and out-node edges of the subgraph;
Step 3 analyzes “;”;
Step 4 analyzes the content of Expression( ) to thereby execute the added Java program, e.g., “processConditionExpression( )”, in order to generate a decoder (D) node and two lower edges thereof, on which edge labels are generated, and further draws a complete subgraph (a set of nodes), as shown in (notation {circumflex over (2)}, and sets in-node and out-nodes of the complete subgraph;
Step 5 analyzes “;”;
Step 6 analyzes the content of ForUpdate to thereby draw a subgraph that is an oval node with a content of i++ (notation {circumflex over (3)}) and obtain an out-node of the subgraph;
Step 7 analyzes “)”;
Step 8 analyzes the content of Statement( ) to thereby draw a subgraph that is an oval node with a content of sum+=i, as shown in notation {circumflex over (4)};
Step 9 links the out-node of the {circumflex over (2)} subgraph representative of the Expression( ) to the {circumflex over (3)} in-node;
Step 10 generates a merge (M) node as shown in notation {circumflex over (5)};
Step 11 links the out-node of the content of Statement( ) to an in-node of the M node;
Step 12 forms the in-node and out-node edges of the M node.
Accordingly, an implementation of translating the “for” statement in the Java source codes into the EAD is described.
Translation of While Statement
The syntax is represented by while (Expression( )) Statement( ).
A translation description is given in the following example.
Referring to
Step 1 analyzes “while” and “(”;
Step 2 analyzes the content of Expression( ) to thereby executes the added Java program “processConditionExpression( )” in order to generate a decode (D) node and two lower edges thereof, on which edge labels are generated, and further draws a complete subgraph (a set of nodes), as shown in notation {circumflex over (2)}, and sets an in-node and out-node of the complete subgraph;
Step 3 analyzes “)”;
Step 4 analyzes the content of Statement( ) to thereby generate a subgraph, as shown in notation {circumflex over (1)} and obtain an in-node and out-node of the {circumflex over (1)} subgraph;
Step 5 links the out-node of the notation {circumflex over (2)} to the in-node of the notation {circumflex over (1)};
Step 6 generates a merge (M) node, as shown in notation {circumflex over (3)};
Step 7 links the out-node of the notation {circumflex over (1)} to the M node;
Step 8 forms the in-node and out-node edges of the M node.
Accordingly, an implementation of translating the “while” statement in the Java source codes into the EAD is described.
Translation of Do Statement
The syntax is represented by do Statement( ) while (Expression( )).
A translation description is given in the following example.
Referring to
Step 1 analyzes “do”;
Step 2 analyzes the content of Statement( ) to thereby generate a subgraph, as shown in notation {circumflex over (1)}, and obtain the out-node of the subgraph;
Step 3 analyzes “while” and “(”;
Step 4 analyzes the content of Expression( ) to thereby executes the added Java program “processConditionExpression( )” in order to generate a decode (D) node and two lower edges thereof, on which edge labels are generated, and further draws a complete subgraph (a set of nodes), as shown in notation {circumflex over (2)}, and sets an in-node and out-node of the complete subgraph;
Step 5 analyzes “)” and “;”;
Step 6 links the out-node of the notation {circumflex over (2)} to the in-node of the notation {circumflex over (1)});
Step 7 generates a merge (M) node, as shown in notation {circumflex over (3)};
Step 8 links the out-node of the notation {circumflex over (2)} to the M node;
Step 9 forms the in-node and out-node edges of the M node.
Accordingly, an implementation of translating the “do” statement in the Java source codes into the EAD is described.
Translation of If Statement
The syntax is represented by if (Expression( )) Statement( )[else Statement( )].
A translation description is given in the following example.
Referring to
Step 1 analyzes “if” and “(”;
Step 2 analyzes the content of Expression( ) to thereby execute the added Java program “processConditionExpression( )” in order to generate a decoder (D) node and two lower edges thereof, on which edge labels are generated, and further draws a complete subgraph (a set of nodes), as shown in notation {circumflex over (1)}), and sets in-node and out-nodes of the complete subgraph;
Step 3 analyzes “)”;
Step 4 analyzes the content of Statement( ) to thereby draw a subgraph that is an oval node with a content of b=−a, as shown in notation {circumflex over (2)}, and obtain the in-node of the {circumflex over (2)} subgraph;
Step 5 analyzes “else”;
Step 6 analyzes the content of else statement( ) to thereby draw a subgraph that is an oval node with a content of b=a, as shown in notation {circumflex over (3)}, and obtain the out-node of the subgraph;
Step 7 links the out-node 1 (right) of the {circumflex over (1)} subgraph to the in-node of the {circumflex over (2)} subgraph;
Step 8 links the out-node 0 (left) of the {circumflex over (1)} subgraph to the in-node of the {circumflex over (3)} subgraph;
Step 9 generates a merge (M) node as shown in notation {circumflex over (4)};
Step 10 links the out-nodes of the {circumflex over (2)} and {circumflex over (3)} subgraphs to the M node.
Accordingly, an implementation of translating the “if” statement in the Java source codes into the EAD is described.
Translation of Switch Statement
The syntax is represented by
A translation description is given in the following example.
Referring to
Step 1 analyzes “switch” and “(”;
Step 2 analyzes the content of Expression( ) and stores the variable i;
Step 3 analyzes “)” and “{”;
Step 4 analyzes the content of a Switch Label( ), and links up “case Expression” with the variable in Expression( ) to thereby obtain a subgraph, as shown in notation {circumflex over (1)} in which a decoder (D) node, edges and edge labels are included, and two out-nodes, Out-Node 0 and Out-Node 1 are set;
Step 5 analyzes the content of Block Statement( ) and draws a subgraph that is an oval node with a content of i++, as shown in notation {circumflex over (2)}, and set the Out-Node 0 to be the out-node of the subgraph;
Step 6 analyzes the other Switch Label( ) as shown in steps 4 and 5, but for the second Switch Label( ) analysis and more, as shown in notations {circumflex over (3)}, {circumflex over (4)} and {circumflex over (5)}, a determination for generating a merge (M) node is added;
Step 7 generates a merge (M) node to link the other out-nodes as shown in notation {circumflex over (6)}.
Accordingly, an implementation of translating the “switch” statement in the Java source codes into the EAD is described.
Therefore,
When the source code is determined to be a statement instruction in step S502, it is further determined if a statement is in front of a condition expression in the statement instruction (step S504); if yes, the statement is translated into a corresponding subgraph (step S505), and subsequently a select node is generated (step S506).
When there is no statement in front of a condition expression in the statement instruction, the select node is generated directly (step S506). Next, left and right curve points are generated (step S507) and respectively linked to the select node. Next, a statement, which is not in front of the condition expression in the statement instruction, is translated into a corresponding subgraph (step S508). Next, a merge node is generated (step S509) to merge the subgraphs. Next, the subgraph generated in step F is respectively linked up with the right curve point (step S510) and the merge node (step S511). At last, it is determined if an instruction is to be translated into a corresponding subgraph (step S512); if yes, step (A) is executed; and if not, a complete extended activity diagram (EAD) is output (step S513).
Accordingly, a complete Java program can be translated into a corresponding EAD, and the programming logic and executing flow of the source codes of the high level language is presented in a visualization form.
As cited, the invention adds a translation rule in a compiler to thereby translate various source codes in different high level programming languages (such as Java, C, C++ and the like) into the respective EADs automatically to thus present the programming logic and executing flow of the source codes in a visualization form. Accordingly, the various high level programming languages are integrated into a unified format for representation, which benefits a following simulation and requirement for a HDL translation.
Although the present invention has been explained in relation to its preferred embodiment, it is to be understood that many other possible modifications and variations can be made without departing from the spirit and scope of the invention as hereinafter claimed.
Number | Date | Country | Kind |
---|---|---|---|
094147586 | Dec 2005 | TW | national |