JPH08272622A - Program conversion device - Google Patents

Program conversion device

Info

Publication number
JPH08272622A
JPH08272622A JP7666295A JP7666295A JPH08272622A JP H08272622 A JPH08272622 A JP H08272622A JP 7666295 A JP7666295 A JP 7666295A JP 7666295 A JP7666295 A JP 7666295A JP H08272622 A JPH08272622 A JP H08272622A
Authority
JP
Japan
Prior art keywords
syntax tree
program
rule
syntax
conversion
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP7666295A
Other languages
Japanese (ja)
Inventor
Mutsumi Komuro
睦 小室
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hitachi Software Engineering Co Ltd
Original Assignee
Hitachi Software Engineering Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hitachi Software Engineering Co Ltd filed Critical Hitachi Software Engineering Co Ltd
Priority to JP7666295A priority Critical patent/JPH08272622A/en
Publication of JPH08272622A publication Critical patent/JPH08272622A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

PURPOSE: To attain the conversion of a program without using a complicated description rule by analyzing the syntax of a conversion rule as well as an input program to be converted to prepare a syntax tree of the conversion rule for the input program and then rewriting the syntax tree of the input program by means of the syntax tree of the conversion rule. CONSTITUTION: A syntax tree analysis device 101 analyzes the syntax tree of an input program 102 to be converted and the syntax of a conversion rule 103 and prepares a syntax tree 104 and the syntax tree of the rule 103. The syntax tree of the program 102 is rewritten by the syntax tree of a syntax tree rewriting rule 105. The rewritten syntax tree 107 of the program 102 is outputted by an output device 108 as a converted program 109. In other words, a syntax tree rewriting device 106 compares the tree 104 of the program 102 with the syntax tree of the rule 105 to check whether the nodes conformable to every node of the syntax tree of the rule 105 are included in the tree 104. Then the conformable nodes are rewritten by means of the syntax tree of the rule 105.

Description

【発明の詳細な説明】Detailed Description of the Invention

【0001】[0001]

【産業上の利用分野】本発明は、プログラム変換装置に
関し、特に複雑な構文を持った入力プログラムを構文解
析し、その結果を変換ルールに基づき別のプログラムへ
変換するプログラム変換装置に関するものである。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a program conversion device, and more particularly to a program conversion device which parses an input program having a complicated syntax and converts the result into another program based on a conversion rule. .

【0002】[0002]

【従来の技術】従来において、変換対象の入力プログラ
ムを別のプログラムへ変換する方法として、入力プログ
ラムを単なるテキストデータと見做し、文書編集ツール
をプログラムの書換えに援用する方法が知られている。
2. Description of the Related Art Conventionally, as a method of converting an input program to be converted into another program, there is known a method in which the input program is regarded as simple text data and a document editing tool is used for rewriting the program. .

【0003】また、記号処理用言語Lispに対しては
プログラムの構造を考慮した書換えツールが言語仕様の
一部として用意され、新しい制御構造の導入の目的に標
準的に用いられているが、これはLisp言語の構文が
非常に簡単で、プログラムそのものがすでに構文木の形
をしているという事実に着目したものである。
For the symbol processing language Lisp, a rewriting tool considering the structure of the program is prepared as a part of the language specification and is used as a standard for the purpose of introducing a new control structure. Focuses on the fact that the Lisp language has a very simple syntax and the program itself is already in the form of a syntax tree.

【0004】一方、特開平5−181651号の「プロ
グラム自動生成装置」に開示されているように、設計知
識を変換対象部分と変換対象にならない部分に分離する
ことにより、変換途中の仕様を小さく保ち、検索時間を
削減する方法がある。
On the other hand, as disclosed in Japanese Patent Application Laid-Open No. 5-181651, "Automatic Program Generator", by separating the design knowledge into a conversion target part and a non-conversion target part, the specifications in the middle of conversion can be reduced. There are ways to keep and reduce search time.

【0005】[0005]

【発明が解決しようとする課題】しかしながら、上記従
来技術にあっては、構文木の構造、特に複雑な構造の通
常のプログラムを変換対象として考慮していないため、
このようなプログラムを変換することは不可能である。
However, in the above-mentioned prior art, since the structure of the syntax tree, in particular, the normal program having a complicated structure is not considered as the conversion target,
It is impossible to convert such a program.

