JP2904112B2 - Automatic program synthesizer - Google Patents
Automatic program synthesizerInfo
- Publication number
- JP2904112B2 JP2904112B2 JP8090128A JP9012896A JP2904112B2 JP 2904112 B2 JP2904112 B2 JP 2904112B2 JP 8090128 A JP8090128 A JP 8090128A JP 9012896 A JP9012896 A JP 9012896A JP 2904112 B2 JP2904112 B2 JP 2904112B2
- Authority
- JP
- Japan
- Prior art keywords
- rewrite
- subtree
- rewriting
- rule
- function
- 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.)
- Expired - Fee Related
Links
- 238000006243 chemical reaction Methods 0.000 claims description 40
- 238000000034 method Methods 0.000 claims description 13
- 230000002194 synthesizing effect Effects 0.000 claims description 8
- 238000010586 diagram Methods 0.000 description 8
- 230000015572 biosynthetic process Effects 0.000 description 1
- 238000007796 conventional method Methods 0.000 description 1
Landscapes
- Stored Programmes (AREA)
Description
【0001】[0001]
【発明の属する技術分野】本発明は、複数用意された書
き換え規則に基づき、木構造で表現されるプログラム仕
様の変換を繰り返してプログラムを合成するプログラム
自動合成技術に関する。BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to an automatic program synthesizing technique for synthesizing a program by repeatedly converting a program specification expressed in a tree structure based on a plurality of rewriting rules.
【0002】[0002]
【従来の技術】プログラム自動合成装置の一種に、左辺
部にプログラム仕様中の変換を行う部分木の構造を、右
辺部にその部分木の変換後の構造をそれぞれ定義した書
き換え規則の集合を用いて、関数記号を節とする木構造
で表現されたプログラム仕様の変換を繰り返すことによ
ってプログラムを自動生成する装置がある。なお、書き
換え対象となるプログラム仕様中に書き換え規則によっ
て書き換え可能な部分が複数ある場合、どれを優先的に
書き換えるかを定める戦略として、プログラム仕様の木
構造上で最も根に近い部分で且つ最も左側の部分を書き
換える最左最外戦略と、最も葉に近い部分で且つ最も左
側の部分を書き換える最左最内戦略とがあるが、本発明
では、このうちの後者の最左最内戦略を用いるプログラ
ム自動合成装置を対象としている。2. Description of the Related Art A type of automatic program synthesizing system uses a structure of a subtree for performing conversion in a program specification on a left side and a set of rewriting rules defining a structure after conversion of the subtree on a right side. There is an apparatus that automatically generates a program by repeating conversion of a program specification represented by a tree structure having function symbols as nodes. If there are a plurality of parts that can be rewritten according to the rewriting rules in the program specification to be rewritten, the strategy to determine which one is to be rewritten preferentially is the part closest to the root and the leftmost part in the tree structure of the program specification. There is a leftmost outermost strategy that rewrites the part and a leftmost innermost strategy that rewrites the part closest to the leaf and the leftmost part. In the present invention, the latter leftmost innermost strategy is used. It is intended for automatic program synthesizers.
【0003】図2は木構造で表されたプログラム仕様の
例を、図3は書き換え規則の集合の例を、図4はそれら
の書き換え規則を木構造で表現した図を、それぞれ示
す。ここで、小文字の英数字は関数記号を、大文字の英
数字は変数を表している。また、図5は図3および図4
に示す書き換え規則を用いて図2に示すプログラム仕様
の変換を繰り返す過程を示している。従来のプログラム
自動合成装置における変換は以下のように進められる。FIG. 2 shows an example of a program specification expressed in a tree structure, FIG. 3 shows an example of a set of rewrite rules, and FIG. 4 shows a diagram in which those rewrite rules are expressed in a tree structure. Here, lowercase alphanumeric characters represent function symbols, and uppercase alphanumeric characters represent variables. FIG. 5 corresponds to FIGS.
2 shows a process of repeating the conversion of the program specifications shown in FIG. 2 using the rewriting rules shown in FIG. The conversion in the conventional automatic program synthesizer proceeds as follows.
【0004】最左最内戦略では、プログラム仕様の最左
最内部(最も葉に近い部分で且つ左側の部分)から書き
換えを行う。そこで先ず、図2のプログラム仕様の最左
最内部に適合する部分木を左辺部に持つ書き換え規則を
図3,図4に示す書き換え規則集合中から探索し、図5
の501の左辺部を持つ書き換え規則33を得て、プロ
グラム仕様の最左最内部および規則33の右辺部の内容
に基づき、図5に示す「書き換え1」を実行し、プログ
ラム仕様22の最左最内部を書き換える。[0004] In the leftmost innermost strategy, rewriting is performed from the leftmost innermost part (the part closest to the leaf and the leftmost part) of the program specification. Therefore, first, a rewrite rule having a subtree conforming to the leftmost innermost part of the program specification of FIG. 2 on the left side is searched from the rewrite rule set shown in FIGS.
Is obtained based on the leftmost innermost part of the program specification and the contents of the right side part of the rule 33, and executes “rewrite1” shown in FIG. Rewrite the innermost part.
【0005】次に、この書き換え後のプログラム仕様の
最左最内部に適合する部分木を左辺部に持つ書き換え規
則を書き換え規則集合中から探索し、図5の502の左
辺部を持つ書き換え規則31を得て、プログラム仕様の
最左最内部および規則31の内容に基づき、図5に示す
「書き換え2」を実行し、プログラム仕様の最左最部を
再度書き換える。[0005] Next, a rewrite rule having a subtree conforming to the leftmost innermost part of the rewritten program specification on the left side is searched from the rewrite rule set, and a rewrite rule 31 having a left side 502 shown in FIG. Then, based on the leftmost innermost part of the program specification and the contents of the rule 31, “rewrite 2” shown in FIG. 5 is executed to rewrite the leftmost part of the program specification again.
【0006】次に、この書き換え後のプログラム仕様の
最左最内部に適合する部分木を左辺部に持つ書き換え規
則を書き換え規則集合中から探索し、図5の503の左
辺部を持つ書き換え規則32を得て、プログラム仕様の
最左最内部および規則32の内容に基づき、図5に示す
「書き換え3」を実行し、プログラム仕様の最左最部を
再度書き換える。Next, a rewrite rule having a subtree conforming to the leftmost innermost part of the rewritten program specification on the left side is searched from the rewrite rule set, and a rewrite rule 32 having a left side portion 503 in FIG. Then, based on the leftmost innermost part of the program specification and the contents of the rule 32, “Rewrite 3” shown in FIG. 5 is executed, and the leftmost part of the program specification is rewritten again.
【0007】次に、この書き換え後のプログラム入力仕
様の最左最内部に適合する部分木を左辺部に持つ書き換
え規則を書き換え規則集合中から探索し、図5の501
の左辺部を持つ書き換え規則33を得て、プログラム仕
様の最左最内部および規則33の内容に基づき、図5に
示す「書き換え4」を実行し、プログラム入力仕様の最
左最内部を再び書き換える。そして、この書き換え後の
プログラム仕様は、これ以上書き換えが行われない正規
形であるため、書き換えを終了する。Next, a rewrite rule having a subtree matching the leftmost innermost part of the rewritten program input specification on the left side is searched from the rewrite rule set, and 501 in FIG.
Is obtained, and based on the leftmost innermost part of the program specification and the contents of the rule 33, "rewrite 4" shown in FIG. 5 is executed, and the leftmost innermost part of the program input specification is rewritten again. . Then, since the rewritten program specification is in the normal form in which no further rewriting is performed, the rewriting is terminated.
【0008】[0008]
【発明が解決しようとする課題】前述したように従来の
装置では、木構造で表現されたプログラム仕様を書き換
え規則を用いて書き換え、新たな木構造が生成された際
に再びその木構造から書き換え規則集合中の書き換え規
則のうちで適用可能な規則を選択していた。このため、
書き換え規則によって生成される構造が、直接他の書き
換え規則によって書き換えが行われることが決定的な場
合も、常にあらためて書き換え規則の選択を行わなけれ
ばならず、その結果、書き換え処理が遅くなるという問
題がある。ここで、書き換え規則によって生成される構
造が、直接他の書き換え規則によって書き換えが行われ
ることが決定的な場合が生じるのは、各々の書き換え規
則を他の全ての書き換え規則を考慮して作成しておくこ
とが困難であること、既存の書き換え規則集合に対して
不足する書き換え規則を順次追加していって書き換え規
則集合の充実を図るようにしていること、デバッグ等の
ために規則自体を利用者が理解し易い形式で作成してい
ること等が、主な要因である。As described above, in the conventional apparatus, a program specification expressed in a tree structure is rewritten using a rewrite rule, and when a new tree structure is generated, the program is rewritten from the tree structure again. Applicable rules were selected from the rewrite rules in the rule set. For this reason,
Even when it is decisive that the structure generated by the rewrite rule is directly rewritten by another rewrite rule, the rewrite rule must always be selected again, resulting in a slow rewrite process. There is. Here, there is a case where it is decisive that the structure generated by the rewrite rules is directly rewritten by another rewrite rule. Each rewrite rule is created by considering all the other rewrite rules. It is difficult to keep in mind that the rewriting rule set is added to the existing rewriting rule set in order to enhance the rewriting rule set, and the rule itself is used for debugging etc. The main factor is that it is created in a format that is easy for people to understand.
【0009】そこで本発明の目的は、書き換え規則集合
を予め解析しておくことによって、或る書き換え規則の
適用後に生成される木構造が、書き換え規則集合中の他
の書き換え規則によって書き換えられる可能性がある場
合、書き換え規則を再度選択することなく直接書き換え
られるようにして、書き換え可能な部分に適用可能な書
き換え規則の選択に要するコストを低減し、もってプロ
グラム合成処理の速度を向上させることにある。Therefore, an object of the present invention is to analyze a set of rewrite rules in advance so that a tree structure generated after applying a certain rewrite rule may be rewritten by another rewrite rule in the set of rewrite rules. In such a case, it is possible to reduce the cost required to select a rewrite rule applicable to a rewritable part by allowing the rewrite rule to be directly rewritten without selecting the rewrite rule again, thereby improving the speed of the program synthesizing process. .
【0010】なお、本発明と同様に書き換えの効率化を
図った装置として、本発明者の提案にかかる特開平6−
251066号公報がある。この従来技術は、予め書き
換え規則の集合を解析して書き換え対象の候補となる関
数記号の集合を求め、この集合に含まれない関数記号は
そもそも変換の対象とはならないので、入力プログラム
仕様中のそのような関数記号に事前にマークを付けてお
き、プログラム仕様中から書き換え可能な部分を探索す
る際にマークが付けられた部分を探索範囲から除外する
ものである。この従来技術は、プログラム仕様中の探索
範囲を絞り込むことによる効率化を狙ったものである。
これに対して本発明は、書き換え規則の選択頻度の削減
による効率化を狙ったものであり、両者は同じ目的を有
するが、それを達成するためのアプローチの仕方が相違
している。As an apparatus for improving the efficiency of rewriting as in the present invention, Japanese Patent Laid-Open No.
No. 2,510,662. In this conventional technique, a set of rewriting rules is analyzed in advance to obtain a set of function symbols that are candidates for rewriting. Function symbols that are not included in this set are not originally subjected to conversion. Such a function symbol is marked in advance, and when searching for a rewritable portion in the program specification, the marked portion is excluded from the search range. This prior art aims to improve efficiency by narrowing a search range in a program specification.
On the other hand, the present invention aims at improving efficiency by reducing the frequency of selecting rewrite rules, and both have the same purpose, but differ in the approach to achieve it.
【0011】[0011]
【課題を解決するための手段】最左最内戦略を採用する
場合、書き換え規則の集合に含まれる書き換え規則のう
ち、その右辺部に現れる関数記号が、自身の書き換え規
則または他の書き換え規則の左辺部に定義された部分木
の最外部関数記号(最も根に近い位置の関数記号)と同
じである場合、その書き換え規則によって書き換えた後
の部分木が、その直後に、自身の書き換え規則または前
記他の書き換え規則によって再度書き換えられる可能性
がある。そこで本発明では、書き換え規則の集合を事前
に解析して上述のような関係にある書き換え規則を洗い
出し、或る書き換え規則の適用後に生成される木構造
が、書き換え規則集合中の他の書き換え規則によって書
き換えられる可能性がある場合、書き換え規則を再度選
択することなく直接書き換えれるようにする。When the leftmost innermost strategy is adopted, among the rewrite rules included in the set of rewrite rules, the function symbol appearing on the right side of the rewrite rules is the same as the own rewrite rule or another rewrite rule. If it is the same as the outermost function symbol of the subtree defined on the left side (function symbol at the position closest to the root), the subtree rewritten by the rewriting rule immediately follows its own rewriting rule or Rewriting may be performed again according to the other rewriting rules. Therefore, in the present invention, a set of rewrite rules is analyzed in advance to identify rewrite rules having the above-described relationship, and a tree structure generated after application of a certain rewrite rule is replaced with another rewrite rule in the set of rewrite rules. If there is a possibility that the rewriting rule is rewritten, the rewriting rule is directly rewritten without selecting the rewriting rule again.
【0012】[0012]
【0013】即ち、本発明は、左辺部にプログラム仕様
中の変換を行う部分木の構造を、右辺部にその部分木の
変換後の構造をそれぞれ定義した書き換え規則の集合を
用いて、関数記号を節とする木構造で表現されたプログ
ラム仕様の変換を繰り返してプログラムを生成するプロ
グラム自動合成装置において、書き換え規則の集合を入
力し、左辺部に定義された部分木の最外部関数記号が同
一である書き換え規則のグループ毎に、呼び出し元から
引数で与えられる変換対象部分木構造に基づき当該グル
ープの何れの書き換え規則の左辺部が変換対象部分木と
マッチするかを判断し、且つ、マッチする左辺部に対応
する右辺部に定義された部分木中に自グループおよび他
グループの何れかの書き換え規則の左辺部に定義された
部分木の最外部関数記号が存在するときは当該右辺部の
定義に基づく変換後の部分木の構造を引数として当該存
在した最外部関数記号に対応する書き換え関数を呼び出
してその返却値を呼び出し元に返却し、そのような最外
部関数記号が存在しないときは当該右辺部の定義に基づ
く変換後の部分木の構造を返却値として呼び出し元に返
却する書き換え関数を生成する書き換え規則コンパイル
部と、変換対象とするプログラム仕様に対して最左最内
戦略に基づいて探索した変換対象部分木の構造を引数に
してその部分木の最外部関数記号に対応する書き換え関
数を呼び出し、その返却される変換後の部分木の構造に
基づき前記変換対象部分木の書き換えを行う処理を、変
換可能な部分木が無くなるまで繰り返す書き換え装置と
を備えることを特徴とする。 That is , according to the present invention, a function symbol is defined by using a set of rewrite rules defining the structure of a subtree for performing conversion in a program specification on the left side and a structure after conversion of the subtree on the right side. In a program automatic synthesizer that generates a program by repeating the conversion of a program specification expressed in a tree structure with nodes, a set of rewrite rules is input, and the outermost function symbols of the subtrees defined on the left side are the same. For each group of rewrite rules that is, based on the subtree structure to be converted given by the caller as an argument, it is determined which rewrite rule of the rewrite rule of the group matches the subtree to be converted, and is matched. outermost function of the defined partial tree on the left side portion of one of the rewrite rules of its own group and other groups in the portion of the tree that is defined on the right side portion corresponding to the left side portion When the symbol exists, the rewriting function corresponding to the existing outermost function symbol is called with the structure of the converted subtree based on the definition of the right side as an argument, and the return value is returned to the caller. If there is no such outermost function symbol, a rewrite rule compiling unit that generates a rewrite function that returns the structure of the subtree after conversion based on the definition of the right side to the caller as a return value, and a program specification to be converted The rewrite function corresponding to the outermost function symbol of the subtree is called with the structure of the conversion target subtree searched based on the leftmost innermost strategy as the argument, and the returned converted subtree structure And a rewriting device that repeats the process of rewriting the conversion target subtree until there is no more convertible subtree.
【0014】更に本発明は、前記書き換え規則コンパイ
ル部に、左辺最外部関数記号登録部と、書き換え規則登
録部と、入力した書き換え規則の集合に含まれる書き換
え規則を解析し、書き換え規則の左辺部に定義された部
分木の最外部関数記号の種類を前記左辺最外部関数記号
登録部に登録すると共に、入力した書き換え規則を前記
最外部関数記号の種類毎にグループ化して前記書き換え
規則登録部に登録する書き換え規則解析部と、前記書き
換え規則登録部に登録された書き換え規則の右辺部に定
義された部分木中に前記左辺最外部関数記号登録部に登
録された種類の関数記号が存在するか否かを調べ、存在
した右辺部の関数記号にマークを付ける右辺マーク部
と、前記書き換え規則登録部に登録された書き換え規則
のグループ毎に、呼び出し元から引数で与えられる変換
対象部分木構造に基づき当該グループの何れの書き換え
規則の左辺部が変換対象部分木とマッチするかを判断
し、且つ、マッチする左辺部に対応する右辺部にマーク
が付いているときは当該右辺部の定義に基づく変換後の
部分木の構造を引数として当該マークが付いている関数
記号に対応する書き換え関数を呼び出してその返却値を
呼び出し元に返却し、マークが付いていないときは当該
右辺部の定義に基づく変換後の部分木の構造を返却値と
して呼び出し元に返却する書き換え関数を生成する書き
換え関数生成部とを含むことを特徴とする。Further, according to the present invention, the rewriting rule compiling unit analyzes the rewriting rules included in the set of the rewriting rules input by the outermost function symbol registration unit on the left side, the rewriting rule registration unit, and analyzes the left side portion of the rewriting rules. The type of the outermost function symbol registered in the subtree is registered in the leftmost outermost function symbol registration unit, and the input rewrite rules are grouped for each type of the outermost function symbol, and are registered in the rewrite rule registration unit. Whether the rewriting rule analysis unit to be registered and the subtree defined on the right side of the rewriting rule registered in the rewriting rule registration unit include a function symbol of the type registered in the leftmost outermost function symbol registration unit. For each group of rewrite rules registered in the rewrite rule registration unit, the call Based on the conversion target subtree structure given as an argument from the source, it is determined which rewriting rule of the corresponding group matches the left side of the conversion rule with the conversion target subtree, and a mark is placed on the right side corresponding to the matching left side. When is marked, the rewrite function corresponding to the function symbol with the mark is called using the structure of the subtree after conversion based on the definition of the right side as an argument, and the return value is returned to the caller, and the mark is returned. And a rewrite function generation unit that generates a rewrite function that returns the structure of the subtree after conversion based on the definition of the right-hand side to the caller as a return value.
【0015】[0015]
【発明の実施の形態】次に本発明の実施の形態の例につ
いて図面を参照して詳細に説明する。DESCRIPTION OF THE PREFERRED EMBODIMENTS Next, embodiments of the present invention will be described in detail with reference to the drawings.
【0016】図1を参照すると、本発明の一実施例のプ
ログラム自動合成装置10は、書き換え規則集合24を
用いて、プログラム仕様22の変換を繰り返すことによ
ってプログラム23を生成する装置であり、仕様入力部
11,書き換え装置12,プログラム出力部13,書き
換え関数格納部14,書き換え規則コンパイル部15お
よび書き換え規則集合入力部21を備えている。Referring to FIG. 1, an automatic program synthesizing apparatus 10 according to one embodiment of the present invention is an apparatus for generating a program 23 by repeatedly converting a program specification 22 using a rewrite rule set 24. An input unit 11, a rewrite device 12, a program output unit 13, a rewrite function storage unit 14, a rewrite rule compiling unit 15, and a rewrite rule set input unit 21 are provided.
【0017】本実施例のプログラム自動合成装置10
は、大別して、書き換え規則集合24から書き換え関数
を生成する部分と、この生成された書き換え関数を使用
して、プログラム仕様22からプログラム23を生成す
る部分とに分けられる。以下では、先ず前者の部分につ
いて説明し、次いで後者の部分について説明する。An automatic program synthesizing apparatus 10 according to the present embodiment.
Are roughly divided into a part for generating a rewrite function from the rewrite rule set 24 and a part for generating a program 23 from the program specification 22 using the generated rewrite function. Hereinafter, the former part will be described first, and then the latter part will be described.
【0018】書き換え規則集合24から書き換え関数を
生成する部分は、書き換え規則集合24を入力する書き
換え規則集合入力部21と、入力された書き換え規則集
合24から書き換え関数を生成する書き換え規則コンパ
イル部15と、生成された書き換え関数を格納する書き
換え関数格納部14とで構成される。The part for generating a rewrite function from the rewrite rule set 24 includes a rewrite rule set input unit 21 for inputting the rewrite rule set 24, and a rewrite rule compiling unit 15 for generating a rewrite function from the input rewrite rule set 24. , And a rewriting function storage unit 14 for storing the generated rewriting function.
【0019】図3に書き換え規則集合24の一例を示
す。また、図4に図3の書き換え規則集合24中の各々
の書き換え規則31〜33を木構造で表現した図を示
す。なお、図3および図4において、小文字の英数字は
関数記号を、大文字の英数字は変数を、それぞれ示す。
各々の書き換え規則31〜33は、図3に示すように、
左辺部と右辺部とそれらを結合する記号(矢印)とで構
成される。左辺部は、プログラム仕様中の変換を行う部
分木の構造を定義し、右辺部はその部分木の変換後の構
造を定義している。FIG. 3 shows an example of the rewrite rule set 24. FIG. 4 shows a tree structure of each of the rewrite rules 31 to 33 in the rewrite rule set 24 of FIG. In FIGS. 3 and 4, lowercase alphanumeric characters indicate function symbols, and uppercase alphanumeric characters indicate variables.
Each of the rewrite rules 31 to 33 is, as shown in FIG.
It is composed of a left side, a right side, and a symbol (arrow) connecting them. The left side defines the structure of the subtree to be converted in the program specification, and the right side defines the structure after conversion of the subtree.
【0020】この例の書き換え規則集合24は、そのま
ま適用すると、プログラム仕様中のa(X,1)または
a(X,0)となる最左最内部に関して、書き換え規則
の選択が冗長になる。即ち、プログラム仕様中の最左最
部が、若しa(X,1)ならば、書き換え規則31が選
択されてa(X,0)に変換されると、最左最内戦略で
は再び最左最内部に対する変換を行うので、次に書き換
え規則32が選択されて最左最部がb(X)に変換さ
れ、更に書き換え規則33が選択されて、最終的にXに
変換され、合計3回の書き換え規則の選択が行われるか
らである。同様に、プログラム仕様中の最左最内部が、
若しa(X,0)ならば、書き換え規則32,書き換え
規則33の順に選択されて、最終的にXに変換され、合
計2回の書き換え規則の選択が必要となる。そこで、本
実施例では、このような冗長性を排するため、プログラ
ム仕様中の最左最内部が若しa(X,1)またはa
(X,0)ならば、その変換結果として直ちにXを返却
するような書き換え関数を、書き換え規則集合24に基
づき生成する。この生成は、書き換え規則コンパイル部
15が行う。If the rewrite rule set 24 of this example is applied as it is, the selection of the rewrite rule becomes redundant with respect to the leftmost innermost portion which becomes a (X, 1) or a (X, 0) in the program specification. That is, if the leftmost part in the program specification is a (X, 1), the rewriting rule 31 is selected and converted into a (X, 0). Since the conversion for the leftmost innermost part is performed, next, the rewriting rule 32 is selected, the leftmost part is converted to b (X), the rewriting rule 33 is selected, and finally converted to X. This is because the rewriting rule is selected twice. Similarly, the leftmost innermost part of the program specification is
If a (X, 0), the rewriting rule 32 and the rewriting rule 33 are selected in this order and are finally converted to X, and a total of two rewriting rule selections are required. Therefore, in this embodiment, in order to eliminate such redundancy, the leftmost innermost part in the program specification is a (X, 1) or a.
If (X, 0), a rewrite function that immediately returns X as the conversion result is generated based on the rewrite rule set 24. This generation is performed by the rewrite rule compiling unit 15.
【0021】書き換え規則コンパイル部15は、図1に
示すように、書き換え関数生成部16と、左辺最外部関
数記号登録部17と、右辺マーク部18と、書き換え規
則登録部19と、書き換え規則解析部20とから構成さ
れている。As shown in FIG. 1, the rewriting rule compiling section 15 includes a rewriting function generating section 16, a left side outermost function symbol registration section 17, a right side mark section 18, a rewriting rule registration section 19, a rewriting rule analysis section And a unit 20.
【0022】左辺最外部関数記号登録部17は、書き換
え規則集合24に含まれる書き換え規則31〜33の左
辺部に定義された部分木の最外部関数記号の種類を保持
する部分であり、書き換え規則解析部20から書き込み
が行われ、書き換え関数生成部16から参照される。こ
こで、部分木の最外部関数記号とは、その部分木の最も
根に近い位置の関数記号を意味し、書き換え規則31,
32の場合はa,書き換え規則33の場合はbである。The leftmost outermost function symbol registration unit 17 is a part that holds the type of the outermost function symbol of the subtree defined on the left side of the rewriting rules 31 to 33 included in the rewriting rule set 24. The writing is performed by the analysis unit 20 and is referred to by the rewriting function generation unit 16. Here, the outermost function symbol of the subtree means a function symbol at a position closest to the root of the subtree.
In the case of 32, it is a, and in the case of the rewriting rule 33, it is b.
【0023】書き換え規則登録部19は、書き換え規則
集合24に含まれる書き換え規則31〜33を、左辺部
の最外部関数記号の種類毎にグループ化して保持する部
分であり、書き換え規則解析部20から書き込みが行わ
れ、右辺マーク部18によって参照されると共にマーク
付けされ、また書き換え関数生成部16によって参照さ
れる。The rewrite rule registration unit 19 is a unit that holds the rewrite rules 31 to 33 included in the rewrite rule set 24 by grouping them according to the type of the outermost function symbol on the left side. The writing is performed, referenced and marked by the right side mark unit 18, and referenced by the rewrite function generation unit 16.
【0024】書き換え規則解析部20は、書き換え規則
集合入力部21を通じて書き換え規則集合24を入力
し、入力した書き換え規則集合24に含まれる書き換え
規則31〜33を解析し、書き換え規則の左辺部に定義
された部分木の最外部関数記号の種類を左辺最外部関数
記号登録部17に登録すると共に、入力した書き換え規
則を最外部関数記号の種類毎にグループ化して書き換え
規則登録部19に登録する手段である。The rewrite rule analysis unit 20 inputs the rewrite rule set 24 through the rewrite rule set input unit 21, analyzes the rewrite rules 31 to 33 included in the input rewrite rule set 24, and defines the rewrite rules 31 to 33 on the left side of the rewrite rule. Means for registering the type of the outermost function symbol obtained in the subtree in the leftmost outermost function symbol registration unit 17, and grouping the inputted rewriting rules for each type of the outermost function symbol and registering them in the rewriting rule registration unit 19 It is.
【0025】右辺マーク部18は、書き換え規則登録部
19に登録された書き換え規則の右辺部に定義された部
分木中に左辺最外部関数記号登録部17に登録された種
類の関数記号が存在するか否かを調べ、存在した右辺部
の関数記号にマークを付ける手段である。The right side mark section 18 has a function symbol of the type registered in the left side outermost function symbol registration section 17 in a subtree defined on the right side of the rewrite rule registered in the rewrite rule registration section 19. This is a means for checking whether or not the function symbol exists on the right side of the function symbol.
【0026】書き換え関数生成部16は、書き換え規則
登録部19に登録された書き換え規則のグループ毎に、
1つの書き換え関数を生成して、書き換え関数格納部1
4に格納する手段である。生成される書き換え関数は、
次のような機能、つまり呼び出し元から引数で与えられ
る変換対象部分木構造に基づき当該グループの何れの書
き換え規則の左辺部が変換対象部分木とマッチするかを
判断し、且つ、マッチする左辺部に対応する右辺部に定
義された部分木中に自グループまたは他グループの書き
換え規則の左辺部に定義された部分木の最外部関数記号
が存在するときは当該右辺部の定義に基づく変換後の部
分木の構造を引数として当該存在した最外部関数記号に
対応する書き換え関数を呼び出してその返却値を呼び出
し元に返却し、そのような最外部関数記号が存在しない
ときは当該右辺部の定義に基づく変換後の部分木の構造
を返却値として呼び出し元に返却する機能を持つ。The rewriting function generator 16 generates, for each group of rewriting rules registered in the rewriting rule
One rewrite function is generated, and the rewrite function storage unit 1
4 means. The generated rewrite function is
Based on the following function, that is, based on the subtree structure to be converted given by the caller as an argument, it is determined which rewrite rule of the relevant group matches the subtree to be converted, and the left side to be matched is determined. If the outermost function symbol of the subtree defined on the left side of the rewriting rule of the own group or another group exists in the subtree defined on the right side corresponding to Calls the rewrite function corresponding to the existing outermost function symbol with the structure of the subtree as an argument, returns the return value to the caller, and if there is no such outermost function symbol, the It has a function to return the structure of the subtree after conversion to the caller as a return value.
【0027】図6は書き換え規則コンパイル部15の処
理例を示すフローチャートである。以下、図1および図
6を参照して書き換え規則コンパイル部15の動作を説
明する。FIG. 6 is a flowchart showing a processing example of the rewriting rule compiling unit 15. Hereinafter, the operation of the rewrite rule compiling unit 15 will be described with reference to FIGS.
【0028】初期の状態においては、左辺最外部関数記
号登録部17および書き換え規則登録部19の内容はク
リアされている。コンパイル時、先ず、書き換え規則解
析部20は、書き換え規則集合入力部21を通じて書き
換え規則集合24を入力する(S1)。In the initial state, the contents of the leftmost outermost function symbol registration unit 17 and the rewrite rule registration unit 19 have been cleared. At the time of compiling, first, the rewrite rule analysis unit 20 inputs the rewrite rule set 24 through the rewrite rule set input unit 21 (S1).
【0029】次に、入力した書き換え規則集合24に含
まれる書き換え規則の各々に対してステップS2〜S5
の処理を行う。先ず、その書き換え規則の左辺部におけ
る最外部の関数記号(左辺最外部関数記号)が左辺最外
部関数記号登録部17に登録されているか否かを調べ
(S3)、登録されていなければ登録した後(S4)、
その書き換え規則をその左辺最外部関数記号に関連付け
て書き換え規則登録部19へ登録する(S5)。他方、
その書き換え規則の左辺最外部関数記号が既に左辺最外
部関数記号登録部17に登録されていれば、ステップS
4をスキップして、今回の書き換え規則をその左辺最外
部関数記号に関連付けて書き換え規則登録部19へ登録
する(S5)。以上の処理を全ての書き換え規則に対し
て繰り返した時点で(S6でYES)、書き換え規則解
析部20の処理が終了する。この時点で、左辺最外部関
数記号登録部17に、書き換え規則集合24に含まれる
書き換え規則の左辺部に定義された部分木の最外部関数
記号の種類が全て登録され、また、書き換え規則登録部
19に全ての書き換え規則が左辺最外部関数記号の種類
毎にグループ化されて登録されたことになる。Next, for each of the rewrite rules included in the input rewrite rule set 24, steps S2 to S5
Is performed. First, it is checked whether or not the outermost function symbol on the left side of the rewriting rule (leftmost outermost function symbol) is registered in the leftmost outermost function symbol registration unit 17 (S3). Later (S4),
The rewriting rule is registered in the rewriting rule registration unit 19 in association with the leftmost outermost function symbol (S5). On the other hand,
If the leftmost outermost function symbol of the rewriting rule has already been registered in the leftmost outermost function symbol registration unit 17, the process proceeds to step S
Step 4 is skipped and the current rewrite rule is registered in the rewrite rule registration unit 19 in association with the leftmost outermost function symbol (S5). When the above processing is repeated for all the rewrite rules (YES in S6), the processing of rewrite rule analysis unit 20 ends. At this time, all the types of the outermost function symbols of the subtree defined on the left side of the rewrite rule included in the rewrite rule set 24 are registered in the leftmost outermost function symbol registration unit 17. 19, all the rewrite rules are grouped and registered for each type of the leftmost outermost function symbol.
【0030】次に、右辺マーク部18は、書き換え規則
登録部19に登録されている書き換え規則の各々に対し
てステップS7〜S9の処理を行う。先ず、その書き換
え規則の右辺部に、左辺最外部関数記号登録部17に登
録されている関数記号が存在するか否かを調べ(S
8)、存在すれば、書き換え規則登録部19上でその存
在した関数記号にマークを付ける(S9)。他方、存在
しなければマーク付け処理は行わない。以上の処理を全
ての書き換え規則に対して繰り返した時点で(S10で
YES)、右辺マーク部18の処理が終了する。この時
点で、書き換え規則登録部19に格納されている書き換
え規則のうち、その右辺部に定義された部分木中に自グ
ループまたは他グループの書き換え規則の左辺部に定義
された部分木の最外部関数記号と同じ関数記号を持つ書
き換え規則については、その関数記号にマークが付けら
れたことになる。Next, the right side mark section 18 performs the processing of steps S7 to S9 for each rewrite rule registered in the rewrite rule registration section 19. First, it is checked whether or not a function symbol registered in the leftmost outermost function symbol registration unit 17 exists on the right side of the rewriting rule (S
8) If present, mark the existing function symbol on the rewriting rule registration unit 19 (S9). On the other hand, if it does not exist, the marking process is not performed. When the above processing is repeated for all the rewriting rules (YES in S10), the processing of the right side mark unit 18 ends. At this point, among the rewrite rules stored in the rewrite rule registration unit 19, the outermost subtree defined on the left side of the rewrite rule of the own group or another group is included in the subtree defined on the right side. For a rewrite rule having the same function symbol as the function symbol, the function symbol is marked.
【0031】次に、書き換え関数生成部16による書き
換え関数の生成と書き換え関数格納部14への格納とが
実行される(S11)。Next, the generation of the rewrite function by the rewrite function generation unit 16 and the storage in the rewrite function storage unit 14 are executed (S11).
【0032】図7は図6のステップS11の詳細を示す
フローチャートである。以下、図1および図7を参照し
て書き換え関数生成部16の動作を説明する。FIG. 7 is a flowchart showing details of step S11 in FIG. Hereinafter, the operation of the rewrite function generator 16 will be described with reference to FIGS.
【0033】書き換え関数生成部16は、左辺最外部関
数記号登録部17に登録されている関数記号単位に、ス
テップS21〜S30を実行することにより、その関数
記号に対応する書き換え関数を生成する。The rewriting function generating section 16 executes steps S21 to S30 for each function symbol registered in the leftmost outermost function symbol registering section 17, thereby generating a rewriting function corresponding to the function symbol.
【0034】先ず、左辺最外部関数記号登録部17に登
録されている1つの関数記号に注目し(S21)、それ
に対応する書き換え関数名を生成し、書き換え関数スケ
ルトンを生成する(S22)。次に、その関数記号に関
連付けられた全ての書き換え規則を書き換え規則登録部
19から入力し(S23)、その各々の書き換え規則に
ついて、ステップS24〜S28の処理を実行する。First, attention is paid to one function symbol registered in the leftmost outermost function symbol registration unit 17 (S21), a corresponding rewriting function name is generated, and a rewriting function skeleton is generated (S22). Next, all the rewriting rules associated with the function symbol are input from the rewriting rule registration unit 19 (S23), and the processes of steps S24 to S28 are executed for each rewriting rule.
【0035】先ず、1つの書き換え規則に注目し(S2
4)、その左辺部から必要に応じパターンマッチを行う
プログラム断片をスケルトン部に生成する(S25)。
パターンマッチを行うプログラム断片は、左辺部に定義
された部分木の構造に従ってパターンマッチを行うプロ
グラム部分、並びに左辺部に現れる変数の代入処理を行
うプログラム部分から構成される。次に、パターンがマ
ッチした場合に書き換え後の部分木の構造を返却するプ
ログラム断片を生成するが、右辺部にマークが有る場合
と無い場合とで作成するプログラム断片が異なるので、
現注目中の書き換え規則の右辺部にマークがあるか否か
を判定し、処理を切りわける(S26)。First, paying attention to one rewrite rule (S2
4) From the left side, a program fragment for performing pattern matching as necessary is generated in the skeleton part (S25).
A program fragment for performing a pattern match is composed of a program part for performing a pattern match in accordance with the structure of a subtree defined on the left side, and a program part for performing a process of substituting variables appearing on the left side. Next, a program fragment that returns the structure of the rewritten subtree when the pattern matches is generated, but the program fragment to be created differs depending on whether or not there is a mark on the right side.
It is determined whether or not there is a mark on the right side of the currently focused rewrite rule, and the processing is divided (S26).
【0036】右辺部にマークが有る場合は、当該右辺部
の定義に基づく変換後の部分木の構造を引数として当該
マークの付いた関数記号に対応する書き換え関数を呼び
出してその返却値を呼び出し元に返却するプログラム断
片をスケルトン部に生成する(S28)。If there is a mark on the right side, the rewriting function corresponding to the function symbol with the mark is called using the structure of the subtree after conversion based on the definition of the right side as an argument, and the return value is called by the caller. Is generated in the skeleton part (S28).
【0037】他方、右辺部にマークが無い場合は、当該
右辺部の定義に基づく変換後の部分木の構造を返却値と
して呼び出し元に返却するプログラム断片をスケルトン
部に生成する(S27)。On the other hand, when there is no mark on the right side, a program fragment for returning the structure of the subtree after conversion based on the definition of the right side to the caller as a return value is generated in the skeleton section (S27).
【0038】以上の処理を、ステップS23で入力した
全ての書き換え規則、つまり同じ左辺最外部関数を持つ
書き換え規則に対して実行することにより(S29)、
当該左辺最外部関数に対応する1つの書き換え関数を生
成し、これを書き換え関数格納部14に格納する(S3
0)。The above processing is executed for all the rewrite rules input in step S23, that is, for the rewrite rules having the same outermost function on the left side (S29).
One rewrite function corresponding to the leftmost outermost function is generated and stored in the rewrite function storage unit 14 (S3).
0).
【0039】以上のような処理を、左辺最外部関数記号
登録部17に登録された全ての関数記号単位に実行し終
えると(S31)、書き換え関数格納部14に、各左辺
最外部関数記号に対応する書き換え関数が格納されたこ
とになり、書き換え関数生成部16の処理が終了する。When the above processing is completed for all the function symbol units registered in the leftmost outermost function symbol registration unit 17 (S31), the rewriting function storage unit 14 stores each leftmost outermost function symbol in the rewriting function storage unit 14. Since the corresponding rewriting function has been stored, the processing of the rewriting function generator 16 ends.
【0040】図8は図3で例示した書き換え規則集合2
4に対して書き換え規則コンパイル部15の書き換え規
則解析部20および右辺マーク部18による処理が行わ
れた後の、左辺最外部関数記号登録部17および書き換
え規則登録部19の内容例を示している。図3に示す3
つの書き換え規則31〜33には、左辺最外部関数記号
として、a,bの2種類が存在するため、図8に示すよ
うに左辺最外部関数記号登録部17にはa,bの2つが
登録される。また、書き換え規則31,32はaを、書
き換え規則33はbを左辺最外部関数として持つため、
書き換え規則登録部19上では、書き換え規則31およ
び32が左辺最外部関数aを持つグループ81として登
録され、書き換え規則33は左辺最外部関数bを持つグ
ループ82として登録される。さらに、書き換え規則3
1および32の右辺部には、左辺最外部関数記号登録部
17に登録されている関数記号aが存在するため、図8
に示すように各々にマークが付けられる。FIG. 8 shows the rewrite rule set 2 illustrated in FIG.
4 shows an example of the contents of the leftmost outermost function symbol registration unit 17 and the rewrite rule registration unit 19 after the rewrite rule analysis unit 20 and the right-side mark unit 18 of the rewrite rule compilation unit 15 have performed the processing for No. 4. . 3 shown in FIG.
Since two rewriting rules 31 to 33 have two types of outermost function symbols on the left side, a and b, two of a and b are registered in the leftmost outermost function symbol registration unit 17 as shown in FIG. Is done. Also, since the rewriting rules 31 and 32 have a as the rewriting rule 33 and the rewriting rule 33 have b as the outermost function on the left side,
On the rewriting rule registration unit 19, the rewriting rules 31 and 32 are registered as a group 81 having the leftmost outermost function a, and the rewriting rule 33 is registered as a group 82 having the leftmost outermost function b. Furthermore, rewriting rule 3
Since the function symbols a registered in the leftmost outermost function symbol registration unit 17 exist on the right side of 1 and 32, FIG.
Each is marked as shown in FIG.
【0041】図9は書き換え関数格納部14に格納され
た書き換え関数の例を示す。この例の書き換え関数は、
図8で例示した左辺最外部関数記号登録部17および書
き換え規則登録部19の内容に基づき書き換え関数生成
部16によって生成されたものであり、何れもC言語の
一つの関数として生成されている。このうち、書き換え
関数91は、図8の書き換え規則登録部19に登録され
ているグループ81に属する2つの書き換え規則31,
32に基づき生成された、関数記号aを書き換える関数
であり、書き換え関数92はグループ82に属する1つ
の書き換え規則33に基づき生成された、関数記号bを
書き換える関数である。FIG. 9 shows an example of the rewrite function stored in the rewrite function storage unit 14. The rewrite function in this example is
It is generated by the rewriting function generator 16 based on the contents of the leftmost outermost function symbol registration unit 17 and the rewriting rule registration unit 19 illustrated in FIG. 8, and both are generated as one function in the C language. Among them, the rewrite function 91 is composed of two rewrite rules 31 belonging to the group 81 registered in the rewrite rule registration unit 19 in FIG.
The rewriting function 92 is a function for rewriting the function symbol a generated based on the function symbol 32, and the rewriting function 92 is a function for rewriting the function symbol b generated based on one rewriting rule 33 belonging to the group 82.
【0042】書き換え関数91には、引数として変数
X,Yが与えられる。また、書き換え規則31の左辺部
の構造は(X,1)であるため、そのパターンマッチを
行うif文として、変数Yが1か否かを調べるプログラ
ム断片「if(Y==1)」と、変数Yが1の場合の処
理を記述するプログラム断片「retrun a(X,
0)」とが含まれる。この後者のプログラム断片は、マ
ークが付いていない場合は書き換え規則31の右辺部の
構造に基づき変換後の部分木の構造「a(X,0)」を
返却値として呼び出し元に返却するプログラム断片とな
るが、マークが付いている場合には、この例に示すよう
に、右辺部の定義に基づく変換後の部分木の構造を引数
として関数記号aに対応する書き換え関数91(この例
の場合は自分自身)を直接呼び出してその返却値を呼び
出し元に返却するプログラム断片となる。同様に、書き
換え規則32の左辺部の構造は(X,0)であるため、
そのパターンマッチを行うif文として、変数Yが0か
否かを調べるプログラム断片「if(Y==0)」と、
変数Yが0の場合の処理を記述するプログラム断片「r
etrun b(X)」とが含まれる。この後者のプロ
グラム断片は、マークが付いていない場合は書き換え規
則32の右辺部の構造に基づき変換後の部分木の構造
「b(X)」を返却値として呼び出し元に返却するプロ
グラム断片となるが、マークが付いている場合には、こ
の例に示すように、右辺部の定義に基づく変換後の部分
木の構造を引数として関数記号aに対応する書き換え関
数92を直接呼び出してその返却値を呼び出し元に返却
するプログラム断片となる。なお、変数Yが1でも0で
もない場合は、書き換えが失敗した旨を示すNULL値
を呼び出し元に返却し得るようにするために、プログラ
ム断片「return NULL」が追加されている。The rewriting function 91 is given variables X and Y as arguments. Since the structure of the left side of the rewrite rule 31 is (X, 1), a program fragment “if (Y == 1)” for checking whether the variable Y is 1 or not is used as an if statement for performing the pattern matching. , A program fragment “rerun a (X,
0) ". If the latter program fragment is not marked, the program fragment that returns the converted subtree structure “a (X, 0)” to the caller as a return value based on the structure on the right side of the rewrite rule 31 However, when the mark is attached, as shown in this example, the rewriting function 91 corresponding to the function symbol a is used as an argument with the structure of the subtree after conversion based on the definition of the right side (in this example, Is a program fragment that directly calls itself) and returns its return value to the caller. Similarly, since the structure on the left side of the rewrite rule 32 is (X, 0),
As an if statement for performing the pattern matching, a program fragment “if (Y == 0)” for checking whether the variable Y is 0,
A program fragment “r” that describes the processing when the variable Y is 0
etrun b (X). " This latter program fragment is a program fragment that returns the subtree structure “b (X)” after conversion based on the structure on the right side of the rewrite rule 32 as a return value to the caller when no mark is attached. Is marked, as shown in this example, the rewriting function 92 corresponding to the function symbol a is directly called with the structure of the converted subtree based on the definition of the right side as an argument, and the returned value is Will be returned to the caller. When the variable Y is neither 1 nor 0, a program fragment “return NULL” is added so that a NULL value indicating that rewriting has failed can be returned to the caller.
【0043】他方、書き換え関数92は、引数として変
数Xが与えられる。そして、この場合、パターンマッチ
の必要性が無いので、変数Xを呼び出し元に返却するプ
ログラム断片(return X)が記述されている。On the other hand, the rewriting function 92 is given a variable X as an argument. In this case, since there is no need for pattern matching, a program fragment (return X) for returning the variable X to the caller is described.
【0044】次に、図1において、生成された書き換え
関数を使用して、プログラム仕様22からプログラム2
3を生成する部分について説明する。この部分は、仕様
入力部11と、書き換え装置12と、プログラム出力部
13と、書き換え関数格納部14とで構成される。Next, referring to FIG. 1, the program 2
3 will be described. This part includes a specification input unit 11, a rewriting device 12, a program output unit 13, and a rewriting function storage unit 14.
【0045】図10は書き換え装置12の処理例を示す
フローチャートである。以下、図1および図10を参照
してその動作を説明する。FIG. 10 is a flowchart showing a processing example of the rewriting device 12. The operation will be described below with reference to FIGS.
【0046】書き換え装置12は、先ず、仕様入力部1
1を通じてプログラム仕様22を入力して内部に展開す
る(S41)。次に、このプログラム仕様22に対して
最左最内戦略に基づいて探索した変換対象部分木の構造
を引数にしてその部分木の最外部関数記号に対応する書
き換え関数を呼び出す(S44)。そして、その返却さ
れる変換後の部分木の構造に基づき前記変換対象部分木
の書き換えを行い(S45)、ステップS42に戻って
再び最左最内戦略に基づいて変換対象部分木を探索す
る。以上の処理を書き換え可能な部分が無くなるまで繰
り返し(S43)、書き換え可能な部分が無くなった時
点の変換後の結果を自動生成結果のプログラムとしてプ
ログラム出力部13を通じて出力する(S46)。The rewriting device 12 firstly receives the specification input unit 1
Then, the program specification 22 is input through the step S1 and is developed therein (S41). Next, a rewrite function corresponding to the outermost function symbol of the subtree is called using the structure of the conversion target subtree searched based on the leftmost innermost strategy for the program specification 22 (S44). Then, the conversion target subtree is rewritten based on the structure of the returned converted subtree (S45), and the process returns to step S42 to search for the conversion target subtree again based on the leftmost innermost strategy. The above processing is repeated until there is no more rewritable part (S43), and the result after conversion at the time when there is no more rewritable part is output through the program output unit 13 as an automatically generated result program (S46).
【0047】例えば、書き換え関数格納部14に図9に
示される書き換え関数91,92が格納されており、図
2に例示したようなプログラム仕様22が入力された場
合、書き換え装置12は、先ず、最左最内部に現れる関
数記号bに対応する書き換え関数92を変数X=1を引
数として呼び出す。書き換え関数92は図9に示す通
り、変数Xをそのまま返却するので、書き換え装置12
は、最左最内部を変数Xに書き換える。つまり、図5の
「書き換え1」のような書き換えを行う。For example, when the rewriting functions 91 and 92 shown in FIG. 9 are stored in the rewriting function storage unit 14 and the program specification 22 illustrated in FIG. 2 is input, the rewriting device 12 first The rewriting function 92 corresponding to the function symbol b appearing at the leftmost innermost position is called using the variable X = 1 as an argument. Since the rewriting function 92 returns the variable X as it is, as shown in FIG.
Rewrites the leftmost innermost part into a variable X. That is, rewriting like “rewriting 1” in FIG. 5 is performed.
【0048】次に、書き換え装置12は、最左最内部に
現れる関数記号aに対応する書き換え関数91(以下、
第1の関数と呼ぶ)を変数X=1,Y=1を引数として
呼び出す。第1の関数である書き換え関数91は図9に
示す通り、変数Yが1の場合、変数X=1,Y=0を引
数として書き換え関数91(つまり自分自身。以下第2
の関数と呼ぶ)を直接呼び出す。この呼び出された第2
の関数である書き換え関数91では、変数Yが0なの
で、変数X=1を引数として書き換え関数92を直接呼
び出す。この呼び出された書き換え関数92では、その
変数X=1をそのまま呼び出し元の第2の関数に返却
し、第2の関数はそれを第1の関数に返却し、そして、
第1の関数である書き換え関数91は、呼び出し元の書
き換え装置12にそれを返却する。この結果、書き換え
装置12は、変換後の部分木の構造として、X=1を得
ることになり、最左最内部をX=1に書き換える。これ
は、図5に示す「書き換え5」に相当する。つまり、従
来必要であった「書き換え2」,「書き換え3」,「書
き換え4」が、1つの「書き換え5」で済むことにな
る。Next, the rewriting device 12 rewrites a rewriting function 91 (hereinafter, referred to as a rewriting function) corresponding to the function symbol a appearing at the leftmost innermost position.
(Referred to as a first function) with variables X = 1 and Y = 1 as arguments. As shown in FIG. 9, when the variable Y is 1, the rewriting function 91, which is the first function, uses the variables X = 1 and Y = 0 as arguments, that is, the rewriting function 91 (that is, itself; hereafter the second function).
Function is called directly. This called second
Since the variable Y is 0 in the rewriting function 91, the rewriting function 92 is directly called with the variable X = 1 as an argument. In the called rewriting function 92, the variable X = 1 is returned as it is to the caller's second function, and the second function returns it to the first function, and
The first function, the rewriting function 91, returns it to the calling rewriting device 12. As a result, the rewriting device 12 obtains X = 1 as the structure of the converted subtree, and rewrites the leftmost innermost part to X = 1. This corresponds to “Rewrite 5” shown in FIG. In other words, “rewrite 2”, “rewrite 3”, and “rewrite 4”, which were conventionally required, can be completed by one “rewrite 5”.
【0049】[0049]
【発明の効果】以上説明したように本発明によれば、木
構造を持つプログラム仕様を書き換え規則の集合を用い
て書き換えを行ってプログラムを生成する場合、書き換
え規則集合を予め解析しておくことによって、或る書き
換え規則の適用後に生成される木構造が、書き換え規則
集合中の他の書き換え規則によって書き換えられる可能
性がある場合、書き換え装置は書き換え規則を再度選択
することなく直接書き換えることができ、書き換え可能
な部分に適用可能な書き換え規則の選択に要するコスト
を低減でき、高速な書き換え、つまりプログラム生成が
可能となる。As described above, according to the present invention, when a program is generated by rewriting a program specification having a tree structure using a set of rewrite rules, the rewrite rule set must be analyzed in advance. Thus, when a tree structure generated after applying a certain rewrite rule may be rewritten by another rewrite rule in the set of rewrite rules, the rewrite device can directly rewrite the rewrite rule without selecting it again. The cost required for selecting a rewrite rule applicable to a rewritable portion can be reduced, and high-speed rewrite, that is, a program can be generated.
【図1】本発明の一実施例のプログラム自動合成装置の
ブロック図である。FIG. 1 is a block diagram of an automatic program synthesizing apparatus according to an embodiment of the present invention.
【図2】プログラム仕様の一例を示す図である。FIG. 2 is a diagram showing an example of a program specification.
【図3】書き換え規則集合の一例を示す図である。FIG. 3 is a diagram illustrating an example of a rewrite rule set.
【図4】図3の書き換え規則集合に含まれる各書き換え
規則を木構造で示す図である。4 is a diagram showing each rewrite rule included in the rewrite rule set of FIG. 3 in a tree structure.
【図5】書き換え規則によってプログラム仕様の変換を
繰り返す過程の説明図である。FIG. 5 is an explanatory diagram of a process of repeating conversion of a program specification according to a rewriting rule.
【図6】書き換え規則コンパイル部の処理例を示すフロ
ーチャートである。FIG. 6 is a flowchart illustrating a processing example of a rewriting rule compiling unit;
【図7】図6のステップ11の詳細な処理を示すフロー
チャートである。FIG. 7 is a flowchart showing a detailed process of step 11 in FIG. 6;
【図8】左辺最外部関数記号登録部および書き換え規則
登録部の登録内容の一例を示す図である。FIG. 8 is a diagram showing an example of registered contents of a leftmost outermost function symbol registration unit and a rewrite rule registration unit.
【図9】書き換え関数格納部に格納された書き換え関数
の例を示す図である。FIG. 9 is a diagram illustrating an example of a rewrite function stored in a rewrite function storage unit.
【図10】書き換え装置の処理例を示すフローチャート
である。FIG. 10 is a flowchart illustrating a processing example of a rewriting device.
10…プログラム自動合成装置 11…仕様入力部 12…書き換え装置 13…プログラム出力部 14…書き換え関数格納部 15…書き換え規則コンパイル部 16…書き換え関数生成部 17…左辺最外部関数記号登録部 18…右辺マーク部 19…書き換え規則登録部 20…書き換え規則解析部 21…書き換え規則集合入力部 22…プログラム仕様 23…プログラム 24…書き換え規則集合 DESCRIPTION OF SYMBOLS 10 ... Automatic program synthesis apparatus 11 ... Specification input part 12 ... Rewriting apparatus 13 ... Program output part 14 ... Rewriting function storage part 15 ... Rewriting rule compilation part 16 ... Rewriting function generation part 17 ... Left side outermost function symbol registration part 18 ... Right side Marking section 19: Rewriting rule registration section 20: Rewriting rule analysis section 21: Rewriting rule set input section 22: Program specification 23: Program 24: Rewriting rule set
Claims (2)
部分木の構造を、右辺部にその部分木の変換後の構造を
それぞれ定義した書き換え規則の集合を用いて、関数記
号を節とする木構造で表現されたプログラム仕様の変換
を繰り返してプログラムを生成するプログラム自動合成
装置において、 書き換え規則の集合を入力し、左辺部に定義された部分
木の最外部関数記号が同一である書き換え規則のグルー
プ毎に、呼び出し元から引数で与えられる変換対象部分
木構造に基づき当該グループの何れの書き換え規則の左
辺部が変換対象部分木とマッチするかを判断し、且つ、
マッチする左辺部に対応する右辺部に定義された部分木
中に自グループおよび他グループの何れかの書き換え規
則の左辺部に定義された部分木の最外部関数記号が存在
するときは当該右辺部の定義に基づく変換後の部分木の
構造を引数として当該存在した最外部関数記号に対応す
る書き換え関数を呼び出してその返却値を呼び出し元に
返却し、そのような最外部関数記号が存在しないときは
当該右辺部の定義に基づく変換後の部分木の構造を返却
値として呼び出し元に返却する書き換え関数を生成する
書き換え規則コンパイル部と、 変換対象とするプログラム仕様に対して最左最内戦略に
基づいて探索した変換対象部分木を引数にしてその部分
木の最外部関数記号に対応する書き換え関数を呼び出
し、その返却される変換後の部分木の構造に基づき前記
変換対象部分木の書き換えを行う処理を、変換可能な部
分木が無くなるまで繰り返す書き換え装置とを備えるこ
とを特徴とするプログラム自動合成装置。1. A function symbol is defined by using a set of rewrite rules defining a structure of a subtree for performing conversion in a program specification on a left side and a structure after conversion of the subtree on a right side. In an automatic program synthesizer that generates a program by repeatedly converting a program specification expressed in a tree structure, a set of rewrite rules is input, and a rewrite rule in which the outermost function symbol of the subtree defined on the left side is the same For each group of, based on the conversion target subtree structure given by the argument from the caller, determine which rewrite rule of the group of the left side of the group matches the conversion target subtree, and
If the outermost function symbol of the subtree defined on the left side of either the own group or the other group 's rewrite rule exists in the subtree defined on the right side corresponding to the matching left side, the right side When the rewrite function corresponding to the existing outermost function symbol is called using the structure of the subtree after the conversion based on the definition of the argument as an argument and the return value is returned to the caller, and such an outermost function symbol does not exist Is a rewrite rule compile unit that generates a rewrite function that returns the structure of the subtree after conversion based on the definition of the right side to the caller as a return value, and a leftmost innermost strategy for the program specification to be converted. The rewriting function corresponding to the outermost function symbol of the subtree is called by using the subtree searched based on the argument as an argument, and the structure of the returned subtree is converted to An automatic program synthesizing device, comprising: a rewriting device that repeats the process of rewriting the conversion target subtree based on the conversion target subtree until there is no more convertible subtree.
解析し、書き換え規則の左辺部に定義された部分木の最
外部関数記号の種類を前記左辺最外部関数記号登録部に
登録すると共に、入力した書き換え規則を前記最外部関
数記号の種類毎にグループ化して前記書き換え規則登録
部に登録する書き換え規則解析部と、 前記書き換え規則登録部に登録された書き換え規則の右
辺部に定義された部分木中に前記左辺最外部関数記号登
録部に登録された種類の関数記号が存在するか否かを調
べ、存在した右辺部の関数記号にマークを付ける右辺マ
ーク部と、 前記書き換え規則登録部に登録された書き換え規則のグ
ループ毎に、呼び出し元から引数で与えられる変換対象
部分木構造に基づき当該グループの何れの書き換え規則
の左辺部が変換元対象部分木とマッチするかを判断し、
且つ、マッチする左辺部に対応する右辺部にマークが付
いているときは当該右辺部の定義に基づく変換後の部分
木の構造を引数として当該マークが付いている関数記号
に対応する書き換え関数を呼び出してその返却値を呼び
出し元に返却し、マークが付いていないときは当該右辺
部の定義に基づく変換後の部分木の構造を返却値として
呼び出し元に返却する書き換え関数を生成する書き換え
関数生成部とを含むことを特徴とする請求項1記載のプ
ログラム自動合成装置。2. The rewriting rule compiling unit analyzes a rewriting rule included in a set of input rewriting rules, a leftmost outermost function symbol registration unit, a rewriting rule registration unit, and defines a rewriting rule on the left side of the rewriting rule. The type of the outermost function symbol registered in the subtree is registered in the outermost function symbol registration unit on the left side, and the input rewrite rules are grouped for each type of the outermost function symbol and registered in the rewrite rule registration unit. A rule analysis unit, and determines whether or not a function symbol of the type registered in the leftmost outermost function symbol registration unit exists in a subtree defined on the right side of the rewrite rule registered in the rewrite rule registration unit. The right-side mark part that checks and marks the existing function symbol on the right-side part, and for each rewrite rule group registered in the rewrite rule registration part, Left portion of any rewrite rule of the group is to determine matches the conversion source target subtree based on the converted partial tree structure given by the argument,
In addition, when a mark is attached to the right side corresponding to the matching left side, the rewriting function corresponding to the function symbol with the mark is used as an argument with the structure of the converted subtree based on the definition of the right side. Generates a rewrite function that calls and returns the return value to the caller, and if it is not marked, returns the structure of the subtree after conversion based on the definition of the right-hand side as the return value to the caller program automatic synthesizer according to claim 1, comprising a part.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP8090128A JP2904112B2 (en) | 1996-03-19 | 1996-03-19 | Automatic program synthesizer |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP8090128A JP2904112B2 (en) | 1996-03-19 | 1996-03-19 | Automatic program synthesizer |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| JPH09258970A JPH09258970A (en) | 1997-10-03 |
| JP2904112B2 true JP2904112B2 (en) | 1999-06-14 |
Family
ID=13989880
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP8090128A Expired - Fee Related JP2904112B2 (en) | 1996-03-19 | 1996-03-19 | Automatic program synthesizer |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP2904112B2 (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP4526833B2 (en) * | 2004-02-19 | 2010-08-18 | 株式会社ジャストシステム | Information processing system, storage device, processing device, and information processing method |
-
1996
- 1996-03-19 JP JP8090128A patent/JP2904112B2/en not_active Expired - Fee Related
Non-Patent Citations (1)
| Title |
|---|
| 「情報処理学会研究報告」Vol.95,No.114(95−PRO−4−3)P.13−18 |
Also Published As
| Publication number | Publication date |
|---|---|
| JPH09258970A (en) | 1997-10-03 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US5671416A (en) | Apparatus and a method for searching and modifying source code of a computer program | |
| US4860203A (en) | Apparatus and method for extracting documentation text from a source code program | |
| US6219831B1 (en) | Device and method for converting computer programming languages | |
| Swierstra et al. | Higher order attribute grammars | |
| US20040154009A1 (en) | Structuring program code | |
| JPH07219758A (en) | Specification generation method | |
| US7065753B2 (en) | Method, system and computer program for syntax validation | |
| Tai | Syntactic error correction in programming languages | |
| JP2904112B2 (en) | Automatic program synthesizer | |
| JPH0667871A (en) | Automatic program updating system | |
| Pugh | Extending Graham-Glanville techniques for optimal code generation | |
| JP3001427B2 (en) | Software coding system | |
| JPH1185536A (en) | Automatic error correction apparatus and method for source program | |
| Alblas | Incremental attribute evaluation | |
| JP2722358B2 (en) | Program creation support system | |
| JPS6349856A (en) | How to generate a neighbor configuration database | |
| JPH08272622A (en) | Program converter | |
| EP1465068A1 (en) | Improvements in structuring program code | |
| JPH08328841A (en) | Software generator | |
| Goettsche | Integrating pattern matching within string scanning | |
| Harford et al. | A new parsing method for non‐LR (1) grammars | |
| EP0153106A2 (en) | Retargetable code generator using up/down parsing | |
| Costagliola et al. | Towards syntax-aware editors for visual languages | |
| Swierstra et al. | Higher order attribute grammars, Lecture notes of the International Summer School on Attribute Grammars, applications and systems | |
| Alblas | Attributed tree transformations with delayed and smart re-evaluation |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20080326 Year of fee payment: 9 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20090326 Year of fee payment: 10 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20090326 Year of fee payment: 10 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20100326 Year of fee payment: 11 |
|
| LAPS | Cancellation because of no payment of annual fees |