JPH0540631A - Type inferring device - Google Patents

Type inferring device

Info

Publication number
JPH0540631A
JPH0540631A JP3219262A JP21926291A JPH0540631A JP H0540631 A JPH0540631 A JP H0540631A JP 3219262 A JP3219262 A JP 3219262A JP 21926291 A JP21926291 A JP 21926291A JP H0540631 A JPH0540631 A JP H0540631A
Authority
JP
Japan
Prior art keywords
data type
type
inference
data
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP3219262A
Other languages
Japanese (ja)
Inventor
Yoshihiro Masuda
佳弘 増田
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujifilm Business Innovation Corp
Original Assignee
Fuji Xerox Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fuji Xerox Co Ltd filed Critical Fuji Xerox Co Ltd
Priority to JP3219262A priority Critical patent/JPH0540631A/en
Publication of JPH0540631A publication Critical patent/JPH0540631A/en
Pending legal-status Critical Current

Links

Abstract

PURPOSE:To easily infer the data types of a variable and a function by performing an inference based on a table where the substitute rules are registered in order to convert a host data type into a follower data type according to the contents of the table. CONSTITUTION:A storage means 16 stores a table where a substitute rule is registered to substitute a host data type of a hierarchical structure data type for a hollower data type that can be specified. A type inferring device 15 carries out a type inference to convert the host data type into the follower data type based on the contents of the table. Thus the substitute rule substitutes the host data type for the follower data type and also substitutes an abstruct data type of a hierarchical data structure for a more concrete follower data type as long as the data treated by a program produced by a user are limited. These substitute rules are previously inputted and defined by the users.

Description

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

【0001】[0001]

【産業上の利用分野】本発明は、型推論装置に関し、特
に、LispやSmalltalkなどのデータ型の宣言が不要な
プログラミング言語で記述されたプログラムのコンパイ
ルの際、および他のプログラミング言語への変換の際
に、変数や関数のデータ型を推論する型推論(Type Inf
erence)を行う型推論装置に関するものである。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a type inference device, and more particularly, to compiling a program written in a programming language such as Lisp or Smalltalk that does not require a data type declaration, and converting it into another programming language. Type inference (Type Inf)
erence) type inference device.

【0002】[0002]

【従来の技術】C言語や、FORTRAN言語などのプ
ログラム言語では、プログラム上の変数に対するデータ
型は、データ型宣言文によって厳密に宣言され、プログ
ラムの全体として、整合性がとれていければならない。
このため、プログラムの実行時には、変数の表わすデー
タ型は静的に既に決定されている。例えば、図9に示す
ように、変数「a」に対しては変数aが整数型データで
あることを予じめデータ型宣言文91により宣言してか
ら当該変数aを用いる。同様に、変数「b」に対して
も、変数bが文字型データであることをデータ型宣言文
92で予じめ宣言してから当該変数bを用いる。このよ
うなデータ型宣言文によって、各々の変数に対して、メ
モリ領域に各々の変数のデータ型により予め定められて
いる領域が割り当てられる。
2. Description of the Related Art In programming languages such as C language and FORTRAN language, data types for variables on a program must be strictly declared by a data type declaration statement, and the whole program must be consistent.
Therefore, when the program is executed, the data type represented by the variable is already statically determined. For example, as shown in FIG. 9, for the variable “a”, the variable a is used after it is declared by the data type declaration statement 91 in advance that the variable a is integer type data. Similarly, with respect to the variable “b”, the variable b is used after the data type declaration statement 92 is used to declare that the variable b is character type data. By such a data type declaration statement, an area predetermined by the data type of each variable is allocated to the memory area for each variable.

【0003】一方、Common LispやSmalltalkなどの
プログラミング言語では、変数はデータへのポインタと
して扱われる。このため、各々の変数に対するデータ型
の宣言は不要である。したがって、このようなプログラ
ミング言語を用いたプログラムでは、プログラムの実行
時において変数の表わすデータ型は動的に変化させて用
いることが可能である。
On the other hand, in programming languages such as Common Lisp and Smalltalk, variables are treated as pointers to data. Therefore, it is not necessary to declare the data type for each variable. Therefore, in a program using such a programming language, the data type represented by a variable can be dynamically changed and used when the program is executed.

【0004】図10は、Common LispやSmalltalkな
どのプログラミング言語における変数のデータ構造を説
明する図である。Common LispやSmalltalkなどのプ
ログラミング言語においては、変数をデータへのポイン
タとして扱うため、例えば、図10に示すように、整数
型データの変数aについて、プログラムの実行時に変数
aのポインタ93により指示された先のデータ型によっ
て、当該変数aのデータ型は動的に変化する。このた
め、各々の変数に対するデータ型の宣言文などはプログ
ラム作成上においては、特に必要とされない。変数を示
しているポインタ93が、整数型データ94を指示した
場合には、変数aは整数型データとなり、また、変数a
のポインタ93が文字型データ95を指示した場合に
は、変数aは文字型データとなる。このように、関接参
照による変数aのデータ型は、参照された参照先のデー
タ型となり、プログラムの実行時に動的に変化する。
FIG. 10 is a diagram for explaining the data structure of variables in programming languages such as Common Lisp and Smalltalk. In programming languages such as Common Lisp and Smalltalk, variables are treated as pointers to data. Therefore, for example, as shown in FIG. 10, an integer type data variable a is designated by the pointer 93 of the variable a when the program is executed. The data type of the variable a dynamically changes depending on the data type of the end. Therefore, a data type declaration statement for each variable is not particularly required in creating a program. When the pointer 93 indicating the variable points to the integer type data 94, the variable a becomes integer type data, and the variable a
When the pointer 93 indicates the character type data 95, the variable a becomes the character type data. In this way, the data type of the variable a by the articulation reference becomes the data type of the referenced reference destination, and dynamically changes when the program is executed.