【0006】一方、ソフトウェア開発に実際用いられて
いるプログラミング言語の構文は複雑であり、正確な構
文解析を行おうとすると、解析ルーチンが大規模とな
り、解析結果である構文木も複雑なものとなってしま
う。
On the other hand, the syntax of a programming language actually used for software development is complicated, and if an accurate parsing is attempted, the parsing routine becomes large and the parsing tree as the parsing result becomes complicated. Will end up.

【0007】これは、プログラム変換装置を実現しよう
とするとき、構文解析部の実現が困難であることのみで
はなく、構文木書換え用の変換ルールを記述しようとす
る時に、ルールの記述が煩雑な形になってしまうことを
意味している。
This is because not only is it difficult to implement a syntax analysis unit when implementing a program conversion device, but the description of rules is complicated when describing conversion rules for rewriting syntax trees. It means that it becomes a shape.

【0008】また、変換ツールを用いて新しい制御構造
を定義しようとする時、構文解析があまりにも厳密であ
ると、定義しようとしている新しい制御構造の解析が構
文エラーとなり、構文木の書換えの形では実現できなく
なるという問題がある。
Further, when trying to define a new control structure using a conversion tool, if the parsing is too strict, the parsing of the new control structure to be defined will result in a syntax error and the form of rewriting the syntax tree There is a problem that can not be realized in.

【0009】本発明の目的は、複雑な構造のプログラム
を、煩雑な記述のルールを用いることなく別のプログラ
ムに変換することができるプログラム変換装置を提供す
ることにある。
An object of the present invention is to provide a program conversion device capable of converting a program having a complicated structure into another program without using a complicated description rule.

【0010】[0010]

【課題を解決するための手段】上記目的を達成するた
め、本発明のプログラム変換装置は、変換対象の入力プ
ログラムとその変換ルールの構文を、構文木を構成する
ノードに型階層を用いた構文解析を行い、入力プログラ
ムの構文木および変換ルールの構文木を作成する構文解
析手段と、前記入力プログラムの構文木を前記変換ルー
ルの構文木で書き換える構文木書き換え手段と、書き換
えられた入力プログラムの構文木を変換されたプログラ
ムとして出力する出力手段とを備えることを特徴とす
る。
In order to achieve the above object, the program conversion device of the present invention uses the syntax of an input program to be converted and the syntax of its conversion rule, in which a type hierarchy is used for nodes constituting a syntax tree. Parsing means for performing an analysis and creating a syntax tree of an input program and a syntax tree of a conversion rule, a syntax tree rewriting means for rewriting the syntax tree of the input program with the syntax tree of the conversion rule, and the rewritten input program And an output unit for outputting the syntax tree as a converted program.

【0011】そして、構文解析手段は、変換対象の入力
プログラムの構文に一致した変換ルールの構文木を出力
することを特徴とする。
The syntax analyzing means outputs the syntax tree of the conversion rule which matches the syntax of the input program to be converted.

【0012】[0012]

【作用】上記手段によれば、入力された変換対象のプロ
グラムを変換ルールに従って構文解析し、変換対象のプ
ログラムの構文木を得る。
According to the above means, the input conversion target program is parsed according to the conversion rule to obtain the syntax tree of the conversion target program.

【0013】同様に、変換ルール自体も構文解析し、変
換ルールの構文木を得る。
Similarly, the conversion rule itself is also parsed to obtain the syntax tree of the conversion rule.

【0014】次に、プログラムの構文木に構文木化され
た変換ルールを適用し、書換えられたプログラムの構文
木を得る。
Next, the syntax tree conversion rule is applied to the syntax tree of the program to obtain the syntax tree of the rewritten program.

【0015】最後に、書換えられた構文木を、変換され
たプログラムとして出力する。
Finally, the rewritten syntax tree is output as a converted program.

【0016】ここで、構文解析手段は、構文木を構成す
るノードに型階層を用いた構文解析を行う。構文木のノ
ードに型階層を導入した場合、構文木において上位型の
ノードが出現可能である下位型のノードが出現すること
も許す。これにより、構文解析ルーチンは上位型のノー
ドのみが出現する簡約化された構文木を出力すればよい
ことになり、処理が楽になる。
Here, the syntactic analysis means performs syntactic analysis using the type hierarchy for the nodes forming the syntactic tree. When the type hierarchy is introduced to the nodes of the syntax tree, it is possible to allow the nodes of the lower type where the nodes of the upper type can appear in the syntax tree. As a result, the syntactic analysis routine only needs to output a simplified syntactic tree in which only upper-type nodes appear, which facilitates processing.

