JP2722465B2 - Data conversion method - Google Patents
Data conversion methodInfo
- Publication number
- JP2722465B2 JP2722465B2 JP62282371A JP28237187A JP2722465B2 JP 2722465 B2 JP2722465 B2 JP 2722465B2 JP 62282371 A JP62282371 A JP 62282371A JP 28237187 A JP28237187 A JP 28237187A JP 2722465 B2 JP2722465 B2 JP 2722465B2
- Authority
- JP
- Japan
- Prior art keywords
- data
- conversion
- class
- procedure
- conversion rule
- 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
Landscapes
- Devices For Executing Special Programs (AREA)
Description
【発明の詳細な説明】
〔産業上の利用分野〕
本発明は変換規則に基づく、データ変換装置による構
造体データから構造体データへの変換方法に関し、特に
処理系外部から与えられた変換規則に基づく、プログラ
ム変換,コンパイラ等の言語変換,プログラミング言語
のインタプリタ,記号実行,自動定理証明等に好適なデ
ータ変換方法に関する。
〔従来の技術〕
プログラミング言語のインタプリタ,コンパイラ,翻
訳等の言語変換,記号実行,自動定理証明等では、本構
造データを仲介としてデータ変換を行う場合が多い。例
えば、コンパイラの場合、文字の列である入力文を、文
の構造を本構造で表現した解析木へと変換し、この木構
造データに対して意味解析,最適化,コード生成を行
い、目的とする機械語へと変換する。この過程は、入力
された記号列を与えられた規則に従って変換する過程と
みなすことができる。従来、このような変換を行う装置
は、変換規則に基づいて設計されたものが多く、変換規
則が異なる毎に設計を変えなければならなかった。
これに対し、個々の変換規則に依存しない変換装置の
一例にパーサージェネレータがある。パーサージェネレ
ータは、入力された文法に基づいて構文解析を行う構文
解析装置を生成する。
構文解析では、文法は、通常、文法規則または書換え
規則,生成規則等と呼ばれる関係の集合Pと、終端記号
の集合Tと、非終端記号の集合Nおよび開始記号sによ
って記述される。文法規則は左辺と右辺から構成され、
左辺の記号列が右辺の記号列に書換えられることを表わ
す。非終端記号は上記文法規則または書換え規則,生成
規則等と呼ばれる関係の集合Pによって書換えることの
できる記号であり、終端記号は上記集合Pによって書換
えることのできない記号である。開始記号sは特別な非
終端記号であり、入力文が文法に適合するならば、sに
上記集合Pを適用することにより、入力文に書換えるこ
とができる。
文法の基本的なクラスの一つに、文脈自由文法があ
る。文脈自由文法とは、上記集合Pに属する文法規則の
左辺を一つの非終端記号、右辺を0個以上の終端,非終
端記号の並びに制約した文法、すなわち、各々の文法規
則が、
A→a A∈N,a∈(NUT)*
と表わされる文法である。ここで、( )*は集合の任
意の要素の0個以上の列を表わす。
一般に、従来のパーサージェネレータが扱う文法は、
文法規則に強い制約を加えたものである。このような文
法は、構文解析機構を簡単にする代償として、文の構造
の記述、すなわち、解析木の構造を自由に設定できない
難点を持つ。特に再帰構造を持つ文法の記述が著しい制
約を受ける。
これに対し、DCG(Definite Clause Grammar)では、
文法を文脈自由文法で記述し、記述した文法規則をProl
ogプログラムとみなして、Prolog処理系で実行すること
により、構文解析が遂行される。なお、上記DCGの詳細
は、F.Pereira and D.Warren,Definite Clause Grammar
s for Language Analysis−A Survey of the Formali
sm a Comparison with Augmented Transition Network
s,Artificial Intelligence,vol.13,pp.231−278(198
0)に掲載されており、ここではその概要を述べる。以
下、述語記号を英小文字列で、変数記号を大文字で始ま
る英文字列で表わす。
DCGは文法を一階の述語論理の節の集まりとして表現
する。この解釈に従えば、ある言語の文を構文解析する
ことは、言語を記述する公理系のもとで、定理を証明す
ることと解釈される。さらに、節の集まりはプログラム
であるとする考え方によれば、この定理証明は自動的に
行うことができる。その意味で、DCGで記述された文法
は、同時に一階の述語論理のもとで公理系であり、さら
にPrologプログラムとして実行可能である。このプログ
ラムの実行は、その言語のトップダウンパーサーの生成
である。
DCGの記法は、文脈自由文法の記法を、次の二点で拡
張したものである。
(1)非終端記号が引き数を持つことを許す。
例:
文脈自由文法 np
DCG np(X,S)
(2)文法規則の右辺に非終端記号や終端記号のリスト
だけでなく、手続き呼出しを書くことができる。
例:
文脈自由文法 name→NAME
DCG name(name(W))
→[W],{is_name(W)}
ここで、文脈自由文法の右辺に出現するNAMEは終端記
号であり、名前の字句カテゴリに属する特定の文字列を
表わす。DCGの右辺の{is_name(W)}は、文字列Wが
名前であるとき、真値を返す述語is_name(W)の呼出
しを表わす。
例えば、
sentence(s(NP,VP),S0,S)
→noun_phrase(NP,S0,S1),
verb_phrase(VP,S1,S).
(但し、S0,S1,Sは語列中の位置を表わす)
で始まる一連の文法規則と辞書がDCGとして与えられて
いるとき、入力文
[every,man,loves,mary]
に対して、前記文法規則と辞書がPrologプログラムとし
て実行されて、項
sentence(theta,[every,man,loves,mary],[])
が真となる。ここで、thetaは、項
s(np(det(every),n(man),rel(nil)),vp(tv
(loves),np(name(mary)))
であり、これは解析木と等価である。
DCGはさらに、次の記述を可能にしている。
(1)手続き呼出しを用いて、条件を与えることができ
る。
例:
date(D,M)
→month(M),[D],
{integer(D),0<D,D<32}.
この例では、M月D日という日付が、年を表わす句
(M)とそれに続く記号Dで記述されることを示す文法
規則において、Dが整数のとき真となる述語integer
(D)と、Dが正のとき真となる述語0<Dと、Dが32
より小さいとき真となる述語D<32を呼出し、Dを、0
より大きくて32より小さい整数に制約している。
(2)引き数を用いて、文脈に依存する情報を運搬しテ
ストすることができる。
この例では、noun_phrase,verb_phrase,その他、数の
影響を受ける非終端記号に数を運搬する引き数Nを付与
し、辞書で与えられた数singular,pluralをnoun_phras
e,verb_phraseまで運搬する。noun_phrase,verb_phrase
が運搬した数は、sentenceのレベルで照合され、一致す
る場合のみ述語sentenceは真となる。
以上をまとめるとDCGは次の特徴を有する。
(1)文脈自由文法を拡張した文法である。
(2)Prologプログラムとして実行することにより、構
文解析装置を生成する。
(3)構文解析の結果は、構文解析の際に使われた引終
端記号に引き数として与えた項であり、引き数の与え方
によって、単なる解析木とは異なる出力項を得ることが
可能である。
(4)文法規則に手続き呼出しを記述することができ
る。
(5)文脈に依存する文法規則を記述することができ
る。
〔発明が解決しようとする問題点〕
上述のDCGは、文法記述に引き数を導入してPrologプ
ログラムとして実行することにより、入力文から解析木
への変換規則である文法を自由に与えることのできる、
個々の変換規則に依存しない変換系を構成することを可
能にした。しかしながら、DCGは入力文から解析木への
変換を目的としており、構造体データから構造体データ
への変換を行うためには、入力の構造体データを予め、
文字列に展開し、文字列から構造体データへの変換とし
て処理しなければならない。これにより、構成要素の数
等、入力データが本来持っていた構造情報が失なわれ、
変換効率が悪化する。
本発明は上記事情に鑑みてなされたもので、その目的
とするところは、従来の技術における上述の如き問題を
解消し、変換規則を自由に与えることができ、与えられ
た変換規則に基づくデータ変換を効率良く実行可能な、
構造体データ変換方法を提供することにある。
〔問題点を解決するための手段〕
本発明の上述の目的は、変換規則に基づいて構造体デ
ータを構造体データに変換するデータ変換方法におい
て、構造体の部分構造をクラスに分類し、入力となる構
造体を前記クラス間の関係によって記述するとともに、
出力する構造体を前記クラスに関連付けて記述する変換
規則の記憶手段を設けて、変換すべき構造体データを入
力し、該変換すべき構造体データを解析し、前記変換規
則のクラスに分類するステップと、出力する構造体デー
タを前記変換規則のクラスに関連付けて再構成するステ
ップとを有することを特徴とするデータ変換方法によっ
て達成される。
ここで、前述の部分構造のクラスは文法記述における
非終端記号に対応するが、非終端記号が文法規則の適用
により文字列を生成するのに対し、ここに言うクラス
は、変換規則の適用により構造体を生成する点が異なる
ものである。
〔作用〕
前記部分構造のクラスは、入力として可能な構造体の
集合を部分構造について分類するため、入力となる構造
体を前記クラスを用いて記述し、出力する構造体をクラ
スに関連付けて記述することにより、構成要素の数等の
構造情報を損なうことなく、簡便に変換規則を記述する
ことができる。このとき、入力となる構造体は、変換規
則に記述するクラス間の関係により、クラスをその部分
構造のクラスに展開して導出される構造体であり、出力
する構造体は、部分構造のクラスを逆に縮約し、各々の
クラスに関連付けた構造体を総合して得られる構造体で
ある。
データ変換処理においても、部分構造のクラスを介
し、構造体データを解析し変換規則のクラスに分類する
ステップと、クラスに関連付けられた構造体の記述に従
って出力する構造体を形成するステップにより変換を行
うことにより、変換規則に記述された構造情報を変換処
理に直結させるとともに、部分構造についての重複計算
を回避し、効率の良い処理を可能とする。
〔実施例〕
以下、本発明の実施例を図面に基づいて詳細に説明す
る。
第2図は本発明に係わる構造体データ変換処理システ
ムの機能ブロック図である。図において、1〜3は処理
系の入出力であり、4〜8は処理系の機能構成を示して
いる。すなわち、1は変換規則、2は入力データであ
り、ともに処理系の入力である。また、3はデータ変換
を行って得られる出力データであり、処理系の出力であ
る。
4は与えられた変換規則を解析し、内部表現に変えて
後述する変換規則記憶部7に出力する変換規則解析部、
5は後述するパターンマッチ部6に与える変換規則を選
択して、中間構造体や出力データの形成を制御するパタ
ーンマッチ制御部、6は上述の、入力データと変換規
則,変換規則と中間構造体のパターンマッチに係わるパ
ターンマッチ部であり、また、7は前述の変換規則の内
部表現を記憶する変換規則記憶部、8は中間構造体を記
憶すると同時に、変換過程で得られる情報を蓄積する中
間構造体記憶部である。
次に、構造体データを項で表わし、本発明の機能を例
示する。項は、引数を持つ定数記号である関数記号を用
いて、次の如く定義する。
(i)0引き数の関数記号は項である。
(ii)fがn引き数の関数記号、r1,r2,‥‥rnが項であ
るとき、f(r1,r2,‥‥rn)は項である。
変数を含む項を、関数記号と変数記号上の項として次
の如く定義する。
(i)0引き数の関数記号は変数を含む項である。
(ii)変数記号は変数を含む項である。
(iii)gがm引き数の関数記号、s1,s2,‥‥smが変数
を含む項であるとき、g(s1,s2,‥‥sm)は変数を含む
項である。
クラス識別子を含む項を、関数記号,変数記号,クラ
ス識別子上の項として、次の如く定義する。
(i)0引き数の関数記号はクラス識別子を含む項であ
る。
(ii)変数記号はクラス識別子を含む項である。
(iii)クラス識別子はクラス識別子を含む項である。
(iv)hがn引き数の関数記号、t1,t2,‥‥tnがクラス
識別子を含む項であるとき、h(1t,t2,‥‥tn)はクラ
ス識別子を含む項である。
クラスを、それを構成する部分構造のクラスを用い
て、次の如く定義する。
<クラス定義>
クラス識別子==クラス識別子を含む項
クラス識別子を#を前置した英大文字、変数記号を_
を前置した英大文字、関数記号を英小文字列および英数
時として、次の五つのクラス定義によって表わされる構
造体について説明する。
#A==f(#B,#C) ‥‥(a)
#B==i ‥‥(b)
#B==j ‥‥(c)
#C==u ‥‥(d)
#C==v ‥‥(e)
上記(a)は、#Aが関数記号fとクラス#B,#Cか
ら構成されることを示し、(b),(c)は、クラスB
が関数記号iまたはjであることを、また、(d),
(e)は、クラスCが関数記号uまたはvであることを
それぞれ示す。
言い換えれば、各々のクラスは、項の集合、
#A={f(i,u),f(i,v),f(j,u),f(j,v)}
#B={i,j}
#C={u,v}
を表わしている。
入力データがf(i,u)であるとき、その構造は次の
如く解析される。
(1)f(i,u)と#Aをパターンマッチし、#B,#C
に対してそれぞれi,uをを束縛する。
(2)iと#Bをパターンマッチし、マッチする上記
(b)を選び出す。
(3)uと#Cをパターンマッチし、マッチする上記
(d)を選び出す。
このとき、クラス識別子#Aは処理の開始点となる。
このようなクラス識別子を、以下、開始記号と呼ぶ。
前述の如く、本発明においては、出力する構造体をク
ラスに関連付けて記述する。ここでは、出力する構造体
を変数を含む項で表わし、クラス識別子に変数を含む項
を後置したその関連を示す。変換過程で得られる情報
は、変数を含む項の変数記号を、項で置換えることによ
り蓄えられる。
前述のクラス定義の例に、出力する構造体を加え、次
の如き変換規則の例を考える。
#A[add(_X,_Y)]
==f(#B[_X],#C[_Y]) ‥‥(a′)
#B[zero]
==i ‥‥(b′)
#B[one]
==j ‥‥(c′)
#C[two]
==u ‥‥(d′)
#C[three]
==v ‥‥(e′)
以下の手順により、データ変換を行う。
(1)入力データf(i,u)と#Aをパターンマッチ
し、(a′)を選び出すと同時に、#B,#Cに対してi,
uを束縛する。
(2)iと#Bをパターンマッチし、マッチする
(b′)を(a′)の右辺の#Bと結合する。
(3)(a′)の変数_Xを、結合している(b′)の項
zeroで置換える。
(4)uと#Cをパターンマッチし、マッチする
(d′)を(a′)の右辺の#Cと結合する。
(5)(a′)の変数_Yを、結合している(d′)の項
twoで置換える。
(6)得られた項add(zero,two)を出力データとす
る。
ここで、クラス識別子と入力データの束縛、変数と出
力となるデータの束縛は、中間構造の節点に記録する。
第1図(a)〜(d)は本発明の基本的な処理動作を
示すフローチャートである。
第1図(a)は変換規則解析のメインフローであり、
この処理は変換規則解析部4が行う。変換規則解析部4
は、変換規則1と開始記号が与えられると、それらを読
取り(ステップ20)、クラス識別子に従って構造体をク
ラスに分類し、開始記号に対応するクラスに印を与える
(ステップ202)。変換規則をクラス単位に内部表現に
変えた後、クラス間の関係を解析し、クラスの間をチェ
インで連結して(ステップ203)、変換規則記憶部7に
出力する(ステップ204)。
第1図(b)は、データ変換のメインフローであり、
データの入出力,パターンマッチ制御部5の起動に係わ
る。入力データが与えられると、本データ変換処理系
は、それを読取る(ステップ301)とともに中間構造体
記憶部8に開始点となる節点を生成し、初期の環境を記
録して変換規則記憶部7から開始記号を得(ステップ30
2)、その節点を引き数として手続き1を呼出す(ステ
ップ303)。手続き1が成功したならば(ステップ30
4)、ステップ302で生成した節点上に記録された出力デ
ータを得(ステップ305)、出力する(ステップ306)。
そうでなければ、入力データの構文エラーを出力する
(ステップ307)。
第1図(c)は、第1図(b)ステップ303に示した
手続き1の処理フローであり、この処理は前記パターン
マッチ制御部5が行う。手続き1の引き数は中間構造体
の節点であり、与えられた節点からクラス識別子とデー
タとを得(ステップ401)、変換規則記憶部7から、そ
のクラス識別子を左辺に持つ変換規則を得る(ステップ
402)。このような変換規則が得られたなら(ステップ4
03)、その変換規則と上記ステップ401で得たデータを
引き数として手続き2を読出し(ステップ404)、ステ
ップ402へ戻る。このような変換規則すべてについての
処理が終了し、そのすべてについて手続き2が失敗した
ならば(ステップ405)、失敗を返し(ステップ406)、
そうでない場合には成功を返す(ステップ407)。
第1図(d)は上記ステップ404に示した手続き2の
処理フローであり、この処理は前述のパターンマッチ部
6が行う。上記手続き2の引き数は変換規則と入力デー
タであり、引き数の変換規則とデータとをパターンマッ
チし(ステップ501)マッチしないならば(ステップ50
2)、失敗を返す(ステップ509)。
マッチする場合は、中間構造体記憶部8を調べて(ス
テップ503)、マッチした変換規則の右辺のクラス識別
子とデータの組を持つ節点が存在しないならば節点を生
成する(ステップ504)。そして節点に現在の環境を記
録する(ステップ505)。変換規則の右辺に含まれるす
べてのクラス識別子について順に(ステップ506)、節
点を引き数として手続き1を呼出し(ステップ507)、
手続き1が成功したならば(ステップ508)、次のクラ
ス識別子の処理を行う(ステップ506)。もし途中で一
つでも失敗したならば、失敗を返す(ステップ509)。
第1図(b)に示した処理は、予め変換テーブルの形
にしたものを入力するようにしても良い。
本発明は、ハードウェアによっても、ソフトウェアに
よっても実施することができる。以下の説明において
は、ソフトウェアによる一実施例を説明する。
第3図は変換規則記憶部7が記憶する情報の一例であ
る。また、第4図は中間構造体記憶部8が記憶する情報
の一例である。第4図において、71は中間構造体の節点
の詳細である。ここでフラグは、節点がポイントするす
べての副節点列のパターンマッチに成功したときtrue、
そうでないときfalseとする。72は中間構造体のリーフ
の詳細、73は副節点の詳細である。副節点は、関係の左
辺のクラス識別子または変数記号と入力データの束縛を
表わす。74は節点結合情報の詳細である。節点結合情報
は、中間構造体の節点間の結合をリスト構造を用いて表
わす。
第6図(a)〜(e)は、本発明の一実施例の処理手
順の詳細を示すフローチャートである。
第6図(a)は、メインルーチンのフローチャートで
あり、データの入出力とパターンマッチ制御部5の起動
を行う。すなわち、入力データを読取り(ステップ90
1)、開始点となる特別な節点と副節点を生成し(ステ
ップ902)、その環境を初期化する(ステップ903)。ま
た、変換規則記憶部7から開始記号を得、該開始記号,
入力データおよび上述のステップ902で生成した副節点
を引き数として手続き1を読出し(ステップ904)、手
続き1が節点に設定した環境のもとで出力データを評価
し(ステップ905)、出力する(ステップ906)。
第6図(b)は、上記手続き1のフローチャートであ
る。手続き1は、クラス識別子,入力データ,副節点を
引き数としてパターンマッチを行う。まず、変換規則記
憶部7から引き数のクラス識別子を左辺に持つ変換規則
を得(ステップ1001)、対応する変換規則が存在しない
場合(ステップ1002)戻り(return)、そうでない場合
は、中間構造体記憶部8から引き数のデータを第1要素
とする節点を捜し(ステップ1003)、存在しないなら
ば、変換規則の第2要素とデータ,副節点を引き数とし
て手続き2を呼出し(ステップ1004)、ステップ1001へ
戻る。また、上記節点が存在するときは、引き数の副節
点へのポインタが親副節点へのポインタ集合にあるなら
ば(ステップ1005)、ステップ1001へ戻り、そうでなけ
れば、副節点へのポインタを集合に加え(ステップ100
6)、節点のフラグがtrueならば(ステップ1007)ステ
ップ1001へ、そうでなければ、節点と副節点を引き数と
して手続き4を呼出し(ステップ1008)、ステップ1001
へ戻る。
第6図(c)は、上記手続き2のフローチャートであ
る。手続き2はクラス識別子を含む項,入力データ,副
節点を引き数として、中間構造体の節点の生成と、クラ
ス識別子を含む項と入力データのパターンマッチ、副節
点の生成を行う。まず、節点を生成し(ステップ110
1)、変換規則の第2要素と節点をパターンマッチする
(ステップ1102)。パターンマッチに失敗した場合(ス
テップ1103)戻り、成功したならば、変換規則の入力の
パターンがクラス識別子を含むかを調べ(ステップ110
4)、含まないならば、節点を引き数として手続き3を
呼出し(ステップ1105)、そうでなければ、副節点を生
成し(ステップ1106)、生成した副節点とその第1,第3
要素を引き数として手続き1を呼出す(ステップ110
7)。
第6図(d)は、手続き3のフローチャートである。
手続き3は、中間構造体の節点を引き数として節点結合
情報の生成と節点の結合を行う。まず、節点のフラグを
trueとし(ステップ1201)、節点の第2要素から親副節
点を得る(ステップ1202)。親副節点が存在しないなら
ば(ステップ1203)戻り、また、存在するならば、節点
へのポインタと親の副節点の第5要素を組にして節点結
合情報を生成し(ステップ1204)、親の副節点の節点結
合情報に加え(ステップ1205)、親の副節点の第6要素
から次の親副節点を得る(ステップ1206)。次の親副節
点が存在するならば(ステップ1207)、得た副節点とそ
の第1,第3要素を引き数として手続き1を呼出し(ステ
ップ1208)、ステップ1202へ戻る。そうでなければ、親
の副節点から辿った親の節点を引き数として手続き3を
呼出し(ステップ1209)、ステップ1202へ戻る。
第6図(e)は上記手続き4のフローチャートであ
る。手続き4は中間構造体の節点と副節点を引き数とし
て、節点結合情報の生成と節点の共有化を行う。まず、
引き数と節点と副節点から節点結合情報を生成し(ステ
ップ1301)、副節点の第5要素の節点結合情報に加え
(ステップ1202)、副節点の第6要素から次の副節点を
得る(ステップ1203)。次の副節点が存在するならば
(ステップ1304)、得た副節点とその第1,第3要素を引
き数として手続き1を呼出し(ステップ1305)、次の副
節点が存在しないならば、副節点から辿った親節点を引
き数として手続き3を呼出す(ステップ1306)。
第5図は、前記変換規則の例について、変換規則と中
間構造体の内部表現を示した図である。本実施例の処理
の理解を助けるため、以下、第5図を用いて補足説明を
行う。
61(1)〜61(5)は、前記変換規則解析部4により
解析された変換規則であり、61(1)には開始記号の印
が付けられ、61(1)から61(2),61(3)へは#B
によるチェインが、61(1)から61(4),61(5)へ
は#Cによるチェインが張られる。
71(1)は、構造体をクラスに分類する際のトップレ
ベルを示す節点で、メインルーチンは、これを副節点73
(1)とともにステップ902で生成し、#A,f(i,u),73
(1)を引き数として手続き1を呼出す(ステップ90
4)。手続き1は、ステップ1001で#Aを左辺に持つ変
換規則61(1)を捜し出し、f(#B,#C),f(i,u),
73(1)を引き数として手続き2を呼出す(ステップ10
04)。手続き2は、節点71(2)を生成し(ステップ11
01)、f(#B,#C)とf(i,u)をパターンマッチす
る(ステップ1102)。このパターンマッチにより、#B
とi,#Cとuがマッチするので、73(2)、73(3)を
生成し(ステップ1106)、73(2)の第6要素を73
(3)とし、#Bとi,73(2)を引き数として手続き1
を呼出す(ステップ1107)。
手続き1は、#Bを第1要素に持つ変換規則61
(2),61(3)を捜し出し(ステップ1001)、i,i,73
(2)の組と、i,j,73(2)の組のそれぞれについて、
手続き2を呼出す(ステップ1004)。i,j,73(2)を引
き数として呼出された手続き2は、節点72(2)を生成
し(ステップ1101)、iとjをパターンマッチするが
(ステップ1102)、マッチしないので手続き1に戻る。
一方、i,i,73(2)を引き数として呼出された手続き
2は、節点72(1)を生成し(ステップ1101)、iとi
をパターンマッチし(ステップ1102)、マッチするので
72(1)を引き数として手続き3を呼出す(ステップ11
05)。手続き3は、72(1)のフラグをtrueにし(ステ
ップ1201)、72(1)の第2要素から73(2)を得(ス
テップ1202)、72(1)と73(2)の第5要素(初期値
はnil)を組にして74(2)を生成して73(2)の第5
要素とし(ステップ1204,1205)、73(2)の第6要素
から73(3)を得(ステップ1206)、#Cとu,73(3)
を引き数として手続き1を呼出す(ステップ1208)。
ここで、#Bとi,73(2)に対して行ったのと同様の
処理を行い、72(4),72(3)を生成し、74(3)を
通じて73(3)に接続する(ステップ1205)。73(3)
の第6要素はnilなので(ステップ1207)、73(3)の
第2要素である71(2)を引き数として手続き3を呼出
す(ステップ1209)。手続き3は、71(2)のフラグを
trueにし(ステップ1201)、73(1)を得(ステップ12
02)、74(1)を生成して73(1)の第5要素とし(ス
テップ1205)、73(1)の第6要素がnilなので71
(1)を引き数として手続き3を呼出す(ステップ120
9)。手続き3は、71(2)のフラグをtrueにし、73
(1)を得(ステップ1201,1202)、74(1)を生成し
(ステップ1204)て73(1)の第5要素とし(ステップ
1205)、73(1)の第6要素がnilなので71(1)を続
き数として手続き3を呼出す。手続き3は、71(1)の
フラグをtrueにし71(1)の第2要素から親副節点を得
るが(ステップ1202)、nilなので(ステップ1203)呼
出し側の手続き3に戻る。呼出し側の手続き3は、71
(2)の親副節点の処理が終ったので、更に呼出し側の
手続き3に戻る。このようにして次々に手続きが開放さ
れ、制御はメインルーチンのステップ905へ移る。
ステップ905は、トップレベルの節点71(1)の出力
パターン_Xを、副節点73(1),節点結合情報74(1)
を経て、節点71(2)の出力パターン前記add(_X,_Y)
と束縛する。ここで、節点結合情報を通じて副節点と結
合する節点は、一般には複数あるが、それら子節点の出
力パターンの各々と親節点の出力パターンを束縛する。
71(1)の出力パターンと71(2)の出力パターンを束
縛したのと同様に、71(2)の出力パターンの変数記号
_Xは、副節点73(2)を経由して節点72(1)の出力パ
ターンzeroに、変数記号_Yは副節点73(3)を経由して
節点72(3)の出力パターンtwoに束縛される。
これらの束縛の結果、すべての変数記号が置き換わ
り、項add(zero,two)ができる。処理系は、この項を
出力し(ステップ906)、変換処理を終了する。
本実施例では、節点結合情報が集合化されていること
から、複数の中間構造体が重ね合せて表現され、中間構
造体が占めるメモリサイズを縮小している。
第4図,第3図に示した内部表現は、論理的に同等な
別の表現、例えば、リストによる表現の代りに、テーブ
ルによる表現等を用いても実施できる。また、第4図の
入力データへのポインタは、入力データを識別し、パタ
ーンマッチに十分な情報を持つ他の情報で置換えること
ができる。他の情報に関しても同様である。更に、複数
の中間構造体を重ね合せて表現する必要がないならば、
節点結合情報は不要である。
なお、第1図(a)〜(e)に示した処理は、逐次的
にも、並列にも実施可能である。
本発明は、抽象データ型の表現に利用することができ
る。次のように定義される二つのデータ型SEQITEM,VECT
ORを例にとり、これを示す。
sort :SEQITEM
operations:nlsq →SEQITEM
apdl ITEM,SEQITEM→SEQITEM
car SEQITEM→ITEM
cdr SEQITEM→SEQITEM
isnil SEQITEM→BOOLEAN
laws :car(apdl(_i,_s)) =_i
cdr(apdl(_i,_s)) =_s
isnil(nlaq) =true
isnil(apdl(_i,_s))=false
sort :VECTOR
operations:emptyv →VECTOR
assign VECTOR,INDEX,ITEM
→VECTOR
read VECTOR,INDEX→ITEM
laws :read(emptyv,_ix) =undefined
:read(assign(_v,_ix1,_i),_ix2)
=if _ix1=_ix2
then _i
else read(_v,_ix2)
データ型SEQITEMのVECTORによる実現は、次の如く表
わされる。
dSEQITEM(nlsq)=emptyv
dITEM SEQITEM SEQITEM(apdl(_i,_s))
=<assign(vector(_s),size(_s)+1,_i),size
(_s)+1>
dSEQITEM ITEM(car(_s))
=read(vector(_s),size(_s))
dSEQITEM SEQITEM(cdr(_s))
=<vector(_s),size(_s)−1>
本実施例では、これを、以下の変換規則として与え
る。
#SEQITEM[_s]
==#SZDVCT[_s]
#SZDVCT[<_v,_ix>]
==<#VECTOR[_v],#INDEX[_iv]>
#SZDVCT[<emptyv,zero>]
==nlsq
#SZDVCT[<assign(_v,_ix+1,_i),_ix+1>]
==apdl(#ITEM[_i],#SEQITEM[<_v,_ix
>])
#ITEM[read(_v,_ix)]
==car(#SEQITEM[<_v,_ix>]
#SZDVCT[<_v,_ix−1>]
==cdr(#SEQITEM[<_v,_ix>]
入力データとして、式
car(cdr(cdr(apdl(C,apdl(B,apdl(A,ni
l))))))
を与えると、この変換規則により、式
read(
<assign(
<assign(
<assign(
<emptyv,1>
1,A),1>,
2,B),2>,
3,C),3>
,1)
へと変換される。
本発明を用いて、代数的に記述した仕様を実行するこ
とができる。抽象データ型はデータ型の代数的仕様記述
とみなすことができるので、前述のSEQITEMを例にと
る。lawsは本実施例の変換規則では、次のように表わさ
れる。
#SEQITEM[nlsq]
==nlsq
#SEQITEM[apdl(_i,_s)]
==apdl(#ITEM[_i],#SEQITEM[_s])
#ITEM[_i]
==car(apdl(#ITEM[_i],#SEQITEM[_
s]))
#EXP[_s]
=cdr(apdl(#ITEM[_i],#SEQITEM[_s]))
#BOOLEAN[true]
==isnil(nlsq)
#BOOLEAN[false]
==isnil(apdl(_i,_s))
#EXP[apdl(_e)]
==apdl(#EXP[_e]
#ITEM[car(_e)]
=car(#EXP[_e])
#EXP[cdr(_e)]
==cdr(#EXP[_e])
この変換規則を繰り返し適用することにより、式
car(cdr(cdr(apdl(C,apdl(B,apdl(A,ni
l))))))
は、
car(cdr(apdl(B,apdl(A,nil))))
car(apdl(A,nil))
A
と変換される。本実施例では、メインルーチンのステッ
プ902〜095を繰り返し実行することにより、この繰り返
しを実現することができる。
本実施例の変換規則は、他の記法によっても実施する
ことができる。その一例を次に示す。
<変換規則>→
<クラス定義><演算規則>の並び
<クラス定義>→
クラス識別子→
クラス識別子を含む項
<演算規則>→
==変数を含む項{<束縛式>の並び}
<束縛式>→
変数を含む項==クラス識別子
この記法により記述した、前記変換規則の例を次に示
す。
#SEQITEM→#SZDVCT
==_x
{_x==#SZDVCT}
#SZDVCT→<#VECTOR,#INDEX>
==<_v,_ix>
{_v==#VECTOR,_ix==#INDEX}
#SZDVCT→nlsq
==<empty,zero>
#SZDVCT→apdl(#ITEM,#SEQITEM)
==<assign(_v,_ix+1,_i),_ix+1>
{_i==#ITEM,<_v,_ix>==#SEQITEM}
#ITEM→car(#SEQITEM)
==read(_v,_ix)
{<_v,_ix>==#SEQITEM}
#SZDVCT→cdr(#SEQITEM)
==<_v,_ix−1>
{<_v,_ix>==#SEQITEM}
このように記述された変換規則に対しても、前記ステ
ップ201,同202を変換規則の記法に適合させるのみで、
他の処理を変更することなく、変換を行うことができ
る。
〔発明の効果〕
異常述べた如く、本発明によれば、変換規則に基づい
て構造体データを構造体データに変換するデータ変換方
法において、構造体の部分構造をクラスに分類し、入力
となる構造体を前記クラス間の関係によって記述すると
ともに、出力する構造体を前記クラスに関連付けて記述
する変換規則の記憶手段を設けて、変換すべき構造体デ
ータを入力し、該変換すべき構造体データを解析し、前
記変換規則のクラスに分類するステップと、出力する構
造体データを前記変換規則のクラスに関連付けて再構成
するステップとを有する如く構成したことにより、DCG
の如く構造体の持つ構造情報を失うことなく、変換規則
を自由に与えることができ、与えられた変換規則に基づ
くデータ変換を効率良く実行可能な、構造体データ変換
方法を実現できるという顕著な効果を奏するものであ
る。DETAILED DESCRIPTION OF THE INVENTION
[Industrial applications]
According to the present invention, the structure of the data conversion device is based on the conversion rule.
Regarding the conversion method from structure data to structure data, especially
A program based on conversion rules given from outside the processing system.
Language conversion, language conversion such as compiler, programming language
Suitable for interpreters, symbolic execution, automatic theorem proofs, etc.
Data conversion method.
[Conventional technology]
Programming language interpreter, compiler, translation
Language conversion of translation, symbol execution, automatic theorem proof, etc.
In many cases, data conversion is performed by using structured data as an intermediary. An example
For example, in the case of a compiler, input statements that are character strings
Is converted to an analytic tree represented by this structure, and this tree structure
Perform semantic analysis, optimization, and code generation for structural data
And convert it to the target machine language. This process is input
Converting the given symbol string according to a given rule; and
Can be considered. Conventionally, a device that performs such conversion
Are often designed based on conversion rules.
The design had to be changed every time the rules were different.
In contrast, conversion devices that do not depend on individual conversion rules
One example is a parser generator. Parser Genere
Is a syntax that performs parsing based on the grammar entered.
Generate an analyzer.
In parsing, the grammar is usually a grammar rule or rewriting.
A set P of relations called rules, production rules, etc., and terminal symbols
And a set N of non-terminal symbols and a start symbol s
Is described. The grammar rule consists of the left and right sides,
Indicates that the symbol string on the left side is rewritten to the symbol string on the right side.
You. Non-terminal symbols are grammatical rules or rewriting rules described above,
Rewriting by a set of relations P called rules
The terminal symbol can be rewritten by the above set P.
It is a sign that cannot be obtained. The starting symbol s is a special non-
Is a terminal symbol, and if the input sentence conforms to the grammar,
By applying the above set P, the input sentence can be rewritten.
Can be.
One of the basic classes of grammar is context-free grammar.
You. The context-free grammar is defined as a grammar rule belonging to the set P
One non-terminal symbol on the left side, zero or more terminals on the right side, non-terminal
A sequence of terminal symbols and a restricted grammar, that is, each grammar rule
The rule is
A → a A∈N, a∈ (NUT)*
It is a grammar expressed as here,( )*Is the responsibility of the set
Represents zero or more columns of meaning elements.
In general, the syntax used by traditional parser generators is
It is a grammar rule with strong restrictions. Statement like this
The cost of simplifying the parser is the structure of the sentence.
Description, that is, the analytic tree structure cannot be set freely
Has difficulties. In particular, grammars with recursive structures are notably described.
Receive about.
In contrast, DCG (Definite Clause Grammar)
Write the grammar in context-free grammar and write the grammar rules
og program and executed by Prolog processing system
Performs a syntax analysis. The details of the above DCG
Is F. Pereira and D. Warren, Definite Clause Grammar
s for Language Analysis-A Survey of the Formali
sm a Comparison with Augmented Transition Network
s, Artificial Intelligence, vol. 13, pp. 231-278 (198
0), and here is an overview. Less than
Below, start the predicate symbol with a lowercase letter and the variable symbol with an uppercase letter.
Expressed as an English character string.
DCG expresses grammar as a set of first-order predicate logic clauses
I do. Following this interpretation, parse a sentence in a language
This proves the theorem under an axiomatic system that describes a language.
Is interpreted as In addition, a set of clauses is a program
According to the notion that this theorem proves automatically
It can be carried out. In that sense, the grammar described in DCG
Is also axiom-based under first-order predicate logic, and
It can be executed as a Prolog program. This blog
Running the ram generates a top-down parser for that language
It is.
The DCG notation extends the notation of context-free grammar in two ways:
It is a stretch.
(1) Allow nonterminals to have arguments.
Example:
Context-free grammar np
DCG np (X, S)
(2) List of nonterminals and terminal symbols on the right side of the grammar rules
Not only can you write procedure calls.
Example:
Context-free grammar name → NAME
DCG name (name (W))
→ [W], {is_name (W)}
Here, NAME appearing on the right side of the context-free grammar is
Number, a specific string belonging to the lexical category of the name.
Express. {Is_name (W)} on the right side of DCG is
Calling a predicate is_name (W) that returns a true value if it is a name
Represents
For example,
sentence (s (NP, VP), S0, S)
→ noun_phrase (NP, S0, S1),
verb_phrase (VP, S1, S).
(However, S0, S1, S represent the position in the word string)
A series of grammar rules and dictionaries starting with are given as DCG
When input text
[Every, man, loves, mary]
In contrast, the grammar rules and dictionary are
Executed
sentence (theta, [every, man, loves, mary], [])
Becomes true. Where theta is a term
s (np (det (every), n (man), rel (nil)), vp (tv
(Loves), np (name (mary)))
Which is equivalent to a parse tree.
The DCG also allows the following description:
(1) Condition can be given using procedure call
You.
Example:
date (D, M)
→ month (M), [D],
{Integer (D), 0 <D, D <32}.
In this example, the date M / D is a phrase representing the year.
(M) followed by the grammar D
Predicate that is true if D is an integer
(D), a predicate 0 <D that is true when D is positive, and D is 32
Call the predicate D <32, which is true when less than, and let D be 0
Constrains to an integer greater than 32.
(2) Using arguments to carry context-sensitive information
You can strike.
In this example, noun_phrase, verb_phrase,
Add an argument N to carry the number to the affected nonterminal
And noun_phras the given number singular, plural in the dictionary
e, transport to verb_phrase. noun_phrase, verb_phrase
The number carried by is matched at the sentence level and matches
Predicate sentence is true only if
In summary, DCG has the following features.
(1) A grammar that extends the context-free grammar.
(2) By executing it as a Prolog program,
Generate a sentence analyzer.
(3) The result of the parsing is the final
A term given as an argument to the end symbol, and how to give the argument
Can give different output terms than just a parse tree.
It is possible.
(4) Procedure calls can be described in grammar rules
You.
(5) grammar rules that depend on the context can be described
You.
[Problems to be solved by the invention]
The DCG described above introduces arguments to the grammar description and
Parse tree from input sentence
You can freely give the grammar that is the conversion rule to
A conversion system that does not depend on individual conversion rules can be configured.
Functioned. However, DCG converts input sentences to parse trees.
For the purpose of conversion, from structure data to structure data
In order to convert to, the structure data of the input
Expand to a string and convert it from string to structure data
Must be processed. This allows the number of components
Such as the structural information originally held by the input data is lost,
Conversion efficiency deteriorates.
The present invention has been made in view of the above circumstances,
However, the above-mentioned problem in the conventional technology is solved.
Can be freely given and given conversion rules, given
Data conversion based on the conversion rules
An object of the present invention is to provide a structure data conversion method.
[Means for solving the problem]
SUMMARY OF THE INVENTION The above object of the present invention is to provide a structure data conversion method based on a conversion rule.
Data conversion method to convert data into structure data
Classify the substructures of the structure into classes,
The structure is described by the relationship between the classes,
Conversion that describes the output structure in association with the class
Provision of rules storage means to input structure data to be converted
To analyze the structure data to be converted,
Classifying into the rule class and the structure data to be output
Step for associating the data with the conversion rule class
Data conversion method characterized by having
Achieved.
Here, the class of the partial structure described above is used in the grammar description.
Corresponds to a non-terminal, but the non-terminal applies grammar rules
Generates a string by
Differs in that a structure is generated by applying a transformation rule
Things.
[Action]
The class of the substructure is
Input structure for classifying sets into substructures
Is described using the above class, and the output structure is
By describing in association with the
Write conversion rules easily without losing structure information
be able to. At this time, the input structure is
Classes are part of the relationship between the classes described in the rule.
A structure that is derived by expanding to the structure class
Structs reduce the classes of substructures in reverse, and
A structure obtained by combining the structures associated with the class
is there.
Even in the data conversion process, through the substructure class
Analyze structure data and classify it into conversion rule classes
Follow the steps and description of the structure associated with the class.
Conversion by the step of forming a structure
The conversion of the structural information described in the conversion rules
Calculate directly, and duplicate calculation for partial structure
And efficient processing can be performed.
〔Example〕
Hereinafter, embodiments of the present invention will be described in detail with reference to the drawings.
You.
FIG. 2 shows a structure data conversion processing system according to the present invention.
It is a functional block diagram of a program. In the figure, 1-3 are processing
4-8 show the functional configuration of the processing system
I have. That is, 1 is a conversion rule and 2 is input data.
Both are inputs to the processing system. 3 is data conversion
Is the output data obtained by performing
You.
4 analyzes the given conversion rules and converts them into internal representations
A conversion rule analysis unit that outputs to a conversion rule storage unit 7 described below;
5 selects a conversion rule to be given to a pattern matching unit 6 described later.
To control the formation of intermediate structures and output data.
The match match control unit 6 receives the input data and the conversion rule described above.
Rules, conversion rules, and patterns related to pattern matching of intermediate structures.
A turn match part, and 7 is one of the conversion rules described above.
8 is a conversion rule storage unit for storing an internal expression,
At the same time as remembering the information obtained during the conversion process
An inter-structure storage unit.
Next, the structure data is represented by terms, and the function of the present invention is shown as an example.
Show. Terms use function symbols, which are constant symbols with arguments
Therefore, it is defined as follows.
(I) The function symbol of the 0 argument is a term.
(Ii) f is a function symbol with n arguments, and r1, r2, and ‥‥ rn are terms
Where f (r1, r2, ‥‥ rn) is a term.
The term including the variable is defined as
Is defined as
(I) A function symbol of 0 argument is a term including a variable.
(Ii) Variable symbols are terms that include variables.
(Iii) g is a function symbol with m arguments, and s1, s2, and ‥‥ sm are variables
G (s1, s2, ‥‥ sm) includes variables
Term.
The term including the class identifier is divided into function symbols, variable symbols,
It is defined as the term on the resource identifier as follows.
(I) The function symbol of 0 argument is a term including a class identifier.
You.
(Ii) A variable symbol is a term that includes a class identifier.
(Iii) The class identifier is a term including the class identifier.
(Iv) h is a function symbol with n arguments, and t1, t2, and ‥‥ tn are classes
If the term contains an identifier, h (1t, t2, ‥‥ tn) is the class
This is a term that includes a resource identifier.
Class using the class of the substructure that composes it
Then, it is defined as follows.
<Class definition>
Class identifier == term containing class identifier
Uppercase letter of class identifier prefixed with #, variable symbol _
Uppercase letters, function symbols in lowercase strings and alphanumeric characters
Sometimes the structure represented by the following five class definitions
The structure will be described.
# A == f (#B, #C) ‥‥ (a)
# B == i ‥‥ (b)
# B == j ‥‥ (c)
# C == u ‥‥ (d)
# C == v ‥‥ (e)
The above (a) indicates whether #A is a function symbol f and classes #B and #C.
(B) and (c) show the class B
Is a function symbol i or j, and (d),
(E) states that class C is a function symbol u or v
Shown respectively.
In other words, each class is a set of terms,
# A = {f (i, u), f (i, v), f (j, u), f (j, v)}
# B = {i, j}
# C = {u, v}
Is represented.
When the input data is f (i, u), its structure is
Is analyzed as follows.
(1) f (i, u) and #A are pattern matched, and #B, #C
For i and u respectively.
(2) i and #B are pattern matched, and the above matches
Select (b).
(3) Pattern matching between u and #C, and matching
Select (d).
At this time, the class identifier #A is a starting point of the processing.
Such a class identifier is hereinafter referred to as a start symbol.
As described above, in the present invention, the output structure is
Write it in association with the class. Here, the structure to output
Is a term that includes a variable, and a term that includes a variable in the class identifier.
Indicates the association followed by Information obtained during the conversion process
By replacing the variable symbol of the term containing the variable with the term.
Is stored.
Add the output structure to the above class definition example.
Consider an example of a conversion rule such as
#A [add (_X, _Y)]
== f (#B [_X], #C [_Y]) ‥‥ (a ′)
#B [zero]
== i ‥‥ (b ′)
#B [one]
== j ‥‥ (c ′)
#C [two]
== u ‥‥ (d ')
#C [three]
== v ‥‥ (e ')
Data conversion is performed according to the following procedure.
(1) Pattern matching between input data f (i, u) and #A
And (a ') is selected, and at the same time, i,
Bind u.
(2) i and #B are pattern matched and matched
(B ') is combined with #B on the right side of (a').
(3) The term of (b ') connecting the variable _X of (a')
Replace with zero.
(4) u and #C are pattern matched and matched
(D ') is combined with #C on the right side of (a').
(5) The term of (d ') connecting the variable _Y of (a')
Replace with two.
(6) Use the obtained term add (zero, two) as output data
You.
Here, binding of class identifier and input data, variables and output
Force data bindings are recorded at the nodes of the intermediate structure.
FIGS. 1A to 1D show basic processing operations of the present invention.
It is a flowchart shown.
FIG. 1 (a) is a main flow of the conversion rule analysis,
This processing is performed by the conversion rule analysis unit 4. Conversion rule analyzer 4
Reads conversion rule 1 and the start symbol, given them.
Take (step 20) and clean the structure according to the class identifier.
Classify as lath and mark the class corresponding to the start symbol
(Step 202). Conversion rules are converted to internal representation for each class
After making changes, analyze the relationships between classes and check
(Step 203), and stored in the conversion rule storage unit 7.
Output (Step 204).
FIG. 1B is a main flow of the data conversion.
Regarding data input / output and activation of pattern match control unit 5
You. Given input data, this data conversion processing system
Reads it (step 301) and creates an intermediate structure
A node serving as a starting point is generated in the storage unit 8, and an initial environment is recorded.
And obtains a start symbol from the conversion rule storage unit 7 (step 30).
2) Call procedure 1 with the node as an argument (step
303). If Procedure 1 succeeds (Step 30
4), the output data recorded on the node generated in step 302
The data is obtained (step 305) and output (step 306).
Otherwise, output a syntax error in the input data
(Step 307).
FIG. 1 (c) shows step 303 in FIG. 1 (b).
This is a processing flow of a procedure 1, in which the processing is performed by using the pattern
This is performed by the match control unit 5. The argument of procedure 1 is an intermediate structure
Class identifier and data from the given node.
(Step 401), and from the conversion rule storage 7,
Get a conversion rule with the class identifier of
402). If such a conversion rule is obtained (Step 4
03), using the conversion rules and the data obtained in step 401 above
Procedure 2 is read as an argument (step 404).
Return to Step 402. For all such conversion rules
Processing ended, procedure 2 failed for all of them
If not (step 405), return failure (step 406),
Otherwise, success is returned (step 407).
FIG. 1 (d) shows the procedure 2 of the procedure 2 shown in the step 404.
This is a processing flow.
6 does. The arguments for procedure 2 above are the conversion rules and the input data.
Pattern mapping between argument conversion rules and data.
(Step 501) If there is no match (Step 50
2), return failure (step 509).
If they match, the intermediate structure storage unit 8 is checked (
Step 503), Class identification on the right side of the matching conversion rule
If there is no node with a child and data pair, create a node.
(Step 504). Write the current environment at the node
Recording (step 505). The rules included on the right side of the conversion rule
For all class identifiers (step 506),
Procedure 1 is called with the point as an argument (step 507),
If procedure 1 is successful (step 508), the next class
The processing of the resource identifier is performed (step 506). If on the way
If at least one fails, a failure is returned (step 509).
The processing shown in FIG. 1B is performed in advance in the form of a conversion table.
You may make it input what was made.
The present invention can be implemented in hardware or software.
Therefore, it can also be implemented. In the following description
Describes an embodiment using software.
FIG. 3 is an example of information stored in the conversion rule storage unit 7.
You. FIG. 4 shows information stored in the intermediate structure storage unit 8.
This is an example. In FIG. 4, 71 is a node of the intermediate structure.
It is the details of. Here, the flag indicates that the node
True if all subnode sequences succeeded in pattern matching,
Otherwise, false. 72 is the leaf of the intermediate structure
73 is the details of the subnode. The subnode is the left of the relationship
Binding between the class identifier or variable symbol of the edge and the input data
Express. 74 is the details of the node connection information. Node connection information
Represents the connection between the nodes of the intermediate structure using a list structure.
I forgot.
FIGS. 6 (a) to 6 (e) show processing procedures according to an embodiment of the present invention.
It is a flowchart which shows the detail of a sequence.
FIG. 6A is a flowchart of a main routine.
Yes, input / output of data and activation of pattern match control unit 5
I do. That is, the input data is read (step 90).
1) Generate special starting nodes and subnodes (step
(Step 902), the environment is initialized (Step 903). Ma
Further, a start symbol is obtained from the conversion rule storage unit 7, and the start symbol,
Input data and subnodes generated in step 902 described above
The procedure 1 is read by using the
Continue 1 to evaluate output data under the environment set as a node
(Step 905), and output (Step 906).
FIG. 6 (b) is a flowchart of the procedure 1 described above.
You. Procedure 1 converts the class identifier, input data, and subnodes
Performs a pattern match as an argument. First, conversion rules
Conversion rule with class identifier of argument on left side from storage unit 7
(Step 1001), there is no corresponding conversion rule
If (step 1002) return, if not
Stores the argument data from the intermediate structure storage unit 8 in the first element
Search for a node (step 1003), if it does not exist
If the second element of the conversion rule, data, and subnodes are arguments,
Call procedure 2 (step 1004) and go to step 1001
Return. If the above node exists,
If the pointer to the point is in the pointer set to the parent subnode
If (step 1005), go back to step 1001, otherwise
If so, a pointer to the subnode is added to the set (step 100).
6) If the node flag is true (step 1007),
To step 1001, otherwise the nodes and subnodes as arguments
And call procedure 4 (step 1008), step 1001
Return to
FIG. 6C is a flowchart of the procedure 2 above.
You. Procedure 2 consists of the term containing the class identifier, the input data,
Using the nodes as arguments, the generation of intermediate structure nodes and the
Matching term including input identifier and input data, subsection
Generate points. First, a node is generated (step 110).
1) Pattern match the second element of the conversion rule with the node
(Step 1102). If the pattern match fails
Step 1103) Return, if successful, enter the conversion rules
Check whether the pattern includes a class identifier (step 110)
4) If not, use procedure 3 with nodes as arguments
Call (step 1105), otherwise create subnodes
(Step 1106), the generated sub-nodes and their first and third sub-nodes
Procedure 1 is called with the element as an argument (step 110)
7).
FIG. 6D is a flowchart of the procedure 3.
Procedure 3 uses the nodes of the intermediate structure as arguments
Generate information and combine nodes. First, set the node flag
true (step 1201), and the parent sub-clause starts from the second element of the node
Points are obtained (step 1202). If parent subnode does not exist
Return (step 1203) and, if it exists, the node
The pointer to the parent and the fifth element of the parent subnode as a set
Generate joint information (step 1204) and connect the nodes of the parent subnodes.
In addition to the joint information (step 1205), the sixth element of the parent subnode
The next parent subnode is obtained from (step 1206). Next parent subclause
If a point exists (step 1207), the obtained subnode and its
Procedure 1 is called with the first and third elements of
Step 1208), and return to step 1202. Otherwise, parent
Procedure 3 using the parent node traced from the subnode of
Call (step 1209) and return to step 1202.
FIG. 6E is a flowchart of the procedure 4 described above.
You. Procedure 4 takes the nodes and subnodes of the intermediate structure as arguments
Then, node connection information is generated and nodes are shared. First,
Generate node connection information from arguments, nodes and subnodes (step
1301), in addition to the node connection information of the fifth element of the subnode,
(Step 1202), the next subnode is obtained from the sixth element of the subnode.
Obtain (step 1203). If the next subnode exists
(Step 1304) Subtracting the obtained subnode and its first and third elements
Procedure 1 is called as the count (step 1305).
If the node does not exist, subtract the parent node followed from the subnode.
Procedure 3 is called as the number (step 1306).
FIG. 5 shows an example of the conversion rule,
It is a figure showing the internal expression of an inter-structure. Processing of this embodiment
In order to help the understanding, a supplementary explanation is given below using FIG.
Do.
61 (1) to 61 (5) are converted by the conversion rule analysis unit 4
This is the conversion rule that has been analyzed.
Is attached, and 61 (1) is changed to 61 (2) and 61 (3) from #B.
Chains from 61 (1) to 61 (4), 61 (5)
Is chained by #C.
71 (1) is the top level when classifying structures into classes.
The main routine calls this a sub-node
Generated in step 902 together with (1), # A, f (i, u), 73
Call procedure 1 with (1) as an argument (step 90)
Four). Procedure 1 is a transformation having #A on the left side in step 1001.
Find the replacement rule 61 (1) and find f (# B, # C), f (i, u),
Call procedure 2 with 73 (1) as an argument (step 10)
04). Procedure 2 generates node 71 (2) (step 11).
01), pattern matching between f (#B, #C) and f (i, u)
(Step 1102). By this pattern match, #B
And i, #C and u match, so 73 (2) and 73 (3)
Is generated (step 1106), and the sixth element of 73 (2) is
Procedure 1 using #B and i, 73 (2) as arguments
Is called (step 1107).
Procedure 1 is a conversion rule 61 having #B as the first element.
(2), 61 (3) is searched (step 1001), i, i, 73
For each of the set (2) and the set i, j, 73 (2),
Procedure 2 is called (step 1004). i, j, 73 (2) is subtracted
Procedure 2 called as a function generates node 72 (2)
(Step 1101), i and j are pattern matched,
(Step 1102) Since there is no match, the procedure returns to Procedure 1.
On the other hand, the procedure called with i, i, 73 (2) as an argument
2 generates a node 72 (1) (step 1101), i and i
Is pattern matched (step 1102)
Call procedure 3 with 72 (1) as an argument (step 11)
05). Procedure 3 sets the flag of 72 (1) to true (step
Steps 1201) and 73 (2) are obtained from the second element of 72 (1) (step 1201).
Step 1202), 5th element of 72 (1) and 73 (2) (initial value
Is nil) and generates 74 (2) to form the fifth of 73 (2).
Element (steps 1204 and 1205), the sixth element of 73 (2)
73 (3) is obtained (step 1206), #C and u, 73 (3)
Procedure 1 is called by using as an argument (step 1208).
Here, the same as performed for #B and i, 73 (2)
Perform processing, generate 72 (4), 72 (3), and convert 74 (3)
The connection is made to 73 (3) through the connection (step 1205). 73 (3)
Is the nil (step 1207), so the 73 (3)
Procedure 3 is called using the second element 71 (2) as an argument.
(Step 1209). Procedure 3 sets the flag of 71 (2)
Set true (step 1201), and obtain 73 (1) (step 12)
02) and 74 (1) are generated as the fifth element of 73 (1).
Steps 1205) and 73 (1) are 71 because the sixth element is nil
Procedure 3 is called using (1) as an argument (step 120).
9). Procedure 3 sets the flag of 71 (2) to true and sets 73
(1) is obtained (steps 1201 and 1202), and 74 (1) is generated.
(Step 1204) As the fifth element of 73 (1) (Step 1204)
1205), 73 (1) continues nil because the sixth element is nil
Procedure 3 is called as the count. Procedure 3 is 71 (1)
Set the flag to true and get the parent subnode from the second element of 71 (1)
(Step 1202), but because it is nil (step 1203)
The procedure returns to procedure 3 on the sending side. Procedure 3 of the caller is 71
Since the processing of the parent subnode of (2) is completed, the calling side
Return to procedure 3. In this way, procedures are released one after another.
Then, control transfers to step 905 of the main routine.
Step 905 is the output of the top-level node 71 (1).
The pattern_X is converted into the subnode 73 (1) and the node connection information 74 (1).
Through the output pattern of the node 71 (2) add (_X, _Y)
And bind. Here, it is connected to the sub node through the node connection information.
Although there are generally multiple nodes that match, the
Constrain each of the force patterns and the output pattern of the parent node.
Bundle 71 (1) output pattern and 71 (2) output pattern
Variable symbol of the output pattern of 71 (2)
_X is the output path of node 72 (1) via subnode 73 (2).
At turn zero, the variable symbol _Y goes through subnode 73 (3)
Bound to the output pattern two at node 72 (3).
As a result of these bindings, all variable symbols are replaced.
The term add (zero, two) is created. The processing system must use this term
Output (step 906), and the conversion process ends.
In the present embodiment, the node connection information is aggregated.
A plurality of intermediate structures are superimposed and represented
The memory size occupied by the structure has been reduced.
The internal expressions shown in FIGS. 4 and 3 are logically equivalent.
Instead of another expression, such as a list expression, a table
It can also be implemented using expressions such as Also, in FIG.
The pointer to the input data identifies the input data and
Replacement with other information that has enough information for the match
Can be. The same applies to other information. In addition, multiple
If there is no need to represent the intermediate structure of
No node connection information is required.
The processes shown in FIGS. 1A to 1E are sequentially performed.
Or in parallel.
The present invention can be used to represent abstract data types.
You. Two data types SEQITEM, VECT defined as follows
This is shown by taking OR as an example.
sort: SEQITEM
operations: nlsq → SEQITEM
apdl ITEM, SEQITEM → SEQITEM
car SEQITEM → ITEM
cdr SEQITEM → SEQITEM
isnil SEQITEM → BOOLEAN
laws: car (apdl (_i, _s)) = _i
cdr (apdl (_i, _s)) = _s
isnil (nlaq) = true
isnil (apdl (_i, _s)) = false
sort: VECTOR
operations: emptyv → VECTOR
assign VECTOR, INDEX, ITEM
→ VECTOR
read VECTOR, INDEX → ITEM
laws: read (emptyv, _ix) = undefined
: read (assign (_v, _ix1, _i), _ ix2)
= If _ix1 = _ix2
then _i
else read (_v, _ix2)
The implementation of the data type SEQITEM by VECTOR is shown in the following table.
Be forgotten.
dSEQITEM(Nlsq) = emptyv
dITEM SEQITEM SEQITEM(Apdl (_i, _s))
= <Assign (vector (_s), size (_s) + 1, _i), size
(_S) +1>
dSEQITEM ITEM(Car (_s))
= Read (vector (_s), size (_s))
dSEQITEM SEQITEM(Cdr (_s))
= <Vector (_s), size (_s) -1>
In the present embodiment, this is given as the following conversion rule.
You.
#SEQITEM [_s]
== # SZDVCT [_s]
#SZDVCT [<_ v, _ix>]
== <# VECTOR [_v], #INDEX [_iv]>
#SZDVCT [<emptyv, zero>]
== nlsq
#SZDVCT [<assign (_v, _ix + 1, _i), _ ix + 1>]
== apdl (#ITEM [_i], #SEQITEM [<_ v, _ix
>])
#ITEM [read (_v, _ix)]
== car (#SEQITEM [<_ v, _ix>]
#SZDVCT [<_ v, _ix-1>]
== cdr (#SEQITEM [<_v, _ix>]
Expression as input data
car (cdr (cdr (apdl (C, apdl (B, apdl (A, ni
l))))))
And this conversion rule gives the expression
read (
<Assign (
<Assign (
<Assign (
<Emptyv, 1>
1, A), 1>,
2, B), 2>,
3, C), 3>
, 1)
Is converted to
The present invention can be used to implement algebraically described specifications.
Can be. Abstract data types are algebraic specifications of data types
So, taking SEQITEM as an example,
You. laws is expressed as follows in the conversion rules of this embodiment.
It is.
#SEQITEM [nlsq]
== nlsq
#SEQITEM [apdl (_i, _s)]
== apdl (#ITEM [_i], #SEQITEM [_s])
#ITEM [_i]
== car (apdl (#ITEM [_i], #SEQITEM [_
s]))
#EXP [_s]
= Cdr (apdl (#ITEM [_i], #SEQITEM [_s]))
#BOOLEAN [true]
== isnil (nlsq)
#BOOLEAN [false]
== isnil (apdl (_i, _s))
#EXP [apdl (_e)]
== apdl (#EXP [_e]
#ITEM [car (_e)]
= Car (#EXP [_e])
#EXP [cdr (_e)]
== cdr (#EXP [_e])
By repeatedly applying this conversion rule, the expression
car (cdr (cdr (apdl (C, apdl (B, apdl (A, ni
l))))))
Is
car (cdr (apdl (B, apdl (A, nil))))
car (apdl (A, nil))
A
Is converted to In this embodiment, the steps of the main routine are executed.
By repeating steps 902-095,
Can be realized.
The conversion rule of this embodiment is also implemented by another notation.
be able to. An example is shown below.
<Conversion rules> →
List of <Class definition> <Operation rules>
<Class definition> →
Class identifier →
Term containing class identifier
<Operation rules> →
== terms including variables {list of <binding expressions>}
<Binding type> →
Term including variable == class identifier
The following is an example of the conversion rule described in this notation.
You.
# SEQITEM → # SZDVCT
== _ x
{_X == # SZDVCT}
# SZDVCT → <# VECTOR, # INDEX>
== <_ v, _ix>
{_V == # VECTOR, _ix == # INDEX}
# SZDVCT → nlsq
== <empty, zero>
# SZDVCT → apdl (# ITEM, # SEQITEM)
== <assign (_v, _ix + 1, _i), _ ix + 1>
{_I == # ITEM, <_ v, _ix> == # SEQITEM}
# ITEM → car (#SEQITEM)
== read (_v, _ix)
{<_V, _ix> == # SEQITEM}
# SZDVCT → cdr (#SEQITEM)
== <_ v, _ix-1>
{<_V, _ix> == # SEQITEM}
The above rules are also applied to the conversion rules described in this way.
Only conform to the notation of the conversion rule
Conversion can be performed without changing other processes
You.
〔The invention's effect〕
As described above, according to the present invention, the conversion rule
Data conversion method for converting structure data to structure data
Classifies the substructures of a structure into classes
Is described by the relationship between the above classes
In both cases, the structure to be output is described in association with the class.
Storage means for the conversion rules to be
Data, and analyze the structure data to be converted.
Classifying into a conversion rule class;
Reconstruct the structure data by associating it with the conversion rule class
DCG
Without losing the structural information of the structure as in
Can be given freely, and based on given conversion rules,
Structure data conversion that can perform data conversion efficiently
It has a remarkable effect that the method can be realized.
You.
【図面の簡単な説明】
第1図(a)〜(d)は本発明の基本的処理動作を示す
フローチャート、第2図は本発明に係わる構造体データ
変換処理システムの機能ブロック図、第3図,第4図は
実施例の情報の内部表現方式を示す図、第5図は情報の
内部表現の具体例を示す図、第6図(a)〜(e)は実
施例の処理手順の詳細を示すフローチャートである。
1:変換規則、2:入力データ、3:出力データ、4:変換規則
解析部、5:パターンマッチ制御部、6:パターンマッチ
部、7:変換規則記憶部、8:中間構造体記憶部。BRIEF DESCRIPTION OF THE DRAWINGS FIGS. 1 (a) to 1 (d) are flowcharts showing basic processing operations of the present invention, FIG. 2 is a functional block diagram of a structure data conversion processing system according to the present invention, and FIG. FIG. 4 and FIG. 4 are diagrams showing the internal representation method of the information of the embodiment, FIG. 5 is a diagram showing a specific example of the internal representation of the information, and FIGS. 6 (a) to 6 (e) show the processing procedure of the embodiment. It is a flowchart which shows details. 1: Conversion rule, 2: Input data, 3: Output data, 4: Conversion rule analysis unit, 5: Pattern match control unit, 6: Pattern match unit, 7: Conversion rule storage unit, 8: Intermediate structure storage unit.
Claims (1)
データの間の変換を変換規則に基づいて行うデータ変換
方法において、 構造体の部分構造をクラスに分類し、入力となる構造体
を前記クラス間の関係によって記述するとともに、出力
する構造体を前記クラスに関連付けて記述する変換規則
の記憶手段を設けて、 変換すべき構造体データを入力し、該変換すべき構造体
データを前記変換規則と照合し、クラスに解析するステ
ップと、 出力する構造体データを前記変換規則のクラスに基づい
て再構成するステップとを有することを特徴とするデー
タ変換方法。 2.前記変換すべき構造体データを解析するステップ
は、入力された構造体データと前記変換規則とのパター
ンマッチングを行い、入力された構造体データの部分構
造を前記クラスと照合するステップと、 前記変換規則に記述されるクラス間の関係に基づきクラ
スを節点とする中間構造体を形成し、前記パターンマッ
チの結果を前記中間構造体の節点上に記録するステップ
とを含み、 前記出力する構造体データを再構成するステップは、前
記中間構造体上に記録された前記パターンマッチの結果
を、対応するクラスに関連付けられた構造体の前記記述
に適用するステップと、 前記中間構造体上に記録された前記適用結果を総合し構
造体データを形成するステップとを含むことを特徴とす
る特許請求の範囲第1項記載のデータ変換方法。(57) [Claims] In a data conversion method for performing conversion between structure data formed by explicit connection of partial structures based on a conversion rule, a partial structure of a structure is classified into a class, and an input structure is inter-class Storage means for storing a conversion rule that describes a structure to be output in association with the class, inputs structure data to be converted, and stores the structure data to be converted with the conversion rule A data conversion method, comprising: collating and analyzing into a class; and reconstructing output structure data based on the conversion rule class. 2. Analyzing the structure data to be converted, performing pattern matching between the input structure data and the conversion rule, and comparing a partial structure of the input structure data with the class; Forming an intermediate structure having a class as a node based on the relationship between the classes described in the rules, and recording a result of the pattern matching on a node of the intermediate structure, the structure data to be output Reconstructing the pattern matching results recorded on the intermediate structure, the step of applying to the description of the structure associated with the corresponding class, the recorded on the intermediate structure 2. The data conversion method according to claim 1, further comprising the step of: combining the application results to form structure data.
Priority Applications (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP62282371A JP2722465B2 (en) | 1987-11-09 | 1987-11-09 | Data conversion method |
| US07/195,142 US5321606A (en) | 1987-05-19 | 1988-05-18 | Data transforming method using externally provided transformation rules |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP62282371A JP2722465B2 (en) | 1987-11-09 | 1987-11-09 | Data conversion method |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| JPH01123326A JPH01123326A (en) | 1989-05-16 |
| JP2722465B2 true JP2722465B2 (en) | 1998-03-04 |
Family
ID=17651533
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP62282371A Expired - Fee Related JP2722465B2 (en) | 1987-05-19 | 1987-11-09 | Data conversion method |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP2722465B2 (en) |
-
1987
- 1987-11-09 JP JP62282371A patent/JP2722465B2/en not_active Expired - Fee Related
Non-Patent Citations (1)
| Title |
|---|
| 情報処理学会第32回(昭和61年前期)全国大会講演論文集 P.551−552 |
Also Published As
| Publication number | Publication date |
|---|---|
| JPH01123326A (en) | 1989-05-16 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US5321606A (en) | Data transforming method using externally provided transformation rules | |
| JPS6375835A (en) | Apparatus for generating intended code, program, list and design document | |
| Lang | Towards a uniform formal framework for parsing | |
| Rajbhoj et al. | Doctomodel: Automated authoring of models from diverse requirements specification documents | |
| CN112099764B (en) | A normalization method for avionics field requirements based on formal conversion rules | |
| Bais et al. | A model of a generic natural language interface for querying database | |
| Gopinath et al. | Input algebras | |
| Arps et al. | A parser for LTAG and frame semantics | |
| CN114528846A (en) | Concept network for artificial intelligence and generation method thereof | |
| Koskimies et al. | The design of a language processor generator | |
| JP2722465B2 (en) | Data conversion method | |
| Gries | Use of transition matrices in compiling | |
| Paakki | Prolog in practical compiler writing | |
| Lang | The systematic construction of Early Parsers: Application to the production of an O (n^ 6) Early Parser for Tree Adjoining Grammars. | |
| Goni et al. | ARIES: A lexical platform for engineering Spanish processing tools | |
| Golemanov et al. | A set of tools to teach language processors construction | |
| JPH02183338A (en) | Apparatus and method for generating program language translator | |
| Klyucherev et al. | A Simple Run-time Parser Generator | |
| Rao et al. | Compiler Design | |
| Barnes | Exploratory steps towards a grammatical manipulation package (GRAMPA) | |
| JP3044463B2 (en) | Data conversion method | |
| Lang | A uniform formal framework for parsing | |
| Walsh | Adapting Compiler Front Ends for Generalised Parsing | |
| Schwaiger | Parsing of configuration files | |
| Kwiatkowski | Reconciling Unger’s parser as a top-down parser for CF grammars for experimental purposes |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| LAPS | Cancellation because of no payment of annual fees |