【0005】また、Common Lisp,Smalltalkなどに
おける間接参照によるデータの扱い方は、プログラムの
実行に柔軟性をもたらすが、データの値をアクセスする
際のコストが、直接参照に比ベて大きくなる。このた
め、Common Lispでは、コンパイラが静的に変数のデ
ータ型を決定してコンパイルできるように、任意の変数
や関数に対してデータ型宣言を行なうため機能や、デー
タ型の推論を行う機能の付加などを行うことが試みられ
ている。例えば、この種のデータ型宣言に関する公知文
献として、次のような文献が挙げられる。 文献1:R.ミルナー著“ア セオリー オブ ポリモ
ルフィズム イン プログラミング”,ジャーナル オ
ブ コンピュータ アンド システム サイエンス,ボ
リューム17,348頁〜375頁,1978年[ R.
Milner,“A Theory of Type Polymorphism in Program
ming", Journal of Computerand System Sciences, vo
l. 17, 348-375 (1978) ] 文献2:R.スズキ著“インフェリング タイプ イン
スモールトーク”,プロシーディング オブ 8th
ACM シンポジウム オン プログラミング ラン
グゥエッジ,187頁〜199頁,1981年[ N. Su
suki,“Inferring type in Smalltalk”, Proceeding
of 8th ACM Symposium onPrinciples of Programming L
anguages,187-199 (1981) ] 文献3:A.H.バーンニング著“ア タイプ デクラ
レーション アンド インタフェース システム フォ
ー スモールトーク”,プロシーディングオブ 9th
ACM シンポジウム オン プログラミング ラン
グゥエッジ,133頁〜142頁,1982年[A. H. B
ourning著“A Type Decla-ration and Interface Syste
m for Smalltalk”, Proceeding of9th ACMSymposium
on Principles of Programming Languages, 133-142 (1
982)
Further, although the handling of data by indirect reference in Common Lisp, Smalltalk, etc. gives flexibility to the execution of a program, the cost of accessing the value of data becomes larger than that of direct reference. For this reason, in Common Lisp, the function for declaring the data type for any variable or function and the function for inferring the data type are provided so that the compiler can statically determine the data type of the variable and compile. Attempts have been made to make additions. For example, the following documents can be cited as known documents regarding this type of data type declaration. Reference 1: R. Milner, "Aceory of Polymorphism in Programming", Journal of Computer and System Science, Volume 17, 348-375, 1978 [R.
Milner, “A Theory of Type Polymorphism in Program
ming ", Journal of Computerand System Sciences, vo
l. 17, 348-375 (1978)] Reference 2: R.I. Suzuki "Infering Type in Small Talk", Proceeding of 8th
ACM Symposium on Programming Language, 187-199, 1981 [N. Su
suki, “Inferring type in Smalltalk”, Proceeding
of 8th ACM Symposium on Principles of Programming L
anguages, 187-199 (1981)] Reference 3: A. H. Burning, "A Type Declaration and Interface System for Small Talk," Proceeding of 9th
ACM Symposium on Programming Language, pp. 133-142, 1982 [AH B
ourning “A Type Decla-ration and Interface Syste
m for Smalltalk ”, Proceeding of9th ACM Symposium
on Principles of Programming Languages, 133-142 (1
982)

【0006】[0006]

【発明が解決しようとする課題】上述のように、関接参
照による変数は、データの扱い方はプログラムの実行に
柔難性を持たらすが、変数の値(データ)をアクセスす
る際のアクセスコストが直接参照に比ベて大きくなる。
このため、Common Lispなど一部のプログラミング言
語では、コンパイラが静的に変数のデータ型を決定して
コンパイルできるように、任意の変数や関数に対してデ
ータ型宣言を行なうための機能が提供されていることは
上述のとおりである。しかしながら、各々の変数に対し
てデータ型宣言を行なうことは、プログラミングするユ
ーザにとって大きな労力となり、プログラムの生産性の
効率も悪くなる。このため、特に、データ型宣言の必要
のない一部のプログラミング言語に対しても、例えば、
前述の文献1,文献2,文献3などに述ベられているよ
うに、変数に対する定数の代入操作,適用関数などのプ
ログラムにおける構造から、データ型を推論する「型推
論」と呼ばれるコード最適化技法が開発されて利用され
ている。
As described above, the variable by reference to the connection gives the flexibility in the execution of the program in the way of handling the data, but the access when accessing the value (data) of the variable The cost is higher than the direct reference.
Therefore, some programming languages such as Common Lisp provide a function for declaring the data type of any variable or function so that the compiler can statically determine the data type of the variable and compile it. This is as described above. However, declaring the data type for each variable is a great effort for the programming user, and the productivity of the program is also inefficient. Therefore, especially for some programming languages that do not require data type declarations, for example,
As described in the above-mentioned Literature 1, Literature 2, Literature 3, etc., code optimization called "type inference" that infers a data type from the structure in a program such as a constant assignment operation to a variable and an application function. Techniques have been developed and used.

【0007】ところで、Common Lispなどのプログラ
ミング言語では、データ型に階層関係が存在する。例え
ば、数値(Number)については、図11に示すように、そ
のデータ型として、最上位の数(number)に対して、その
次の下位のデータ型として、実数(real)と複素数(compl
ex)とが存在し、また、実数(real)に対しては、その次
の下位のデータ型として、桁固定小数(rational)と浮動
小数(float)とが存在する。このようにデータ型に階層
関係が存在する。なお、図11において、下線を付けた
各々のデータ型は、下位のデータ型(サブタイプ)を伴
った抽象的なデータ型であることを示しており、これら
のデータ型はその下位のデータ型のいずれかであること
を表わしている。
By the way, in programming languages such as Common Lisp, there is a hierarchical relationship between data types. For example, as for the numerical value (Number), as shown in FIG. 11, as the data type, the real number and the complex number (compl) are set as the next lower data type for the highest number (number).
ex), and for real numbers, there are fixed-point decimals (rational) and floating-point numbers (float) as the next lower data types. In this way, there is a hierarchical relationship between data types. Note that in FIG. 11, each underlined data type is an abstract data type accompanied by a lower data type (subtype), and these data types are lower data types. It means that it is either.

【0008】このようにデータ型に階層関係が存在する
言語において型推論を行う際に、推論結果を導くのに十
分な情報が推論対象のプログラムから得られない場合、
変数や関数によっては、型推論の結果が抽象的なデータ
型に帰結されてしまうことがある。一般に、このような
抽象的なデータ型はコンパイル処理の際に行なわれる最
適化にとって、あまり有用な情報とはならない。
When type inference is performed in a language in which data types have a hierarchical relationship in this way, if sufficient information for inducing an inference result cannot be obtained from the inference target program,
Depending on variables and functions, the result of type inference may result in an abstract data type. In general, such abstract data types do not provide much useful information for the optimization done during the compilation process.

【0009】一方、ユーザによる十分なデータ型宣言が
行なわれていれば、そのデータ型宣言により比較的に適
切に型推論が行なわれる。しかし、プログラムの性質に
よっては、整数演算しか必要でないとわかっているよう
な場合もあるので、このような場合に対してまで、デー
タ型宣言をいちいち行うことは面倒であり、プログラム
作成における生産性を向上させることはできない。
On the other hand, if sufficient data type declaration is made by the user, type inference is relatively appropriately performed by the data type declaration. However, depending on the nature of the program, there are cases where it is known that only integer arithmetic is required, so even in such cases, it is troublesome to make data type declarations one by one, and productivity in program creation is increased. Can not be improved.

【0010】本発明は、上記のような問題点を解決する
ためになされたものであり、本発明の目的は、プログラ
ミング言語で記述されたプログラムのコンパイルの際、
および他のプログラミング言語への変換の際に、変数や
関数のデータ型の推論を容易に行うことができる型推論
装置を提供することにある。
The present invention has been made to solve the above problems, and an object of the present invention is to compile a program written in a programming language,
Another object of the present invention is to provide a type inference device that can easily infer the data types of variables and functions when converting to another programming language.

【0011】[0011]

【課題を解決するための手段】上記の目的を達成するた
め、本発明の型推論装置は、ソースプログラムにおける
データ型の未宣言の変数や関数について、登録されたデ
ータ型と当該ソースプログラムの構造に基づきデータ型
の推論を行う型推論装置であって、階層構造データ型の
上位のデータ型を特定可能な下位のデータ型に置換する
置換規則を登録したテーブルを記憶する記憶手段(図1
の16)と、前記テーブルを参照して、テーブル内容か
ら上位のデータ型を下位のデータ型に変換する型推論を
行う型推論手段(図1の15)とを備えることを特徴と
する。
In order to achieve the above object, the type inference apparatus of the present invention provides a registered data type and a structure of the source program for undeclared variables and functions of the data type in the source program. 1 is a type inference apparatus that infers a data type based on a storage means for storing a table in which a replacement rule for replacing an upper data type of a hierarchical structure data type with a identifiable lower data type is registered (FIG. 1).
16) and a type inference means (15 in FIG. 1) for referring to the table and performing type inference for converting an upper data type into a lower data type from the table contents.