【0017】さらに、構文木の変換ルールを型に応じて
記述するオブジェクト指向プログラミングが可能とな
り、変換ルールの記述と処理が簡単かつ明確となる。
Further, it becomes possible to perform object-oriented programming in which the conversion rule of the syntax tree is described according to the type, and the description and processing of the conversion rule become simple and clear.

【0018】構文木を簡約化したことから解析結果にあ
いまいさが生じる場合があるが、これはあいまいさを持
ち得るノード型に対して、あいまいさの解消ルールを与
えることで解決する。
Ambiguity may occur in the analysis result due to the reduction of the syntax tree, but this can be solved by giving a ambiguity resolution rule to the node type that may have ambiguity.

【0019】また、構文木の変換ルールとして、変換対
象となっているプログラミング言語と同じ構文を用い、
プログラム変換装置全体も対象プログラミング言語を用
いて作成すると、プログラム変換装置を自分自身に適用
することが可能となり、オペレーティングシステムが異
なる機種のプログラムへの移植、拡張を容易に行うこと
ができる。
Further, as the conversion rule of the syntax tree, the same syntax as the programming language to be converted is used,
If the entire program conversion device is also created using the target programming language, it becomes possible to apply the program conversion device to itself, and it is possible to easily perform porting and expansion to programs of different models having different operating systems.

【0020】[0020]

【実施例】以下、図を用いて本発明の一実施例について
説明する。
An embodiment of the present invention will be described below with reference to the drawings.

【0021】図1は、本発明の一実施例を示すブロック
構成図であり、変換対象の入力プログラム102とその
変換ルール103の構文を、構文木を構成するノードに
型階層を用いた構文解析を行い、入力プログラム102
の構文木104および変換ルール103の構文木(以
下、構文木書換えルールという)105を作成する構文
解析装置101と、入力プログラム102の構文木を書
換えルール105の構文木で書換える構文木書き換え装
置106と、書き換えられた入力プログラムの構文木1
07を変換されたプログラム109として出力する出力
装置108とを備えている。
FIG. 1 is a block diagram showing an embodiment of the present invention. The syntax of an input program 102 to be converted and its conversion rule 103 is parsed by using a type hierarchy for nodes constituting a syntax tree. Input program 102
Syntax tree 104 and a syntax tree 101 of the conversion rule 103 (hereinafter referred to as a syntax tree rewriting rule), and a syntax tree rewriting apparatus rewriting the syntax tree of the input program 102 with the syntax tree of the rewriting rule 105. 106 and syntax tree 1 of the rewritten input program
And an output device 108 that outputs 07 as the converted program 109.

【0022】構文木書き換え装置106は、入力プログ
ラムの構文木104と構文木書き換えルール105の構
文木を比較し、書き換えルール105の構文木の各ノー
ドに当てはまるノードが入力プログラムの構文木104
にあるか否かを調べ、当てはまるノードは書換えルール
105の構文木で書換える操作を行うものである。
The syntax tree rewriting device 106 compares the syntax tree 104 of the input program with the syntax tree of the syntax tree rewriting rule 105, and the node corresponding to each node of the syntax tree of the rewriting rule 105 is the syntax tree 104 of the input program.
Is checked, and the applicable node performs the rewriting operation with the syntax tree of the rewriting rule 105.

【0023】本実施例では、変換対象とするプログラミ
ング言語としてC言語を選び、構文解析は、標準的なパ
ーザ生成装置(Lex,Yacc)等の名称で知られて
いる構文解析装置を使用できるので、実現が容易であ
る。
In this embodiment, the C language is selected as the programming language to be converted, and the syntactic analysis can be performed by using a syntactic analysis device known by the standard parser generation device (Lex, Yacc) or the like. , Easy to implement.

【0024】しかし、C言語の構文は、文脈自由文法で
は解析しきれないことが知られており、解析結果である
構文木104には誤りのある可能性がある。しかし、こ
の誤りの出現箇所は限られており、C言語の場合は複文
の最初の部分において宣言文と実行文を解析し間違える
場合だけである。
However, it is known that the syntax of C language cannot be completely parsed by the context-free grammar, and there is a possibility that the syntax tree 104 as the analysis result has an error. However, the places of occurrence of this error are limited, and in the case of C language, it is only when the declaration statement and the execution statement are analyzed and mistaken in the first part of the compound statement.

