Program conversion device and storage medium
Abstract
[Task] To enable program conversion without losing comment information and program format in the program creation process. Also, the order of applying rules can be changed without rewriting the rules.
Solution.The text information of the program is accumulated at the time of lexical / syntactic analysis, and is retained in each section of the syntactic tree that is the parsing result. Then, the user can specify which syntax element type clause is to be retained. Furthermore, a type hierarchy is introduced in the syntax tree, and only rules that keep types are allowed, and conversion rules are classified and held for each type. The rewrite rule is basically described by a set of program patterns including pattern variables, the program part specified by the first pattern is rewritten to the program part of the second pattern, and further, it is made into a rule as an extended form. Add a conditional part to limit the application of rules.
Term
Term ended
Projected expiry passed 12 September 2017, 9 years ago.
- Priority
- Filed
- Published
- Projected expiry
- Today
9 claims: 2 independent, 7 dependent
- 1【特許請求の範囲】 【請求項1】 変換対象の入力プログラムとその変換ルールの構文を、構文木を構成するノードに型階層を用いた構文解析を行い、入力プログラムの構文木および変換ルールの構文木を作成する構文解析手段と、 前記入力プログラムの構文木を前記変換ルールの構文木で書き換える構文木書き換え手段と、 書き換えられた入力プログラムの構文木を変換されたプログラムとして出力する手段とを備え、 前記構文解析手段は、字句・構文解析時に入力プログラムのテキスト情報を蓄積してゆき、構文解析結果である構文木の各節に保持させることを特徴とするプログラム変換装置。
- 2【請求項2】 前記構文木書き換え手段は、関連する変換ルールの集まりをルール集合としてまとめ、競合する変換ルールを別の変換ルール集合に所属させ、変換ルール集合毎の適用順序を制御することを特徴とする請求項1記載のプログラム変換装置。
- 3【請求項3】 前記構文木書き換え手段は、型階層を保つ変換ルールのみの適用を許すことを特徴とする請求項1記載のプログラム変換装置。
- 4【請求項4】 前記変換ルールに、ルール適用の条件指定部を付加したことを特徴とする請求項1記載のプログラム変換装置。
- 5【請求項5】 前記構文木書換え手段は、適用済みルールを記録する手段を有することを特徴とする請求項4記載のプログラム変換装置。
- 6【請求項6】 前記構文木書換え手段は、プログラムの型検査を行う手段と、型検査の結果である型情報を格納する手段を有することを特徴とする請求項4記載のプログラム変換装置。
- 7【請求項7】 前記変換ルールにルール適用の付加処理を付加し、かつ前記構文木書換え手段は該付加処理を実行する付加処理手段を有することを特徴とする請求項4記載のプログラム変化装置。
- 8【請求項8】 前記構文解析手段の後段に、さらに変換ルール中にある構文木のパラメータの読み換えを行う字句解析部を有する構文解析手段を接続したことを特徴とする請求項4記載のプログラム変換装置。
- 9【請求項9】 変換対象の入力プログラムとその変換ルールの構文を、構文木を構成するノードに型階層を用いた構文解析を行い、入力プログラムの構文木および変換ルールの構文木を作成する構文解析処理を行う処理と、 前記入力プログラムの構文木を前記変換ルールの構文木で書き換える構文木書き換え処理を行う処理と、 書き換えられた入力プログラムの構文木を変換されたプログラムとして出力する処理を行う処理と、 前記構文解析処理を行うステップは、字句・構文解析時に入力プログラムのテキスト情報を蓄積してゆき、構文解析結果である構文木の各節に保持させる処理と、をコンピュータに実行させる命令を含むプログラムを格納したコンピュータが読み取り可能な記憶媒体。
Independent claims9
201 paragraphs in 1 section, as filed
Description: TECHNICAL FIELD [Detailed description of the invention]
【0001】
[Technical field to which the invention belongs]
The present invention relates to a program conversion device and a storage medium, and relates to a program conversion device and a storage medium that parse a program having a complicated syntax and rewrite the result to another program based on a rewriting rule.
【0002】
[Conventional technology]
Conventionally, as a method of converting an input program to be converted into another program, a method of regarding the input program as mere text data and using a document editing tool to rewrite the program is known. However, here, it is not assumed that the rewriting is performed in consideration of the structure of the program.
【0003】
On the other hand, for the symbol processing language Lisp, a rewriting tool that considers the structure of the program is prepared as part of the language specification and is used as standard for the purpose of introducing a new control structure. The syntax of the Lisp language is very simple and is based on the fact that the program itself is already in the form of a syntax tree. However, it cannot be applied to programs with complicated structures.
【0004】
In addition, there is C language as a representative of languages having complicated syntax. The C language also comes with a built-in rewriting tool, but this does not act on the syntax tree, but rewrites the character string by looking at the program as a sequence of character strings.
【0005】
In addition, general program conversion technology that is not limited to rewriting has been used for compilers, partial calculations, etc., but for programmers, comment information, program formats, etc. are used to facilitate lexical and parsing in these applications. Information that is useful but unnecessary for execution on the computer is deleted in advance. Since this information does not correspond to the section (syntactic element) on the syntax tree of the analysis result, it cannot be handled by the usual lexical / syntactic analysis method.
【0006】
On the other hand, as disclosed in "Automatic Program Generator" of Japanese Patent Application Laid-Open No. 5-18161, by separating the design knowledge into a part to be converted and a part not to be converted, the specifications during conversion are kept small and the search time is reduced. There is a way to reduce.
【0007】
In Japanese Patent Application Laid-Open No. 5-18161, the specifications are expressed in the form of a syntax tree for conversion, but conversion for a program is not covered by the scope of application.
【0008】
[Problems to be Solved by the Invention]
The above-mentioned conventional program conversion techniques have been used for compilers, partial calculations, etc., but in these application targets, the conversion results should be executed by a computer and were not supposed to be read or written by humans. That is, comment information, program format, etc., which are not necessary for execution on a computer but are useful information for programmers, have been deleted from the conversion result. For this reason, there is a problem that useful information in the program creation process cannot be obtained.
【0009】
Further, when expressing the conversion by the rewrite rule, it is necessary to control the conflict between the rules, but in the past, the program was rewritten according to the description order of the rules. Therefore, when changing the application order of the rules, there is a problem that the rules themselves must be rewritten, such as rewriting the contents of the rules and changing the application order by exchanging the description order.
【0010】
Also, if you try to rewrite the program by rewriting the character string with the editing function of the document editing roots or the rewriting tool built in C language, the syntax tree does not work, so conversion omission occurs or the syntax type is not maintained. There was a possibility of rewriting to a syntactically invalid program.
【0011】
Also, since all matching strings are replaced, it was not possible to convert only specific ones or dynamically generate temporary variables.
【0012】
A first object of the present invention is to provide a program conversion device capable of performing program conversion without losing comment information, program format, etc. in the program creation process.
【0013】
A second object of the present invention is to provide a program conversion device capable of changing the application order of rules without rewriting the rules.
【0014】
A third object of the present invention is to provide a program conversion device capable of guaranteeing the syntactic safety of rewriting.
【0015】
A fourth object of the present invention is to provide a program conversion device capable of controlling rule application conditions such as conversion of only a specific character string.
【0016】
A fifth object of the present invention is to provide a program conversion device capable of easily defining various rules. Specifically, (1) make it possible to limit the number of times a rule can be applied, (2) make it possible to use program type information as a rule application condition, and (3) when a rule is applied. As an additional process, it is possible to change / add matching information, and (4) it is possible to cite a program fragment in the description of the additional process of the rule.
【0017】
[Means for solving problems]
In order to achieve the first object described above, in the program conversion device of the present invention, the text information of the program is accumulated at the time of lexical / syntactic analysis and is retained in each section of the syntactic tree which is the parsing result. Then, the user can specify which syntax element type clause should be retained.
【0018】
Normally, a syntax tree rule is used as the syntax element type, but it is also possible to select a smaller element type, and text information is given to the syntax element when the syntax element of the specified type is accepted. .. The text information accumulated between the acceptance of one specified syntax element and the acceptance of the next specified syntax element is (1) the first syntax element, (2) the second syntax element, and (3). ) Holds one of these parent syntax elements in the one specified by the user. However, the comment information (comment information belonging to the whole) entered at the top level is managed independently.
【0019】
In addition, in order to achieve the second purpose, a set of related rules is grouped as a rule set, competing rules belong to another rule set, and the application order of each rule set is controlled to control the rule application. Changed to control the conflict.
【0020】
Furthermore, in order to achieve the third purpose, we will introduce a type hierarchy in the syntax tree, allow only rules that keep types, and classify and hold conversion rules for each type.
【0021】
In addition, in order to achieve the fourth purpose, the rewrite rule is basically described by a set of program patterns including pattern variables, and the program part specified by the first pattern is the program part of the second pattern. In addition, a conditional part was added to the rule as an extended format so that the application of the rule could be restricted.
【0022】
In the program conversion device of the present invention, a rewriting rule and an input program are analyzed by lexical / syntactic analysis to create a syntax tree, an attempt is made to match the (subtree) of these syntax trees, and if they match, the syntax tree follows the rule. Is rewritten, a program is created from the result, and it is output. At this time, if the condition part exists in the rule, the condition part is evaluated, and if the evaluation result is false, it is treated in the same manner as the matching failure. In addition, a new pattern variable can be introduced in the condition section, which can be used in the output pattern. This allows the use of dynamic temporary variables.
【0023】
When the matching fails, the result program is output based on the retained text information. This makes it possible to prevent loss of comment information and the like. Top-level comments are output to their original positions.
【0024】
When there is a conflict between rules, you can explicitly control the rewrite order by declaring the rewrite strategy and changing the rewrite strategy, or by dividing the rule with the conflict so that it belongs to another rule set. You can.
【0025】
Since the rules are classified and held for each type, the applicable rules can be selected according to the node type of the input syntax subtree, and the rule application can be speeded up.
【0026】
In addition, since each rule maintains the node type, the rewritten output syntax part also has the same syntax type, and the same syntax is maintained even after conversion.
【0027】
Furthermore, in order to achieve the fifth purpose, the following extended form of the rewriting rule can be handled.
【0028】
(1) Introduced a means to record whether the rule has been applied, and made it possible to judge whether the rule has been applied in the condition part of the rule definition. This allows, for example, to be applied only once, regardless of whether the rule is further applicable.
【0029】
(2) Introduced a means to perform type inspection of the program and a means to store the type information that is the result of the type inspection, so that the type information can be referred to in the condition part of the rule. This makes it possible to handle conditions related to the type of an expression.
【0030】
(3) An additional processing unit has been added to the rule so that the match information of the pattern variable can be referred to, changed, or added when the rule is applied.
【0031】
(4) Introduced a program in which two parsers are connected in a cascade. However, while one is a normal parser, the other has a lexical analyzer that replaces pattern variables that are parameters of the syntax tree. This is because, for example, when a pattern variable declared as Expression appears in a program fragment in the rule definition, it is treated as Expression. This makes it possible to cite a piece of the program in the description of the additional processing of the rule.
【0032】
BEST MODE FOR CARRYING OUT THE INVENTION
Hereinafter, embodiments of the present invention will be described with reference to the drawings. FIG. 1 is a schematic diagram showing processing and data flow in an information processing system configured as an embodiment of the present invention.
【0033】
In FIG. 1, the syntax of the input program 102 to be converted and its conversion rule 103 is parsed using the type hierarchy for the nodes constituting the syntax tree, and the syntax tree 104 of the input program 102 and the syntax tree of the conversion rule 103 are parsed. A parser 101 that creates 105 (hereinafter referred to as a syntax tree rewriting rule), a syntax tree rewriting device 106 that rewrites the syntax tree of the input program 102 with the syntax tree of the rewriting rule 105, and a syntax machine of the rewritten input program 102. It is provided with an output processing device 108 that outputs 107 as a converted program 109.
【0034】
The syntax tree rewriting device 106 compares the syntax tree 104 of the input program 102 with the syntax tree of the syntax tree rewriting rule 105, and is there a node in the syntax tree 104 of the input program that applies to each node of the syntax tree of the rewriting rule 105? Check whether or not, and the applicable node performs the operation of rewriting with the syntax tree of the rewrite rule 105.
【0035】
The programs 102 and 109 conversion rule 103 may be stored in a portable storage medium such as a floppy disk (FD), respectively. Further, the parsing device 101 and the parsing tree rewriting device 106 and the output processing device 108 may be stored in FD and MO (magneto-optical disk) as software that performs the same processing as the devices, respectively.
【0036】
In this embodiment, C language is selected as the programming language to be converted, and parsing can be easily realized because a parser known as a standard parser generator (Lex, Yacc) can be used. Is.
【0037】
Figure 2 shows the algorithm for rewriting the syntax tree. First, the parser Parse is called to obtain the syntax tree 104 (TP) of the program P to be converted (step 301). Then select the subtree TP'to be rewritten next from the syntax tree 104 (TP) (step 302). This selection depends on the rewriting strategy, and several types of strategies such as innermost rewriting and outermost rewriting are known, but the strategy to be adopted can be switched by the declaration statement "#define_rewrite_strategy" of the rewriting strategy. (The default is the innermost rewrite).
【0038】
When there is no subtree to be rewritten, "False" is returned as the value of TP', so it ends and returns TP as the syntax tree of the rewriting result (steps 303, 311).
【0039】
If not, use "get_rule" to retrieve a set of rules that can be applied to TP'(step 304). If the set of rules is NIL (step 305), the process returns to step 302.
【0040】
"Get_rule" is a function that retrieves a set of applicable rules according to the root node type of the given syntax tree. The rules that are the elements of this rule set are (A, B, C) three sets. However, A is the input pattern specification, B is the condition part, and C is the output pattern specification.
【0041】
A, B, and C are all described in C language syntax, but pattern variables can be used in the syntax, and matching and instantiation are performed for these pattern variables.
【0042】
The rule is applied to the rule (the first one) in which the syntax tree TA of the parsing result of A matches TP'and the condition part B succeeds. To apply the rule, first create a variable bound bind of the pattern variable from the matching of TA and TP'(step 306), and under this variable bound, evaluate the intermediate processing designation B by the condition part evaluation device Eval, and make a new one. Get the variable binding "new_bind" (step 308). If "bind" is "false" (step 307), then this rule is not applicable and we return to step 305.
【0043】
Construct an instantiated pattern variable in the syntax tree TC of the output pattern C with "new_bind" and replace the subtree TP'in the TP with this (step 310). If the intermediate process fails, "new_bind" becomes "false" (step 309), so the process returns to step 302. The above process is repeated until there is no rewritable subtree TP'.
【0044】
Figure 3 shows an example of rule description. Pattern variables are represented by prefixing them with "@", such as "@x".
【0045】
Figure 3 (a) is an example of defining a function "foo" that can take an indefinite number of arguments using a two-argument function "bar".
【0046】
Figure 3 (b) is an example of convolving a character set-dependent conditional branch into a dedicated function "islower".
【0047】
Figure 3 (c) is an example of rewriting the C function definition of the original specification to the definition with the latest ANSI-compatible prototype.
【0048】
Figures 4 to 6 show the storage status of text information when the conversion rule is applied. Figure 4 shows the case where the conventional method is applied, and the comment 41 to 45 information is lost even for the program to which the rewriting rule is not applied.
【0049】
Figure 5 shows the case where text information is stored in each top-level syntax tree (that is, function definition statement or type declaration statement). The rewritten function definition statement loses comment information as in Figure 4, but is rewritten. The text information 51 and 52 is retained as is for the second function definition statement to which the rule is not applied.
【0050】
FIG. 6 shows a case where the text information is provided in each "statement" unit, and the text information between the "statements" is retained in the immediately preceding "statement".
【0051】
As in the case of FIG. 5, the text information 61 and 62 is retained as it is for the second function definition statement, and the comment 63 before entering the function definition body is retained for the first function definition statement.
【0052】
Figure 7 shows an example of a rule that specifies the condition part. Figure 7 (a) is an example used for optimization by code movement. When the end judgment of the "for" statement is a complicated expression, it is not evaluated every time, but it is evaluated only once in advance and the value is held in the dynamically generated temporary variable, and the end judgment is made. It is rewritten so that it is done with that variable value.
【0053】
Whether or not it is a complicated variable value is judged by a judgment function called "complex_expression_p", and if it passes the judgment, it proceeds to rewriting, but if not, it calls the system function "fail" of the condition part and calls the matching process itself. It fails and does not proceed to rewriting. In addition, temporary variables are dynamically generated using the system function "gensym" to avoid collision of variable names with other variables.
【0054】
Here, "gensym" is a function that takes a character string as an argument and generates a new variable name using that character string. For example, when gensym ("work") is called, variable names such as "work0001", "work0002", ... are newly generated and returned each time they are called.
【0055】
Figure 7 (b) is an example of converting the path name when porting. Depending on the platform, the length of the path name may be limited. In this rule, the code using the path name is caught by pattern matching, and the function "shorten_path_name" that shortens the length of the path name is called in the condition part and rewritten to this.
【0056】
Figure 8 (a) is an example of defining a macro that takes a type name as an argument. "Swap" is a macro that takes a type name as the first argument and a variable name as the second and third arguments, and exchanges the values of those variables. Here, too, "gensym" is called in the condition part to generate a temporary variable for exchange.
【0057】
Figure 8 (b) is an example of defining a control structure. Here, the control structure "dotimes" that receives the expression and the statement and executes the statement as many as the result of evaluating the expression is defined. "Dotimes" described in the program is rewritten (compiled) into a "for" statement according to this rule, and then executed. However, since it is necessary to teach the parser that the variable name "dotimes" is used as a control structure, it is declared with the "#declare_control_stmt" statement before the rule definition.
【0058】
9 to 11 are examples of conflict control. There is a conflict between the two rules. For example, both rules can be applied to the expression "foo (bar (x))", so the conversion result will differ depending on the application order. Figure 9 shows the case where "innermost" is specified in the "#define_rewrite_stragy" declaration, and the rewrite candidate "bar (x)" inside the expression "foo (bar (x))" comes first. The result is "foo (bar (x))" because it is rewritten to. Since the default of rewriting is "innermost", this rewriting is executed when no declaration is made.
【0059】
Figure 10 shows the case where "outermost" is specified in the "#define_rewrite_stragy" declaration, the expression "foo (bar (x))" is rewritten from the outside, and the result is "foobar (x)". Become.
【0060】
FIG. 11 shows a control method using division of rule sets 1 and 2. By dividing the two rules 1 and 2 into separate rule sets, the order of application can be explicitly specified.
【0061】
(Second Embodiment of the Invention) The second embodiment of the present invention will be described. The second embodiment is basically the same as that of the first embodiment, but as shown in the block diagram of FIG. 12, the syntax tree rewriting device 106 is shown in the block diagram of FIG. It is composed of a match information 111, a rewrite condition determination device 112, a rewrite result generation device 113, and an applied rule recording device 114.
【0062】
The pattern matching device 110 processes steps 301 to 307 in the flowchart of FIG. The rewrite condition determination device 112 processes steps 308 to 309. The rewrite result generator 113 processes step 310. The match information 111 is a variable binding bind or new_bind of the pattern variable generated in step 306 or step 308. The above is the same as that of the first embodiment.
【0063】
In the present embodiment, the applied rewrite rule is further recorded in the applied rule recording device 114 after the processing in step 310 of FIG. This record can be referenced in the Conditional Section of the Rewrite Rule. This makes it possible to create a rewrite rule that does not apply once it has already been applied.
【0064】
(Third Embodiment of the invention) The third embodiment of the present invention will be described. The third embodiment is basically the same as that of the first embodiment, but as shown in the block diagram of FIG. 13 for the syntax tree rewriting device 106 in the block configuration diagram of FIG. 1, the pattern matching device 110, It is composed of match information 111, rewrite condition determination device 112, rewrite result generation device 113, type inspection device 115, and type information 116. The flow chart of the basic processing is the same as in FIG.
【0065】
In this embodiment, a type inspection step is further performed by the type inspection apparatus 115 between steps 307 and 308 of FIG. The type information 116 obtained by this type inspection step can be referred to in the condition part of the rewrite rule. As a result, it becomes possible to create a rewriting rule using the type information of the program as a rewriting condition.
【0066】
FIG. 14A is an example of a rewriting rule that is possible when both the second and third embodiments are implemented at the same time. This rewriting rule is for rewriting the program, for example, for the purpose of debugging the program, so that the contents of the variable of the character string are displayed particularly during the execution of the program. If there is an assignment statement for a variable in the character string, insert a print statement 141 to display the variable immediately after the assignment statement.
【0067】
Once this rewrite rule has been applied, it must not be applied any further. This is because the printed text is inserted endlessly. Therefore, in the condition section, the information of the applied rule recording device 114 of the second embodiment is referred to by the function "applied ()", and if it has already been applied, the rule application fails.
【0068】
Moreover, since the print statement for displaying the variable differs depending on the type of the variable, only the case of the character string type variable is dealt with here. In the condition part, the type of the variable is checked by the function "type_of ()" for the type information 116 obtained in the third embodiment, and the rule application fails unless it is a character string type (char *). There is. Figure 14 (b) shows before debugging, and Figure 14 (c) shows after debugging.
【0069】
(Fourth Embodiment of the Invention) The fourth embodiment of the present invention will be described. The fourth embodiment is basically the same as that of the first embodiment, but as shown in the block diagram of FIG. 15 for the syntax tree rewriting device 106 in the block configuration diagram of FIG. 1, the pattern matching device 110, It is composed of a match information 111, a rewrite condition determination device 112, a rewrite result generation device 113, and an additional processing device 117. The flow chart of the basic processing is the same as in FIG.
【0070】
In the present embodiment, the format of the description of the rewriting rule is further expanded, and an additional processing unit that can refer to, add, and change the variable binding of the pattern variable is added. Further, a step in which the additional processing unit is executed by the additional processing device 117 is inserted between steps 309 and 310 in FIG. The variable binding of the pattern variable obtained by this additional processing step becomes new_bind again and is used in step 310.
【0071】
Such additional processing can also be described in the condition section. However, the structure of the rewriting rule can be clarified by describing the processing unrelated to the condition determination and the processing to be performed after the condition determination in the addition processing unit.
【0072】
(Fifth Embodiment of the Invention) The fifth embodiment of the present invention will be described. The fifth embodiment is basically the same as that of the first embodiment, but as shown in the block diagram of FIG. 16 for the parser 101 in the block configuration diagram of FIG. 1, the lexical analyzer (1) It is composed of 118, lexical analyzer (2) 119, lexical buffer 120, parser (1) 121, and parser (2) 122. The flow chart of the basic processing is the same as in FIG.
【0073】
Except for the lexical analyzer (2) 119 and the parser (2) 122 from FIG. 16, it is a normal parser. The parsing of the program is performed in the same manner as in the first embodiment without using the lexical analyzer (2) 119 and the parser (2) 122. As for the parsing of conversion rules, the example rules mentioned so far are parsed without using the lexical analyzer (2) 119 and the parser (2) 122.
【0074】
In the present embodiment, the description format of the conversion rule is further expanded so that the additional processing unit can cite a program fragment and use it for changing / adding the binding of the pattern variable. A lexical analyzer (2) 119 and a parser (2) 122 are used to parse the quoted part of this program fragment.
【0075】
When parsing a conversion rule that has a quoted part of a program fragment, normal processing is performed by the lexical analyzer (1) 118, the lexical buffer 120, and the syntactic analyzer (1) 121 until the quoted part of the program fragment appears. Is done. The parser (1) 121 transfers control to the parser (2) 122 when the quoted portion of the program fragment appears. The parser (2) 122 proceeds with parsing until the quoted part of the program fragment is completed, stores the syntactic tree of the obtained program fragment as lexical in the lexical buffer 120, and controls it to the parser (1) 121. Return. The parser (1) 121 can acquire the syntax tree of the program fragment as lexical from the lexical buffer 120 and proceed with normal parsing.
【0076】
While the parser (2) 122 is parsing the citation of the program fragment, the words obtained by the lexical analyzer (1) 118 are further stored in the lexical buffer 120 through the lexical analyzer (2) 119. The lexical analyzer (2) 119, for example, when a pattern variable @x declared as "expr @x" appears, replaces it with the phrase EXPR_PATTERN instead of just a pattern variable. By defining the syntax so that it is recognized as expr when the lexical EXPR_PATTERN appears, @x can be recognized as expr.
【0077】
FIG. 17 is an example of a rewriting rule that is possible when both the fourth and fifth embodiments are implemented at the same time. This rule is for performing the same processing as the rule for rewriting the function definition of C shown in Fig. 3 (c). In FIG. 3 (c), the processing performed by the special function "make_arg_decls ()" in the condition section is performed in the additional processing section surrounded by the frame 171 in FIG. In this additional processing unit, the program fragment shown in the first underlined part 172 creates an empty new argument list "new_args", and then the second element of the original argument list is traced one by one. By quoting the program fragment shown in the underlined part 173, the corresponding argument declaration is newly created and added to "new_args". By introducing the additional processing unit and the citation of the program fragment in this way, it is possible to easily define a complicated rewriting rule without using a special function.
【0078】
[Effect of the invention]
As described above, according to the present invention, it is possible to perform program conversion while minimizing the loss of text information such as comment information in the program creation process. In particular, top-level comment information can be retained as is. In addition, the concept of rewriting strategy specification and rule set makes it easy to control conflicts between rules, and the order of applying rules can be changed without rewriting the rules themselves. In addition, syntactic security in the conversion is ensured because each rewrite retains its syntax. Furthermore, since the rule has a condition part, it is possible to introduce incidental conditions and temporary variables for rule establishment, further define the control structure, and perform control such as converting only a specific character string. .. Therefore, by preparing such a rewriting rule, it can be used for program porting, modification, development, management, etc., and further, by accumulating the rewriting rule, the efficiency of software development can be improved.
【0079】
In addition, there is a means to record whether the rule has been applied, and the condition part of the rule definition can determine whether the rule has been applied, so it is only once regardless of whether the rule is further applicable or not. Can be applied. Furthermore, since the type information can be referred to in the condition section, the condition related to the type of the expression can be used for controlling the rule. In addition, since the rule has an additional processing unit, the structure of the rule can be clarified. Further, an effect such as being able to cite a program fragment in the additional processing unit of the rule can be obtained.
[Simple explanation of drawings]
[Figure 1]
It is a block block diagram which shows the embodiment of this invention.
[Figure 2]
It is a flowchart which shows the rewriting algorithm of a syntax tree.
[Fig. 3]
It is a figure which shows the description example of a rewrite rule.
[Fig. 4]
It is a figure which shows the storage state of the text information when a rewrite rule is not applied.
[Fig. 5]
It is a figure which shows the example which the text information is stored in the top-level syntax tree unit.
[Fig. 6]
It is a figure which shows the example which saves the text information for each statement.
[Fig. 7]
It is a figure which shows the example used for the optimization by code movement, and the example which converts the path name at the time of porting.
[Fig. 8]
It is a figure which shows the example which defines the macro which takes a type name as an argument, and the example which defines a control structure.
[Fig. 9]
It is a figure which shows the conversion result at the time of specifying the innermost rewrite in the case of performing conflict control.
[Fig. 10]
It is a figure which shows the conversion result at the time of specifying the outermost rewrite in the case of performing conflict control.
[Fig. 11]
It is a figure which shows the control example which used the division of a rule set.
[Fig. 12]
It is a detailed block diagram of the syntax tree rewriting apparatus 106 of the 2nd Embodiment.
[Fig. 13]
It is a detailed block diagram of the syntax tree rewriting apparatus 106 of the 3rd Embodiment.
[Fig. 14]
It is a figure which shows the example of the conversion rule for the 2nd and 3rd embodiments.
[Fig. 15]
It is a detailed block diagram of the syntax tree rewriting device 106 of the 4th embodiment.
[Fig. 16]
It is a detailed block diagram of the parser 101 of the fifth embodiment.
[Fig. 17]
It is a figure which shows the example of the conversion rule for the 4th and 5th embodiments.
[Explanation of symbols]
101 ... parser, 102 ... input program to be converted, 103 ... conversion rule, 104 ... syntax tree, 105 ... syntax tree rewriting rule, 106 ... syntax tree rewriting device, 107 ... rewritten syntax tree, 108 ... output processor, 109 ... converted program, 110 ... pattern match device, 111 ... match information, 112 ... rewrite condition judgment device , 113 ... Rewrite result generator, 114 ... Applied rule recording device, 115 ... Type inspection device, 116 ... Type information, 117 ... Additional processing device, 118 ... Phrases analysis device (1), 119 ... Phrase analyzer (2), 120 ... Phrase buffer, 121 ... Parser (1), 122 ... Parser (2).
Every citation, both ways
| Document | Relation | Office | Cited during |
|---|---|---|---|
| US9710243B2 | Cited by | United States of America | Applicant |
| CN114791812A | Cited by | China | Search report |
| WO2022234675A1 | Cited by | World Intellectual Property Organization (WIPO) | International search |
7 priority claims, no other members on record
Priority claims7
| Document | Office | Kind | Date |
|---|---|---|---|
| 25837096 | Japan | A | |
| 25837096 | Japan | A | |
| 8258370 | Japan | – | |
| 24794097 | Japan | A | |
| 258370 | – | – | – |
| JP19960258370 | – | – | – |
| JP19970247940 | – | – | – |
Numbers
- Publication
- 10-154079
- Publication, DOCDB
- H10154079
- Publication, EPODOC
- JPH10154079
- Application
- 9247940
- Application, DOCDB
- 24794097
- Application, EPODOC
- JP19970247940
Titles2
- Japanese
- 【発明の名称】プログラム変換装置および記憶媒体
- English
- [Title of Invention] Program converter and storage medium
Classification
- IPC, 2
- G06F9 06
- G06F9 45