【0012】[0012]

【作用】本発明の型推論装置においては、記憶手段(1
6)に、データ型を置換するための置換規則を登録した
テーブルを記憶しておく。そして、型推論手段(15)
が、この置換規則を登録したテーブルを参照して、テー
ブル内容から上位のデータ型を下位のデータ型に変換す
る型推論を行う。この置換規則は、階層構造データ型の
上位のデータ型を特定可能な下位のデータ型に置換する
置換規則であり、ユーザが作成するプログラムで扱うデ
ータ型が限られている場合、階層関係にあるデータ構造
におけるデータ型の抽象的なデータ型を、より具体的な
下位のデータ型に置き換えるための変換規則となってい
る。これらの変換規則はユーザが予じめ入力して定義す
る。
In the type inference apparatus of the present invention, the storage means (1
In 6), a table in which a replacement rule for replacing the data type is registered is stored. And type inference means (15)
However, with reference to the table in which this replacement rule is registered, type inference is performed to convert the upper data type to the lower data type from the table contents. This replacement rule is a replacement rule that replaces a higher-order data type of a hierarchical structure data type with an identifiable lower-order data type, and has a hierarchical relationship when the data types handled by the program created by the user are limited. It is a conversion rule for replacing the abstract data type of the data type in the data structure with a more specific lower data type. These conversion rules are preliminarily input and defined by the user.

【0013】型推論手段が、ソースプログラムにおける
データ型の未宣言の変数や関数について、データ型の推
論を行う場合には、一般には、データ型宣言文などの宣
言により、既に登録されたデータ型と当該ソースプログ
ラムの構造に基づきデータ型の推論を行うが、この場
合、変換規則を適用することによって、型推論ではでき
るだけ具体的なデータ型に推論結果を導く。これによ
り、宣言文として登録されたデータ型と同様に、型推論
を行うデータ型がより下位の具体的なデータ型に導くこ
とが可能となるので、コンパイル処理におけるコード最
適化を容易にさせることができる。
When the type inference means infers the data type of a variable or function whose data type has not been declared in the source program, generally, the data type already registered by the declaration such as the data type declaration statement is used. Data type inference is performed based on the structure of the source program. In this case, by applying the conversion rule, the type inference leads the inference result to the concrete data type as much as possible. As a result, like the data type registered as a declaration statement, the data type for which type inference is performed can be led to a lower specific data type, which facilitates code optimization in the compilation process. You can

【0014】[0014]

【実施例】以下、本発明の一実施例を図面により具体的
に説明する。図1は本発明の一実施例にかかるデータ型
推論装置の要部の構成を示すブロック図である。図1に
おいて、11はソースプログラム、12はデータ型推論
装置、13はデータ型情報検出登録機構、14はデータ
型格納テーブル、15は型推論機構、16はデータ型置
換規則格納テーブル、17はデータ型置換規則入力格納
機構である。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS An embodiment of the present invention will be specifically described below with reference to the drawings. FIG. 1 is a block diagram showing a configuration of a main part of a data type inference apparatus according to an embodiment of the present invention. In FIG. 1, 11 is a source program, 12 is a data type inference device, 13 is a data type information detection / registration mechanism, 14 is a data type storage table, 15 is a type inference mechanism, 16 is a data type replacement rule storage table, and 17 is data. It is a type substitution rule input storage mechanism.

【0015】データ型推論装置12は、データ型情報検
出登録機構13,データ型格納テーブル14,型推論機
構15,データ型置換規則格納テーブル16,および、
データ型置換規則入力格納機構17を備えている。プロ
グラム中で使用されるデータのデータ型が限られている
場合、まず、ユーザは、抽象的なデータ型をより具体的
なデータ型に置換する規則を、データ型置換規則入力格
納機構17を用いて入力し、データ型置換規則格納テー
ブル16に登録する。なお、ここで入力されたデータ型
置換規則の情報は、後述する型推論の処理の際に用いら
れる。
The data type inference device 12 includes a data type information detection / registration mechanism 13, a data type storage table 14, a type inference mechanism 15, a data type replacement rule storage table 16, and
A data type replacement rule input storage mechanism 17 is provided. When the data type of the data used in the program is limited, the user first uses the data type replacement rule input storage mechanism 17 to set the rule for replacing the abstract data type with a more specific data type. Is input and registered in the data type replacement rule storage table 16. The data type substitution rule information input here is used in the process of type inference described later.

【0016】また、データ型推論装置12は、ソースプ
ログラム11が入力されると、データ型情報検出登録機
構13により、ソースプログラム11のソースコード中
のデータ型に関する情報(データ型宣言文など)を取り
出して、データ型格納テーブル14に格納する。そし
て、次に型推論機構15により、データ型格納テーブル
14に格納された情報をもとにして、型推論の処理が行
なわれる。この型推論処理自体は、本発明とは直接に関
係しないので詳しい説明は省略するが、例えば、前述し
た文献1,文献2,文献3などに示されているような方
法により行う。
Further, when the source program 11 is input, the data type inference apparatus 12 causes the data type information detection / registration mechanism 13 to obtain information (data type declaration statement, etc.) regarding the data type in the source code of the source program 11. It is taken out and stored in the data type storage table 14. Then, the type inference mechanism 15 performs type inference processing based on the information stored in the data type storage table 14. This type inference process itself is not directly related to the present invention, and therefore a detailed description thereof will be omitted. For example, the type inference process is performed by the method shown in the above-mentioned Documents 1, 2, and 3.

【0017】このようなデータ型を推論する型推論の処
理を行う際、型推論機構15は、データ型置換規則格納
テーブル16を参照しながら型推論を行う。型推論の処
理において、データ型置換規則格納テーブル16に登録
されたデータ型と一致するデータ型を発見すると、その
データ型の登録された置換規則に従って、データ型を抽
象的なデータ型からより具体的なデータ型に置換するデ
ータ型の変換処理を行なった上で型推論を進めていく。
When performing the type inference process for inferring such a data type, the type inference mechanism 15 performs type inference with reference to the data type replacement rule storage table 16. In the process of type inference, when a data type matching the data type registered in the data type replacement rule storage table 16 is found, the data type is more concretely selected from the abstract data type according to the registered replacement rule of the data type. Type inference is performed after performing the conversion process of the data type that replaces the specific data type.