【0025】そこで、複文を示す構文木ノードの型に訂
正ルールを与えることで、この誤りを訂正する。訂正ル
ールは、このシステムのユーザが記述する変換ルールの
先頭に自動的に付加される。
Therefore, this error is corrected by giving a correction rule to the type of the syntax tree node indicating the compound sentence. The correction rule is automatically added to the beginning of the conversion rule described by the user of this system.

【0026】C言語に対する厳密な構文木を作成しよう
とすると、構文木のノードは100種類程度必要になる
が、型階層を導入することで10種類程度のノード型か
らなる構文木に簡約化できる。
To create a strict syntax tree for the C language, about 100 kinds of syntax tree nodes are required, but by introducing a type hierarchy, it is possible to simplify the syntax tree to about 10 kinds of node types. .

【0027】例えば、実行文は、通常の構文木では、ラ
ベル付き実行文、式、複文、条件文、繰り返し文、ジャ
ンプ文、代入式、論理式など30以上の種類が必要とな
るが、この実施例では図2に示すような型階層を用いて
おり、ノードの種類は実行文201、複文202、制御
文203、条件文204、繰返し分205の5種類で済
んでいる。
For example, in an ordinary syntax tree, there are required 30 or more types of executable statements such as labeled executable statements, expressions, compound statements, conditional statements, repeated statements, jump statements, assignment expressions, and logical expressions. In the embodiment, the type hierarchy as shown in FIG. 2 is used, and the types of nodes are five types: the execution statement 201, the compound statement 202, the control statement 203, the conditional statement 204, and the repetition 205.

【0028】このうち制御文203は条件文201、繰
り返し文205の上位型となるノード型として導入した
もので、元の構文木にはなかったノード型である。
Of these, the control statement 203 is introduced as a node type that is a supertype of the conditional statement 201 and the repetition statement 205, and is a node type that was not found in the original syntax tree.

【0029】通常の構文解析では、条件文、繰り返し文
の解析処理がキーワード(if,while,forな
ど)をチェックするので、新しい制御構造を定義すると
構文解析がエラーとなってしまう。
In the normal syntax analysis, the analysis processing of the conditional statement and the repeated statement checks the keywords (if, while, for etc.), so that the syntax analysis results in an error if a new control structure is defined.

【0030】これに対し、本実施例では、制御文203
という上位型で解析を止めているのでエラーとなること
はなく、新しい制御構造の定義が可能となる。
On the other hand, in this embodiment, the control statement 203
Since the analysis is stopped by the upper type, no error will occur and a new control structure can be defined.

【0031】図3に、構文木書換えのアルゴリズムを示
している。
FIG. 3 shows an algorithm for rewriting a syntax tree.

【0032】まず、構文解析装置101(Parse)
を呼び、変換対象のプログラム102(P)の構文木1
04(TP)を得る(ステップ301)。
First, the syntax analysis device 101 (Parse)
, And the syntax tree 1 of the program 102 (P) to be converted
04 (TP) is obtained (step 301).

【0033】次に、構文木104(TP)から次に書き
換えるべき部分TP’を選択する(ステップ302)。
この選択は書換えの戦略に依存し、最内書換え、最外書
換えなど数種類の戦略が知られているが、採用する戦略
は大域変数「strategy」の値により切り換える
ことができる(デフォルトは最内書換えを採用してい
る)。
Next, the part TP 'to be rewritten next is selected from the syntax tree 104 (TP) (step 302).
This selection depends on the rewriting strategy, and several kinds of strategies such as innermost rewriting and outermost rewriting are known, but the strategy to be adopted can be switched by the value of the global variable "strategy" (default is the innermost rewriting. Has been adopted).

【0034】書き換えるべき部分木がないときには、T
P’の値として「False」が返るので、終了してT
Pを書換え結果の構文木として返す(ステップ303,
311)。
When there is no subtree to be rewritten, T
Since "False" is returned as the value of P ', the processing ends and T
Return P as a syntax tree of the rewriting result (step 303,
311).

【0035】そうでないときは、TP’に適用できるル
ールの集合を「get_rule」により取り出す(ス
テップ304)。「get_rule」は与えられた構
文木のルートノードの型によって適用可能ルール集合を
取り出す関数である。このルール集合の要素であるルー
ルは、(A,B,C)の3組である。
If not, the set of rules applicable to TP 'is retrieved by "get_rule" (step 304). “Get_rule” is a function that extracts an applicable rule set according to the type of the root node of a given syntax tree. The rules that are the elements of this rule set are three sets of (A, B, C).

【0036】ただし、Aは入力パターン指定、Bは中間
処理指定、Cは出力パターン指定である。
However, A is an input pattern designation, B is an intermediate processing designation, and C is an output pattern designation.

【0037】A,B,C共に、C言語の構文で記述する
が、構文中にパターン変数を用いることができ、このパ
ターン変数に関してマッチングとインスタンシエーショ
ンが行われる。
Although each of A, B, and C is described in the syntax of C language, a pattern variable can be used in the syntax, and matching and instantiation are performed on this pattern variable.

【0038】Aの構文解析結果の構文木TAがTP’と
マッチし、かつ中間処理Bが成功するようなルール(の
うち最初のもの)に対してルールの適用が行われる。T
P’に対するルールの集合を取り出す(ステップ30
4)。もし、ルールの集合がNILならば(ステップ3
05)、ステップ302に戻る。ルールの集合があった
場合、その先頭のルールを取り出し、TAとTP’のマ
ッチングからパターン変数の変数束縛「bind」を作
成する(ステップ306)。
The rule is applied to the rule (the first one) in which the syntax tree TA of the result of the parsing of A matches TP 'and the intermediate process B succeeds. T
Retrieve a set of rules for P '(step 30
4). If the rule set is NIL (step 3
05), and returns to step 302. When there is a set of rules, the first rule is taken out, and the variable binding "bind" of the pattern variable is created from the matching of TA and TP '(step 306).

【0039】「bind」が「false」であれば
(ステップ307)、このルールは適用可能でないので
ステップ305に戻る。
If "bind" is "false" (step 307), this rule is not applicable, and the process returns to step 305.

【0040】「bind」が「false」でなかった
時は、この変数束縛のもとで、中間処理指定Bを中間処
理評価装置「Eval」により評価し、新しい変数束縛
「new_bind」を得る(ステップ308)。
When "bind" is not "false", the intermediate processing specification B is evaluated by the intermediate processing evaluation device "Eval" under this variable binding to obtain a new variable binding "new_bind" (step 308).

【0041】中間処理出失敗した場合は、「new_b
ind」が「false」となるので(ステップ30
9)、ステップ302に戻る。
When the output of the intermediate process fails, "new_b"
Since "ind" becomes "false" (step 30
9) and returns to step 302.

【0042】「new_bind」が「false」で
ない時は、「new_bind」により出力パターンC
の構文木TC内のパターン変数をインスタンシエイトし
たもものを構成し、TP内の部分木TP’をこれに置き
換える(ステップ310)。
When "new_bind" is not "false", the output pattern C is determined by "new_bind".
Constructs a pattern tree instantiated in the syntax tree TC of the above, and replaces the subtree TP 'in the TP with this (step 310).

【0043】以上の処理を書換え可能な部分木TP’が
なくなるまで繰り返す。
The above processing is repeated until there are no rewritable subtrees TP '.

【0044】図4に、ルール記述の例を示す。パターン
変数は「?x」のように先頭に「?」を付けて表す。ま
た、変数のあとに「@」に続けてノード型を表す正規表
現を記述できる。
FIG. 4 shows an example of the rule description. A pattern variable is represented by adding "?" At the beginning like "? X". In addition, after the variable, a regular expression representing the node type can be described following "@".

【0045】例えば、「?x@stmt*」は「?x」
が「stmt型」(実行文を表すノード型)の項目の0
個以上の並びとマッチすることを表す。
For example, "? X @ stmt *" is "? X"
Is 0 of the item of "stmt type" (node type that represents an executable statement)
Represents a match with more than one sequence.

【0046】41は不定長の引数をとる関数を定義する
例である。
Reference numeral 41 is an example of defining a function that takes an argument of indefinite length.

【0047】例えば、「foo(a,b)」という関数
呼び出しは、最初のルールに従い、「bar(a,
b)」に、「foo(a,b,c)」という関数呼び出
しは両方のルールが適用され、「bar(a,bar
(b,c))」に書換えられる。
For example, the function call "foo (a, b)" follows the first rule, "bar (a, b)".
b) ”, both rules are applied to the function call“ foo (a, b, c) ”, and“ bar (a, bar)
(B, c)) ”.

【0048】42はカーニハン・リッチの(古い)仕様
のCの関数定義をANSIC対応の(新しい)仕様に基
づいた関数定義に書換える例である。
Reference numeral 42 is an example of rewriting the C function definition of Kanihan Rich's (old) specification to a function definition based on the (new) specification corresponding to ANSIC.