【0018】次に、Common Lispの場合を例として、
データ型の型推論の処理の具体例を説明する。まず、C
ommon Lispにおけるデータ型宣言について説明する。
変数のデータ型に関する宣言は、Common Lispでは、
例えば、次の,に例示するように、proclaimフォー
ム、declareフォームによって行なわれる。 (proclaim '(integer “counter")) ……… (defun careful (x y) (declare (integer x )(float y) (setq z (+ x y ) ……… このような,のプログラム文におけるデータ型の宣
言によって、この例では変数名“counter"およびxのデ
ータ型はinteger型として宣言され、また、変数名yの
データ型はfloat型として宣言されたことになる。
Next, taking the case of Common Lisp as an example,
A specific example of the process of data type inference will be described. First, C
The data type declaration in ommon Lisp will be described.
The declaration for the data type of a variable is in Common Lisp:
For example, as illustrated in the following, it is performed by the proclaim form and declare form. (proclaim '(integer “counter")) ……… (defun careful (xy) (declare (integer x) (float y) (setq z (+ xy) ………) By the declaration, in this example, the data types of the variable names "counter" and x are declared as the integer type, and the data type of the variable name y is declared as the float type.

【0019】[1:データ型置換規則の入力]この実施
例のデータ型推論装置12においては、まず、データ型
置換規則格納テーブル16に、データ型推論にかかるデ
ータ型置換規則が登録されていなければなない。Commo
n Lispインタプリタにおいては、次のようにしてデー
タ型の置換規則を入力する。 >(define-type-reduction 'number 'fixnum) これにより、型推論を行う際の「データ型のnumberはデ
ータ型がfixnumに置換される」ことがデータ型置換規則
として入力されたことになる。このようなデータ型置換
規則を入力を行う処理は、データ型置換規則入力格納機
構17により行なわれる。
[1: Input of Data Type Replacement Rule] In the data type inference apparatus 12 of this embodiment, first, the data type replacement rule relating to data type inference must be registered in the data type replacement rule storage table 16. I don't know. Commo
In the n Lisp interpreter, the data type replacement rule is input as follows. > (Define-type-reduction 'number' fixnum) As a result, when performing type inference, "data type number is replaced by fixnum" is input as the data type replacement rule. The process of inputting such a data type replacement rule is performed by the data type replacement rule input storage mechanism 17.

【0020】図2は、データ型置換規則入力格納機構が
行うデータ型置換規則入力処理の処理フローの一例を示
すフローチャートである。図2を参照して、データ型置
換規則入力処理を説明する。この処理では、まず、ステ
ップ21において、データ型置換規則が入力されると、
次に、ステップ22において、置換データ型は抽象デー
タ型のサブタイプであるか否かをチェックする。置換デ
ータ型が抽象データ型のサブタイプでなければ、置換規
則として登録できないのでエラーとてして、エラー処理
に進む。また、置換データ型が抽象データ型のサブタイ
プであれば登録可能なので、次のステップ23に進む。
なお、ここでの「抽象データ型」とは、データ型階層構
造においてサブタイプを持つデータ型(図11のデータ
型階層構造においては下線を付加して示しているデータ
型)のことであり、また、「置換データ型」とは置換結
果となるデータ型(サブサイプ)のことである。
FIG. 2 is a flowchart showing an example of the processing flow of the data type replacement rule input processing performed by the data type replacement rule input storage mechanism. The data type replacement rule input process will be described with reference to FIG. In this process, first, when the data type replacement rule is input in step 21,
Next, in step 22, it is checked whether the replacement data type is a subtype of the abstract data type. If the replacement data type is not a subtype of the abstract data type, it cannot be registered as a replacement rule, so an error occurs and processing proceeds to error processing. Also, if the replacement data type is a subtype of the abstract data type, it can be registered, so the process proceeds to the next step 23.
The “abstract data type” here is a data type having a subtype in the data type hierarchical structure (a data type shown with an underline in the data type hierarchical structure of FIG. 11), The "replacement data type" is a data type (subsipe) that is a replacement result.

【0021】次のステップ23においては更に、既に置
換規則が定義されているか否かを判定する。この判定で
既に置換規則が定義されている場合には、ステップ24
に進み、ステップ24においてデータ型置換規則格納テ
ーブル16に登録されている規則を削除してから、ステ
ップ25に進み、入力された置換規則をデータ型置換規
則テーブルに登録する。この場合は、データ型置換規則
格納テーブル16に既に登録されているデータ型置換規
則の更新処理となる。また、ステップ23の判定処理
で、既に置換規則が定義されていない場合には、直ちに
ステップ25に進み、入力された置換規則をデータ型置
換規則テーブルに登録する。この場合においては、デー
タ型置換規則格納テーブル16へのデータ型置換規則の
新規登録処理となる。
In the next step 23, it is further determined whether or not the replacement rule is already defined. If the replacement rule is already defined in this determination, step 24
In step 24, the rule registered in the data type replacement rule storage table 16 is deleted, and then in step 25, the input replacement rule is registered in the data type replacement rule table. In this case, the update processing of the data type replacement rule already registered in the data type replacement rule storage table 16 is performed. If the replacement rule is not already defined in the determination processing of step 23, the process immediately proceeds to step 25, and the input replacement rule is registered in the data type replacement rule table. In this case, the data type replacement rule is newly registered in the data type replacement rule storage table 16.

【0022】このようにしてデータ型置換規則格納テー
ブル16に入力されて登録され、定義されたデータ型置
換規則は、例えば、図3に示すようなフォーマットのハ
ッシュ表30に登録される。
The data type substitution rules defined and input by the data type substitution rule storage table 16 in this manner are registered in the hash table 30 in the format as shown in FIG. 3, for example.

【0023】図3は、データ型置換規則格納テーブルに
相当するハッシュテーブルの一例を示す図である。デー
タ型置換規則は、図3に示すように、各々のデータ型の
置換規則30が、抽象データ型31と対応づけられた置
換データ型32として登録されている。例えば、抽象デ
ータ型“stream”には置換データ型“file-stream”が
対応づけられ、また、抽象データ型“integer”には置
換データ型“fixnum”が対応づけられている。このデー
タ型置換規則により、データ型「integer」は更に具体
的なデータ型「fixnum」に置換されることになる。
FIG. 3 is a diagram showing an example of a hash table corresponding to the data type replacement rule storage table. As for the data type replacement rule, as shown in FIG. 3, the replacement rule 30 of each data type is registered as a replacement data type 32 associated with an abstract data type 31. For example, the abstract data type “stream” is associated with the replacement data type “file-stream”, and the abstract data type “integer” is associated with the replacement data type “fixnum”. By this data type replacement rule, the data type “integer” is replaced with a more specific data type “fixnum”.

【0024】[2:データ型推論処理]上述のようなデ
ータ型置換規則の入力処理が終了すると、データ型の推
論処理が可能となる。図4はデータ型格納テーブルの一
例を示す図であり、また、図5および図6は、データ型
推論処理の処理例を説明するフローチャートである。次
に、図4〜図6を参照してデータ型推論の処理を説明す
る。データ型推論の処理は、ソースプログラムを読み込
み、データ型情報を検出しデータ型格納テーブルに登録
する処理と、ソースプログラムから取り出したデータ型
情報,プログラム構造,およびデータ型置換規則から型
推論を行う処理とに、分けて行なわれる。
[2: Data type inference processing] When the input processing of the data type replacement rule as described above is completed, the data type inference processing becomes possible. FIG. 4 is a diagram showing an example of the data type storage table, and FIGS. 5 and 6 are flowcharts for explaining a processing example of the data type inference processing. Next, the data type inference process will be described with reference to FIGS. The data type inference process reads the source program, detects data type information and registers it in the data type storage table, and performs type inference from the data type information, program structure, and data type replacement rules extracted from the source program. The processing is performed separately.

【0025】Common Lispのソースプログラム11
が、データ型推論装置12に入力されると、データ型情
報検出登録機構13により、ソースプログラム中の各々
のS式(symbolic expression)に対して、その式が変
数や関数のデータ型情報を含んだ式(declare式やprocl
aim式など)であるかどうかが調ベられ、もし含んでい
る場合には、そのデータ型情報が、図4に示すようなハ
ッシュ表形式のデータ型情報格納テーブル40に登録さ
れる。
Source program 11 of Common Lisp
Is input to the data type inference device 12, the data type information detection / registration mechanism 13 includes, for each S expression (symbolic expression) in the source program, the expression includes data type information of variables and functions. Expression (declare expression or procl
It is determined whether or not it is an aim expression), and if it is included, the data type information is registered in the data type information storage table 40 in the hash table format as shown in FIG.

【0026】図4に示すハッシュ表形式のデータ型情報
格納テーブル40は、名前フィールド41,フレーム名
フィールド42,データ型名フィールド43,定義型?
フィールド43を有するハッシュ表形式のテーブルであ
る。このデータ型情報格納テーブル40において、名前
フィールド41には、変数や関数の名前を示す情報が格
納される。フレーム名フィールド42には、名前が重複
した場合でも区別できるように、当該変数や関数がどの
関数や制御構造の中のものであるかを示す情報が格納さ
れる。データ型名フィールド43には、データ型名を示
す情報が格納される。また、定義型?フィールド44に
は、当該変数のデータ型が宣言文によって、明示的に宣
言されたものであるかを示す情報が格納される。
The hash table format data type information storage table 40 shown in FIG. 4 has a name field 41, a frame name field 42, a data type name field 43, and a definition type?
It is a hash table format table having a field 43. In the data type information storage table 40, the name field 41 stores information indicating the names of variables and functions. In the frame name field 42, information indicating which function or control structure the variable or function belongs to is stored so that it can be distinguished even if the names are duplicated. The data type name field 43 stores information indicating the data type name. Also, the definition type? The field 44 stores information indicating whether the data type of the variable is explicitly declared by a declaration statement.

【002 【0027】ところで、関数のデータ型情報の場合、例
えば、名前“cdr”のデータ型情報のように、データ型
名フィールド43には(function (list list) list)
のような形式で関数のフォーマットを示す形式データが
格納される。このように関数のデータ型は (function (<引数のデータ型1> <引数のデータ型2> … ) <戻り値のデータ型>) のような形式で格納される。
By the way, in the case of the data type information of a function, for example, like the data type information of the name "cdr", the data type name field 43 has (function (list list) list).
Format data indicating the format of the function is stored in a format such as. In this way, the data type of the function is stored in a format such as (function (<argument data type 1><argument data type 2> ...) <return value data type>).

【0028】また、定義型?フィールド44に格納され
る“定義型?”の情報Tは、当該変数または関数が、そ
のデータ型が宣言文によって明示的に宣言されたもので
あるか、あるいは推論の結果得られたデータ型であるか
を示している。つまり、データ型情報検出登録機構13
によって登録されたデータ型情報の場合には、すベて
“定義型?”の情報として、Tがセットされる。
In addition, the definition type? The "definition type?" Information T stored in the field 44 is the data type of the variable or function whose data type is explicitly declared by a declaration statement, or the data type obtained as a result of inference. It shows whether there is. That is, the data type information detection registration mechanism 13
In the case of the data type information registered by, T is set as the information of "definition type?".

【0029】このようなソースプログラム11からデー
タ型情報を検出しデータ型格納テーブル14に登録する
処理は、データ型情報検出登録機構13により行なわれ
る。図5を参照して、データ型情報検出登録機構13の
処理を説明する。この処理では、まず、ステップ51に
おいて、ソースファイルから1つのトップレベルフォー
ムを入力する。次に、ステップ52において、ソースフ
ァイル中のトップレベルフォームは終りか否かを判定す
る。トップレベルフォームが終りであると、ここでのデ
ータ型格納テーブルにデータ型を格納する処理は終了す
るので、次の処理ステップ55(図6)に進む。また、
ステップ52でソースファイル中のトップレベルフォー
ムが終りでなければ、ステップ53において、入力した
トップレベルフォームは、preclaimフォームまたはdecl
areフォームを含んだフォームであるか否かを判定し、
入力したトップレベルフォームがpreclaimフォームまた
はdeclareフォームを含んだフォームであると判定され
た場合には、ステップ54に進み、データ型格納テーブ
ルに宣言されたデータ型を格納する。そして、ステップ
51に戻り、ソースファイル中の次のトップレベルフォ
ームに対して、ステップ51からの処理を繰り返し行
う。このようにして、データ型格納テーブルに対して宣
言されたデータ型の全ての格納処理を終了した後、次
に、ステップ55に進み、ソースプログラムから取り出
したデータ型情報,プログラム構造,およびデータ型置
換規則から型推論を行う。この型推論の処理は、処理の
制御を型推論機構15に移して行う。
The process of detecting the data type information from the source program 11 and registering it in the data type storage table 14 is performed by the data type information detecting / registering mechanism 13. The processing of the data type information detection / registration mechanism 13 will be described with reference to FIG. In this process, first, in step 51, one top level form is input from the source file. Next, in step 52, it is determined whether the top level form in the source file is over. When the top-level form is finished, the process of storing the data type in the data type storage table here is finished, so the process proceeds to the next processing step 55 (FIG. 6). Also,
If the top level form in the source file is not the end in step 52, the top level form input in step 53 is the preclaim form or decl.
Determine whether it is a form that includes an are form,
When it is determined that the input top level form is a form including a preclaim form or a declare form, the process proceeds to step 54 and the declared data type is stored in the data type storage table. Then, returning to step 51, the processing from step 51 is repeated for the next top level form in the source file. In this way, after all the storage processing of the data types declared in the data type storage table is completed, the process proceeds to step 55, and the data type information extracted from the source program, the program structure, and the data type Perform type inference from the replacement rules. This type inference process is performed by transferring control of the process to the type inference mechanism 15.

【0030】図6を参照する。宣言されたデータ型情報
をデータ型格納テーブル14に格納した後、ステップ5
5に進む。ステップ55では、まず、ソースファイルを
リワインドする。次に、ステップ56において、ソース
ファイルから1つのトップレベルフォームを入力する。
次に、ステップ57において、ソースファイル中のトッ
プレベルフォームは終りか否かを判定する。トップレベ
ルフォームが終りであると、このトップレベルフォーム
に対する型推論処理は終了するので、次にステップ61
に進む。また、ステップ57でソースファイル中のトッ
プレベルフォームが終りでなければ、次のステッフ58
の処理で、入力したトップレベルフォームにおいて、フ
ォーム中の変数および関数定義に関するデータ型情報を
データ型格納テーブルから取り出す。次に、ステップ5
9において、取り出したデータ型情報とフォームの構造
から型推論を行う。この時、データ型置換規則テーブル
に登録された抽象データ型は置換データ型に置き換えて
型推論を行う。そして、次のステップ60において、デ
ータ型格納テーブルに新しく型推論された結果を格納す
る。
Referring to FIG. After storing the declared data type information in the data type storage table 14, step 5
Go to 5. In step 55, first, the source file is rewound. Next, in step 56, one top level form is entered from the source file.
Next, in step 57, it is determined whether the top level form in the source file is over. If the top-level form is the end, the type inference process for this top-level form is completed, so next step 61
Proceed to. If the top level form in the source file does not end in step 57, the next step 58
In the above process, in the input top level form, the data type information regarding the variable and function definition in the form is retrieved from the data type storage table. Next, step 5
At 9, type inference is performed from the extracted data type information and the structure of the form. At this time, the abstract data type registered in the data type replacement rule table is replaced with the replacement data type to perform type inference. Then, in the next step 60, the newly type-inferred result is stored in the data type storage table.

【0031】このようにして、ステップ56で入力した
現在の1つトップレベルフォームに対して、ステップ5
8〜ステップ60の型推論の処理が終了すると、次のト
ップレベルフォームに対して型推論を行うベく、ステッ
プ56に進む。ステップ56では、ソースファイルから
次の1つのトップレベルフォームを入力し、次の処理ス
テップ57に進み、以下、同様の型推論の処理を繰り返
し行う。
Thus, for the current one top-level form entered in step 56, step 5
When the type inference processing of 8 to step 60 is completed, the type inference is performed on the next top level form, and the process proceeds to step 56. In step 56, the next one top level form is input from the source file, the process proceeds to the next process step 57, and the same type inference process is repeated.

【0032】ソースファイル中の全てのトップレベルフ
ォームに対する型推論の処理が終了すると、ステップ5
7の判定処理により、ソースファイル中のトップレベル
フォームの終りが判定できるので、次にステップ61に
進む。そして、ステップ61において、データ型格納テ
ーブルの内容が更新されたか否かを判定する。データ型
格納テーブルの内容が更新された場合には、型推論によ
りデータ型が変更されたので、データ型の推論による変
更が最終的なものであることを確認すべく、再び型推論
処理を行うために、ステップ55に戻り、ステップ55
からの処理を繰り返し行う。また、ステップ61の判定
処理で、データ型格納テーブルの内容が更新されていな
ければ、これまでの型推論の処理により、データ型が確
定したことを意味するので一連の処理を終了する。
When the type inference processing for all the top level forms in the source file is completed, step 5
Since the end of the top level form in the source file can be determined by the determination processing of 7, the process proceeds to step 61. Then, in step 61, it is determined whether or not the content of the data type storage table has been updated. When the content of the data type storage table is updated, the data type was changed by type inference, so type inference processing is performed again to confirm that the change due to data type inference is final. To return to step 55,
The process from is repeated. If the content of the data type storage table is not updated in the determination processing of step 61, it means that the data type has been determined by the processing of the type inference so far, and the series of processing is terminated.

【0033】次に、データ型推論装置により型推論を行
った結果のソースプログラムの具体例を説明する。図7
はデータ型の宣言がなされていない型推論前のソースプ
ログラムの一例を示す図であり、図8はデータ型推論装
置により型推論を行った結果のソースプログラムの一例
を示す図である。図7に示す型推論前のソースプログラ
ム71に対して、データ型推論装置により型推論を行っ
た結果、図8に示すように、当該ソースプログラム81
には、型推論の結果として、関数に対するデータ型宣言
フォーム82と、当該関数の変数x,y,zのデータ型
が整数型である旨を指示するデータ型宣言フォーム83
が付加される。
Next, a specific example of the source program resulting from the type inference performed by the data type inference apparatus will be described. Figure 7
FIG. 9 is a diagram showing an example of a source program before type inference in which a data type is not declared, and FIG. 8 is a diagram showing an example of a source program resulting from type inference by a data type inference apparatus. As a result of performing type inference by the data type inference apparatus on the source program 71 before type inference shown in FIG. 7, as shown in FIG.
Includes a data type declaration form 82 for the function as a result of the type inference, and a data type declaration form 83 that indicates that the data types of the variables x, y, and z of the function are integer types.
Is added.

【0034】データ型の推論処理では、まず、データ型
情報検出登録機構13により、ソースプログラムで宣言
されたデータ型を検出して、データ型格納テーブル14
への登録する処理を終了すると、処理の制御は型推論機
構15に移される。ここでの例の図7のソースプログラ
ム71では、データ型の宣言はないので、直ちに型推論
を行う処理に制御が移される。型推論機構15ではソー
スファイルをリワインドして、ソースファイル中のS式
を1つずつ読み込み、型推論の処理を行う。このとき、
ソースファイルから読み込まれたフォーム中の出現する
変数や関数のデータ型がデータ型格納テーブル14から
取り出され、データ型格納テーブルから取り出されたデ
ータ型情報と、プログラム構造から、型推論処理が行な
われる。
In the data type inference processing, first, the data type information detection / registration mechanism 13 detects the data type declared in the source program, and the data type storage table 14 is detected.
When the process of registering with is completed, the control of the process is transferred to the type inference mechanism 15. In the source program 71 of FIG. 7 in this example, since there is no data type declaration, control is immediately transferred to the process of performing type inference. The type inference mechanism 15 rewinds the source file, reads the S expressions in the source file one by one, and performs type inference processing. At this time,
The data types of variables and functions appearing in the form read from the source file are fetched from the data type storage table 14, and the type inference processing is performed from the data type information fetched from the data type storage table and the program structure. ..

【0035】図7のソースプログラム71では、明示的
に宣言されているデータ型は存在しないので、ソースプ
ログラムで定義されている関数72のプログラム構造か
ら、データ型の型推論が行なわれる。また、型推論処理
では、型推論される全てのデータ型について、そのデー
タ型に対する置換規則が定義されていないかどうかをデ
ータ型置換規則格納テーブル16の検索により調ベ、型
推論の処理を進める。もし、データ型置換規則格納テー
ブル16に該当する置換規則を発見した場合、当該デー
タ型を置換データ型に置き換えて、再度の型推論処理を
繰り返し行う。
In the source program 71 of FIG. 7, since the explicitly declared data type does not exist, the data type is inferred from the program structure of the function 72 defined in the source program. In the type inference process, the type inference process is performed by searching the data type substitution rule storage table 16 to determine whether or not the substitution rules for the data types to be type inferred are defined. .. If a corresponding replacement rule is found in the data type replacement rule storage table 16, the data type is replaced with the replacement data type, and the type inference process is repeated.

【0036】型推論の結果として特定された未知の変数
や関数のデータ型はデータ型格納テーブル14に登録さ
れる。そして、型推論処理はデータ型置換規則格納テー
ブル16によるデータ型情報による変更が発生しなくな
り、データ型格納テーブルにおいて特定のデータ型に収
束するまで繰り返し行う。ここではプログラム構造から
型推論の結果、関数72が変数x,y,zを伴う条件判
定を行う関数であり、かつ、条件判定を引数の変数x,
yの大小比較により行い、判定結果を引数の変数zに返
す関数であることから、当該関数の変数x,y,zのデ
ータ型が整数型であり、更に整数型の下位である固定長
型の“fixnum”であるとの型推論がなされ、関数に対す
るデータ型宣言フォーム82と、当該関数の変数x,
y,zのデータ型が整数型である旨を指示するデータ型
宣言フォーム83が付加された結果となる。
The data type of the unknown variable or function specified as a result of the type inference is registered in the data type storage table 14. Then, the type inference process is repeated until the change due to the data type information by the data type replacement rule storage table 16 does not occur and the data type storage table 16 converges to a specific data type. Here, as a result of type inference based on the program structure, the function 72 is a function that performs a conditional judgment involving variables x, y, and z, and the conditional judgment is a variable x, which is an argument.
The data type of the variables x, y, and z of the function is an integer type, and is a fixed-length type that is a subordinate of the integer type, because the function returns the determination result to the variable z of the argument by comparing the magnitude of y. "Fixnum" is inferred, and the data type declaration form 82 for the function and the variable x,
As a result, the data type declaration form 83 indicating that the data types of y and z are integer types is added.

【0037】次に、本実施例にかかるデータ型推論装置
の変形例について説明する。上述のデータ型置換規則
は、図3に示すように、抽象データ型と置換データ型と
の1対1の置換規則としたが、データ型置換規則は、抽
象的なデータ型からそのサブタイプへの1対1の変換規
則である必要はない。抽象的なデータ型のサブタイプ全
てを置換データ型によって置き換えてもよい。
Next, a modification of the data type inference apparatus according to this embodiment will be described. The above-mentioned data type replacement rule is a one-to-one replacement rule between an abstract data type and a replacement data type, as shown in FIG. 3, but the data type replacement rule changes from an abstract data type to its subtype. It does not have to be a one-to-one conversion rule of. All subtypes of abstract data types may be replaced by replacement data types.

【0038】また、データ型置換規則は推論結果から自
動的に定義されたもよい。例えば、使用されている変数
がx,y,z,nの4つしかなく、型推論の結果が x→integer, y→fixnum, z→fixnum,n→real のような場合には、 real→fixnum, integer→fixnum のような置換規則を自動的に生成して、データ型置換規
則テーブルに格納して別のデータ型の推論を行う際の置
換規則として用いるようにしてもよい。このような場合
にも、型推論の処理を行う際には、予め決められたデー
タ型変換の規則にしたがって、抽象的なデータ型がその
サブタイプのいずれかに置換され、型推論が行なわれ
る。これにより、データ型宣言を十分に行なわなくて
も、型推論の結果によって、抽象的なデータ型をより具
体的なデータ型に変換することが可能となる。
Further, the data type replacement rule may be automatically defined from the inference result. For example, if there are only four variables used x, y, z, and n, and the result of type inference is x → integer, y → fixnum, z → fixnum, n → real, then real → A substitution rule such as fixnum, integer → fixnum may be automatically generated and stored in the data type substitution rule table to be used as a substitution rule when inferring another data type. Even in such a case, when the type inference process is performed, the abstract data type is replaced with one of the subtypes according to a predetermined data type conversion rule, and the type inference is performed. .. As a result, it is possible to convert an abstract data type into a more specific data type according to the result of type inference, without sufficiently performing data type declaration.

【0039】以上に説明した本実施例にかかるデータ型
推論装置の特徴点をまとめれば、次のようなる。 (1)ソースプログラムを同一または別のプログラミン
グ言語のソースプログラムに変換するプログラム変換装
置、あるいはソースプログラムを械機語にに翻訳するコ
ンパイラにおいて用いられる型推論を行うデータ型推論
装置である。 (2)このデータ型推論装置には、ソースプログラム中
に存在するデータ型宣言文などの変数や関数に関して、
既に宣言されたデータ型情報を取り出すデータ型情報検
出登録機構を備える。 (3)ソースプログラム中に各変数に対するデータ型情
報を記憶し保持しておくためのデータ型格納テーブルを
備える。 (4)階層構造を有するデータ型においては、特定のデ
ータ型をそのサブタイプのいずれかのデータ型によって
置換する置換規則をユーザが入力するためデータ型置換
規則入力格納機構を備える。 (5)ユーザにより入力されたデータ型置換規則を記憶
し保持しておくためデータ型置換規則格納テーブルを備
える。 (6)ソースプログラムのソースコード中に明示的にデ
ータ型が宣言されていない変数や関数については、デー
タ型格納テーブルに登録されたデータ型情報およびプロ
グラム構造から、データ型の推論を行なう。これと同時
に置換規則が与えられているデータ型については、指定
されたデータ型に置換して推論を行う。
The features of the data type inference apparatus according to this embodiment described above can be summarized as follows. (1) A program conversion device that converts a source program into a source program of the same or another programming language, or a data type inference device that performs type inference used in a compiler that translates a source program into a machine language. (2) In this data type inference device, regarding variables and functions such as data type declaration statements existing in the source program,
A data type information detection / registration mechanism for extracting the already declared data type information is provided. (3) A data type storage table for storing and holding data type information for each variable is provided in the source program. (4) A data type having a hierarchical structure is provided with a data type substitution rule input storage mechanism for the user to input a substitution rule for substituting a specific data type with one of the subtypes. (5) A data type replacement rule storage table is provided to store and retain the data type replacement rule input by the user. (6) For a variable or function whose data type is not explicitly declared in the source code of the source program, the data type is inferred from the data type information and the program structure registered in the data type storage table. At the same time, the data type for which the replacement rule is given is replaced with the specified data type for inference.

【0040】[0040]

【発明の効果】以上に説明したように、本発明の型推論
装置によれば、データ型を置換するための置換規則を登
録したテーブルが記憶され、この置換規則を登録したテ
ーブルを参照して、テーブル内容から上位のデータ型を
下位のデータ型に変換する推論を行うので、宣言文とし
て登録されたデータ型と同様に、型推論を行うデータ型
がより下位の具体的なデータ型に導くことが可能とな
り、コンパイル処理におけるコード最適化を容易にさせ
ることができる。
As described above, according to the type inference apparatus of the present invention, the table in which the substitution rule for replacing the data type is registered is stored, and the table in which this substitution rule is registered is referred to. , Inference is performed by converting the upper data type to the lower data type from the table contents, so the data type for which type inference is performed leads to a lower specific data type, similar to the data type registered as a declaration statement. This makes it possible to facilitate code optimization in the compilation process.

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

【図1】 図1は本発明の一実施例にかかるデータ型推
論装置の要部の構成を示すブロック図、
FIG. 1 is a block diagram showing a configuration of a main part of a data type inference device according to an embodiment of the present invention,

【図2】 図2はデータ型置換規則入力格納機構が行う
データ型置換規則入力処理の処理フローの一例を示すフ
ローチャート、
FIG. 2 is a flowchart showing an example of a processing flow of a data type replacement rule input process performed by a data type replacement rule input storage mechanism;

【図3】 図3はデータ型置換規則格納テーブルに相当
するハッシュテーブルの一例を示す図、
FIG. 3 is a diagram showing an example of a hash table corresponding to a data type replacement rule storage table,

【図4】 図4はデータ型情報格納テーブルの一例を示
す図、
FIG. 4 is a diagram showing an example of a data type information storage table,

【図5】 図5はデータ型推論処理の処理例を説明する
第1のフローチャート、
FIG. 5 is a first flowchart illustrating a processing example of data type inference processing,

【図6】 図6はデータ型推論処理の処理例を説明する
第1のフローチャートに続く第2のフローチャート、
FIG. 6 is a second flowchart following the first flowchart for explaining the processing example of the data type inference processing;

【図7】 図7はデータ型の宣言がなされていない型推
論前のソースプログラムの一例を示す図
FIG. 7 is a diagram showing an example of a source program before type inference in which a data type is not declared.

【図8】 図8はデータ型推論装置により型推論を行っ
た結果のソースプログラムの一例を示す図である。
FIG. 8 is a diagram showing an example of a source program resulting from type inference performed by a data type inference apparatus.

【図9】 図9はデータ型宣言が必要なプログラミング
言語における変数のデータ構造を説明する図、
FIG. 9 is a diagram illustrating a data structure of a variable in a programming language that requires a data type declaration,

【図10】 図10はオブジェクト指向のプログラミン
グ言語における変数のデータ構造を説明する図、
FIG. 10 is a diagram illustrating a data structure of variables in an object-oriented programming language,

【図11】 Common Lispにおけるnumberのデータ型
の階層構造を説明する図である。
FIG. 11 is a diagram illustrating a hierarchical structure of a number data type in Common Lisp.

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

11…ソースプログラム、12…データ型推論装置、1
3…データ型情報検出登録機構、14…データ型格納テ
ーブル、15…型推論機構、16…データ型置換規則格
納テーブル、17…データ型置換規則入力格納機構、3
0…データ型の置換規則、40…データ型情報格納テー
ブル、71…型推論前のソースプログラム、81…型推
論後のソースプログラム。
11 ... Source program, 12 ... Data type inference device, 1
3 ... Data type information detection registration mechanism, 14 ... Data type storage table, 15 ... Type inference mechanism, 16 ... Data type replacement rule storage table, 17 ... Data type replacement rule input storage mechanism, 3
0 ... Data type replacement rule, 40 ... Data type information storage table, 71 ... Source program before type inference, 81 ... Source program after type inference.

Claims (1)

【特許請求の範囲】[Claims] 【請求項1】 ソースプログラムにおけるデータ型の未
宣言の変数や関数について、登録されたデータ型と当該
ソースプログラムの構造に基づきデータ型の推論を行う
型推論装置であって、 階層構造データ型の上位のデータ型を特定可能な下位の
データ型に置換する置換規則を登録したテーブルを記憶
する記憶手段と、 前記テーブルを参照して、テーブル内容から上位のデー
タ型を下位のデータ型に変換する型推論を行う型推論手
段とを備えることを特徴とする型推論装置。
1. A type inference apparatus for inferring a data type based on the registered data type and the structure of the source program for undeclared variables and functions of the data type in the source program, which is a hierarchical structure data type. Storage means for storing a table in which a substitution rule for substituting an upper data type with a identifiable lower data type is stored; and referring to the table, converting the upper data type into a lower data type from the table contents A type inference apparatus comprising a type inference means for performing type inference.
JP3219262A 1991-08-06 1991-08-06 Type inferring device Pending JPH0540631A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP3219262A JPH0540631A (en) 1991-08-06 1991-08-06 Type inferring device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP3219262A JPH0540631A (en) 1991-08-06 1991-08-06 Type inferring device

Publications (1)

Publication Number Publication Date
JPH0540631A true JPH0540631A (en) 1993-02-19

Family

ID=16732771

Family Applications (1)

Application Number Title Priority Date Filing Date
JP3219262A Pending JPH0540631A (en) 1991-08-06 1991-08-06 Type inferring device

Country Status (1)

Country Link
JP (1) JPH0540631A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003501742A (en) * 1999-06-07 2003-01-14 マイクロソフト コーポレイション Inferring operand types in intermediate languages
WO2022190418A1 (en) * 2021-03-11 2022-09-15 オムロン株式会社 Development assitance device, development assitance method, and development assitance program

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003501742A (en) * 1999-06-07 2003-01-14 マイクロソフト コーポレイション Inferring operand types in intermediate languages
WO2022190418A1 (en) * 2021-03-11 2022-09-15 オムロン株式会社 Development assitance device, development assitance method, and development assitance program

Similar Documents

Publication Publication Date Title
JP4794437B2 (en) An extended system for representing and checking the integrity of program components during the editing process
CN110187885B (en) Intermediate code generation method and device for quantum program compiling
US6014518A (en) Terminating polymorphic type inference program analysis
CN108920133B (en) Cross-language programming method and device, electronic equipment and storage medium
Lewis et al. Implicit parameters: Dynamic scoping with static types
US8707278B2 (en) Embedding class hierarchy into object models for multiple class inheritance
EP0118829A2 (en) Compilation of perform statements
JP2007521568A (en) Intermediate representation of multiple exception handling models
JPH096627A (en) Optimizing device
US7685581B2 (en) Type system for representing and checking consistency of heterogeneous program components during the process of compilation
JPH01306923A (en) System for connecting different languages
US6948170B2 (en) Computer and computer-readable storage medium for command interpretation
Lawson Programming-language-oriented instruction streams
JPH0540631A (en) Type inferring device
Koskimies et al. The design of a language processor generator
CN111767033A (en) Programming system for mechanical arm program development and function extension method
Van Reeuwijk Tm: A code generator for recursive data structures
JPH07146785A (en) Method for automatically generating program and device therefor
Turba The Pascal exception handling proposal
JP3580394B2 (en) Program conversion device and program conversion method
Allais Seamless, Correct, and Generic Programming over Serialised Data
CN112579856A (en) Method and device for processing crawling control instruction
CN114895958A (en) Method and device for generating code statement of configuration table, electronic equipment and medium
JPH06266562A (en) Object code size optimizing system in object-oriented language processing system
Cox et al. Implementing Functional Languages on the Transputer