【0049】41のルールを構文解析して構文木の書換
えルールと見做す仕方を図5および図6に示す。
5 and 6 show how to parse 41 rules and regard them as rewriting rules of a syntax tree.

【0050】図5が最初のルール41、図6が2番目の
ルール42に対応する。
FIG. 5 corresponds to the first rule 41, and FIG. 6 corresponds to the second rule 42.

【0051】図7に入力「foo(a,b,c)」に対
するシステムの動作を示す。入力61は構文解析装置1
01により構文解析され、構文木63となる。システム
は指定された戦略に従い、この構文木あるいはその部分
木に適用可能なルールを捜す。
FIG. 7 shows the operation of the system for the input "foo (a, b, c)". Input 61 is the parser 1
01 is parsed into a syntax tree 63. The system searches for rules applicable to this syntax tree or its subtrees according to the specified strategy.

【0052】この例では、図6の構文木521に「?x
=a」,「?y=b」,「?z=c」という変数束縛を
与えたものが構文木63と一致するから図6のルール5
20が適用され、構文木522にパターン変数に対する
上述の代入を行った構文木64に書き換えられる。
In this example, the syntax tree 521 of FIG.
= A ”,“? Y = b ”, and“? Z = c ”given variable bindings match the syntax tree 63, so rule 5 in FIG.
20 is applied, and the syntax tree 522 is rewritten to the syntax tree 64 in which the above-mentioned substitution for the pattern variable is performed.

【0053】同様にして部分木64の部分木65と部分
木511に「?x=b」,「?y=c」という変数束縛
を与えたものが一致するから図5のルール510が適用
されて、図8の構文木66に書き換えられる。
Similarly, the subtree 65 of the subtree 64 and the subtree 511 have the same variable bindings as "? X = b" and "? Y = c", so that the rule 510 of FIG. 5 is applied. And is rewritten as the syntax tree 66 of FIG.

【0054】このようにして書き換えられた構文木は、
出力処理装置108によりプログラム109として出力
される。
The syntax tree rewritten in this way is
The output processing device 108 outputs the program 109.

【0055】図4のルール42に対応する構文木の書換
えルールを示したのが図9である。
FIG. 9 shows a rewriting rule of the syntax tree corresponding to the rule 42 of FIG.

【0056】ただし、簡単のためプロトタイプ宣言にあ
たる出力部は省略してある。
However, for simplicity, the output part corresponding to the prototype declaration is omitted.

【0057】ルール42の入力パターン43および出力
パターン44はそれぞれ構文木71,73に解析され、
フィルタ部72による特定のノードに対する処理を伴う
構文木の書換えルールと見做される。
The input pattern 43 and the output pattern 44 of the rule 42 are parsed into syntax trees 71 and 73, respectively,
It is regarded as a rule for rewriting a syntax tree that involves processing on a specific node by the filter unit 72.

【0058】このルール42の適用を示したのが図10
である。
The application of this rule 42 is shown in FIG.
Is.

【0059】書き換えるべきプログラム81が与えられ
ると、プログラムの構文木が作成され、構文木71と比
較され、パターン変数とのマッチが行われ、「?fct
_type」には「int」82,「?fct_nam
e」には「foo」83,「?args」には「(x,
y,z)のリスト84,「?arg_decls」には
「int x,y;long y;」というリスト85,
「?fct_body」には関数定義本体86が対応づ
けられる。
When the program 81 to be rewritten is given, a syntax tree of the program is created, compared with the syntax tree 71, and a match with a pattern variable is performed.
"_Type" has "int" 82 and "? Fct_nam".
"e" is "foo" 83, and "? args" is "(x,
y, z) list 84, “? arg_decls” has list 85 “int x, y; long y;”
The function definition body 86 is associated with “? Fct_body”.

【0060】フィルタ部87により「?result_
decl」の計算が行われ、出力用構文木中72のパタ
ーン変数が対応する値88〜811に置き換えられ、変
換されたプログラム109が結果として得られる。
By the filter unit 87, “? Result_
"decl" is calculated, the pattern variable 72 in the output syntax tree is replaced with the corresponding values 88 to 811, and the converted program 109 is obtained as a result.

【0061】このように本実施例によれば、構文木に型
階層を導入したことにより、プログラム変換ルールの記
述と変換処理を簡明にすることができる。
As described above, according to this embodiment, by introducing the type hierarchy into the syntax tree, the description of the program conversion rule and the conversion process can be simplified.

【0062】また、構文を拡張して新しい制御構造を導
入する目的にも用いることができる。
It can also be used for the purpose of extending the syntax and introducing new control structures.

【0063】また、プログラムの移植、拡張に用いるこ
とができるが、変換ルールの記述も変換対象のプログラ
ムと同じ構文で記述しているので、変換ルールに対する
処理自体にプログラム変換を用いることができ、拡張性
の高い形のシステムが実現できる。
Further, although it can be used for porting and extending a program, since the description of the conversion rule is described by the same syntax as the program to be converted, the program conversion can be used for the processing itself for the conversion rule. A highly scalable system can be realized.

【0064】さらに、実施例で述べたC言語変換システ
ムの場合は、システムの実現もC言語により行われてい
るので、処理系自身に変換を適用してシステムを書き換
えることができ、特に移植性の高いシステムを構築する
ことができる。
Furthermore, in the case of the C language conversion system described in the embodiment, since the system is also realized by the C language, the conversion can be applied to the processing system itself to rewrite the system, which is especially portable. It is possible to build a high system.

【0065】[0065]

【発明の効果】以上説明したように、本発明によれば、
複雑な構造のプログラムを、煩雑な記述のルールを用い
ることなく別のプログラムに変換することができる。
As described above, according to the present invention,
A program with a complicated structure can be converted into another program without using complicated description rules.

【0066】特に、構文木に型階層を導入したことによ
り、プログラム変換ルールの記述と変換処理を簡明にす
ることができる。
In particular, by introducing the type hierarchy into the syntax tree, the description of the program conversion rule and the conversion process can be simplified.

【0067】また、構文木の変換ルールとして、変換対
象となっているプログラミング言語と同じ構文を用い、
プログラム変換装置全体も対象プログラミング言語を用
いて作成すると、プログラム変換装置を自分自身に適用
することが可能となり、オペレーティングシステムが異
なる機種のプログラムへの移植、拡張を容易に行うこと
ができる。
As the conversion rule of the syntax tree, the same syntax as the programming language to be converted is used,
If the entire program conversion device is also created using the target programming language, it becomes possible to apply the program conversion device to itself, and it is possible to easily perform porting and expansion to programs of different models having different operating systems.

【図面の簡単な説明】[Brief description of drawings]

【図1】本発明の一実施例を示すブロック構成図であ
る。
FIG. 1 is a block diagram showing an embodiment of the present invention.

【図2】構文木のノードの型階層の例を示す説明図であ
る。
FIG. 2 is an explanatory diagram showing an example of a type hierarchy of nodes in a syntax tree.

【図3】構文木の書き換え手順を示す流れ図である。FIG. 3 is a flowchart showing a procedure for rewriting a syntax tree.

【図4】C言語に対する変換ルールの記述例を示す説明
図である。
FIG. 4 is an explanatory diagram showing a description example of a conversion rule for C language.

【図5】図4のルール41を構文解析して構文木の変換
とみる仕方を示す説明図である。
5 is an explanatory diagram showing how to parse the rule 41 of FIG. 4 and regard it as conversion of a syntax tree.

【図6】図4の続きを示す説明図である。FIG. 6 is an explanatory diagram showing a sequel to FIG. 4;

【図7】ルール510の適用例を示す説明図である。FIG. 7 is an explanatory diagram showing an application example of a rule 510.

【図8】図7の続きを示す説明図である。FIG. 8 is an explanatory diagram showing a sequel to FIG. 7;

【図9】ルール42を構文解析して構文木の変換とみる
仕方を示す説明図である。
FIG. 9 is an explanatory diagram showing how to parse a rule 42 and regard it as conversion of a syntax tree.

【図10】ルール42の適用例を示す説明図である。FIG. 10 is an explanatory diagram showing an application example of a rule 42.

【符号の説明】[Explanation of symbols]

101…構文解析装置、102…変換対象のプログラ
ム、103…変換ルール、104…構文木、105…構
文木書換えルール、106…構文木書き換え装置、10
7…書き換えられた構文木、108…出力処理装置、1
09…変換されたプログラム。
101 ... Syntax analysis device, 102 ... Conversion target program, 103 ... Conversion rule, 104 ... Syntax tree, 105 ... Syntax tree rewriting rule, 106 ... Syntax tree rewriting device, 10
7 ... Rewritten syntax tree, 108 ... Output processing device, 1
09 ... Converted program.

Claims (2)

【特許請求の範囲】[Claims] 【請求項1】 変換対象の入力プログラムとその変換ル
ールの構文を、構文木を構成するノードに型階層を用い
た構文解析を行い、入力プログラムの構文木および変換
ルールの構文木を作成する構文解析手段と、 前記入力プログラムの構文木を前記変換ルールの構文木
で書き換える構文木書き換え手段と、 書き換えられた入力プログラムの構文木を変換されたプ
ログラムとして出力する出力手段とを備えるプログラム
変換装置。
1. A syntax for parsing the syntax of an input program to be converted and its conversion rule using a type hierarchy for nodes constituting the syntax tree to create a syntax tree of the input program and a syntax tree of the conversion rule. A program conversion device comprising: an analysis unit; a syntax tree rewriting unit that rewrites the syntax tree of the input program with a syntax tree of the conversion rule; and an output unit that outputs the rewritten syntax tree of the input program as a converted program.
【請求項2】 前記構文解析手段は、変換対象の入力プ
ログラムの構文に一致した変換ルールの構文木を出力す
ることを特徴とする請求項1記載のプログラム変換装
置。
2. The program conversion device according to claim 1, wherein the syntax analysis unit outputs a syntax tree of a conversion rule that matches the syntax of an input program to be converted.
JP7666295A 1995-03-31 1995-03-31 Program conversion device Pending JPH08272622A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP7666295A JPH08272622A (en) 1995-03-31 1995-03-31 Program conversion device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP7666295A JPH08272622A (en) 1995-03-31 1995-03-31 Program conversion device

Publications (1)

Publication Number Publication Date
JPH08272622A true JPH08272622A (en) 1996-10-18

Family

ID=13611630

Family Applications (1)

Application Number Title Priority Date Filing Date
JP7666295A Pending JPH08272622A (en) 1995-03-31 1995-03-31 Program conversion device

Country Status (1)

Country Link
JP (1) JPH08272622A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008243019A (en) * 2007-03-28 2008-10-09 Toshiba Corp Source code converting device and source code converting method
WO2010047388A1 (en) * 2008-10-24 2010-04-29 独立行政法人情報通信研究機構 Calculation processing system, program creation method, and program creation program
JP2014211729A (en) * 2013-04-18 2014-11-13 株式会社日立製作所 Computer, program, and data generation method

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008243019A (en) * 2007-03-28 2008-10-09 Toshiba Corp Source code converting device and source code converting method
WO2010047388A1 (en) * 2008-10-24 2010-04-29 独立行政法人情報通信研究機構 Calculation processing system, program creation method, and program creation program
US8984103B2 (en) 2008-10-24 2015-03-17 National Institute Of Information And Communications Technology (Niict) Calculation processing system, program creation method, and program creation program
JP2014211729A (en) * 2013-04-18 2014-11-13 株式会社日立製作所 Computer, program, and data generation method

Similar Documents

Publication Publication Date Title
Wile Abstract syntax from concrete syntax
CA2078247C (en) Source code analyzer
CA2417752A1 (en) Xml-robot
US20040154009A1 (en) Structuring program code
JPH1196016A (en) Gdmo translator, gdmo translation method and recording medium recording gdmo translator program
EP0520708B1 (en) Method and apparatus for converting high level form abstract syntaxes into an intermediate form
Zhang et al. Automated extraction of grammar optimization rule configurations for metamodel-grammar co-evolution
US20030233640A1 (en) Structuring program code
EP0692115B1 (en) System for conversion of loop functions to continuation-passing style
Kleppe Towards the generation of a text-based IDE from a language metamodel
JPH08272622A (en) Program conversion device
Grov et al. Hume box calculus: robust system development through software transformation
GB2420638A (en) Method of substituting code fragments in Internal Representation
JP2675100B2 (en) Language converter and language conversion method
Zingaro Modern extensible languages
JP3584204B2 (en) Automatic source program converter
Harmer et al. Transformations to Restructure and Re–engineer COBOL Programs
WO2022234675A1 (en) Program modification device, program modification method, and program
Koppel et al. Automatically deriving control-flow graph generators from operational semantics
Lilis et al. Meta C++: an extension layer for multi-stage generative metaprogramming.
JP2001005655A (en) Device and method for aiding development of application generator
JP2956591B2 (en) Method and apparatus for parallelizing a loop having a conditional jump out of the loop
JP3194372B2 (en) Parser generator preprocessor system, preprocessing method for parser generator
JPH10154079A (en) Program conversion device and storage medium
JP2904112B2 (en) Automatic program synthesizer