JPH0659902A - Processing method for substituting character string - Google Patents

Processing method for substituting character string

Info

Publication number
JPH0659902A
JPH0659902A JP21383792A JP21383792A JPH0659902A JP H0659902 A JPH0659902 A JP H0659902A JP 21383792 A JP21383792 A JP 21383792A JP 21383792 A JP21383792 A JP 21383792A JP H0659902 A JPH0659902 A JP H0659902A
Authority
JP
Japan
Prior art keywords
character string
pointer
replacement
stack
argument
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
JP21383792A
Other languages
Japanese (ja)
Inventor
Kiyoshi Otaki
潔 大瀧
Hiroyuki Suzuki
啓之 鈴木
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.)
KOBE NIPPON DENKI SOFTWARE KK
NEC Corp
NEC Software Kobe Ltd
Original Assignee
KOBE NIPPON DENKI SOFTWARE KK
NEC Corp
NEC Software Kobe 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 KOBE NIPPON DENKI SOFTWARE KK, NEC Corp, NEC Software Kobe Ltd filed Critical KOBE NIPPON DENKI SOFTWARE KK
Priority to JP21383792A priority Critical patent/JPH0659902A/en
Publication of JPH0659902A publication Critical patent/JPH0659902A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PURPOSE:To provide a character string substituting method having faster speed and higher memory using efficiency as compared with a convensional method. CONSTITUTION:A substituting character string table for storing definition information for a character string to be substituted is prepared. Then a stack having a pointer to the character string to be substituted in the table and a pointer to the argument of the character string to be substituted in an input area as elements is parepared. The character string in the input area is retrieved and whether the character string is substituted or not is judged. When substitution is necessary, the table is referred to and the pointer to the character string to be substituted and the pointer to the argument of the character string to be substituted in the input area are stored in a stack. A character string specified by the pointer stored in the stack is copied to an output area to substitute the character string.

Description

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

【0001】[0001]

【産業上の利用分野】本発明は、効率の良い文字列の置
換処理方法に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to an efficient character string replacement processing method.

【0002】[0002]

【従来の技術】文字列を入力して、文字列の置換処理を
行なう方法として、従来、図6に示すような処理方法が
知られている。
2. Description of the Related Art As a method of inputting a character string and performing a character string replacement process, a processing method as shown in FIG. 6 is conventionally known.

【0003】この処理方式を、図8に示すようなCコン
パイラのプリプロセッサにおいて、「#define
f(x,y) x+y」という定義により、文字列「f
(100,200)」を文字列「100+200」に置
換する処理について、図6と図7を用いて説明する。
This processing method is applied to "#define" in a preprocessor of a C compiler as shown in FIG.
By the definition of “f (x, y) x + y”, the character string “f
The process of replacing (100, 200) ”with the character string“ 100 + 200 ”will be described with reference to FIGS. 6 and 7.

【0004】まず、置換しようとする文字列の定義情報
(この例の場合、「f(x,y)x+y」)をデータと
して格納するテーブル(以下、置換文字列テーブルと呼
ぶ)を生成する(S20)。次に図7に示すような入力
領域上の文字列を検索し、置換すべき文字列かどうか判
定する(S21)。もし、置換すべき文字列(この場合
「f」(n26)、以下、被置換文字列と呼ぶ)を発見
した場合、この被置換文字列以降(この場合、「(10
0,200)==300){」(c27))を退避領域
へ複写して退避する(S22)。退避した文字列のう
ち、被置換文字列「f」の引数(この場合「100」
(c28)と「200」(c29))までと、置換文字
列テーブルに格納している文字列(この場合「+」(c
30))を出力領域に複写する(S23)。その後、被
置換文字列の引数以降(この場合「==300){」
(c31))を出力領域に複写する(S24)。入力領
域上に置換すべき文字列がない場合、入力領域上の文字
列を出力領域に複写する(S25)。
First, a table (hereinafter referred to as a replacement character string table) for storing definition information of a character string to be replaced (in this example, "f (x, y) x + y") as data is generated ( S20). Next, the character string on the input area as shown in FIG. 7 is searched to determine whether it is a character string to be replaced (S21). If a character string to be replaced (in this case, "f" (n26), hereinafter referred to as a replaced character string) is found, this replaced character string and thereafter (in this case, "(10
0,200) == 300) {”(c27)) is copied to the save area and saved (S22). Of the saved character strings, the argument of the replaced character string “f” (in this case, “100”
Up to (c28) and "200" (c29), the character strings stored in the replacement character string table (in this case, "+" (c
30)) is copied to the output area (S23). Then, after the argument of the replaced character string (in this case, "== 300) {"
(C31)) is copied to the output area (S24). If there is no character string to be replaced in the input area, the character string in the input area is copied to the output area (S25).

【0005】[0005]

【発明が解決しようとする課題】前述した従来の方式で
は、置換すべき文字列を発見した場合、この被置換文字
列以降の文字列を退避する必要があるため、入力領域と
出力領域以外に新しく退避領域を用意する必要があり、
また、入力領域から退避領域へ、退避領域から出力領域
へ文字列を2度複写しなければならないため効率が悪い
という欠点がある。
In the above-mentioned conventional method, when a character string to be replaced is found, it is necessary to save the character string after the character string to be replaced. It is necessary to prepare a new save area,
In addition, since the character string must be copied twice from the input area to the save area and from the save area to the output area, there is a disadvantage that the efficiency is low.

【0006】[0006]

【課題を解決するための手段】本発明の文字列置換処理
方法は、入力された文字列中の置換すべき文字列の置換
を行うCコンハイラのプリプロセッサにおける文字列置
換処理方法において、置換する文字列の定義情報を格納
する置換文字列テーブルを備え、前記テーブル中の置換
文字列へのポインタと入力領域上の被置換文字列の引数
へのポインタを要素としてもつスタックを用意し、前記
入力領域上の文字列の置換の有無を判定し、前記置換が
必要でない場合前記入力領域上の文字列を予め備えた出
力領域に出力し、前記置換が必要な場合前記置換文字列
テーブルを参照して前記置換文字列へのポインタと前記
入力領域上の被置換文字列の引数へのポインタを前記ス
タックに格納し、前記スタック中のポインタが指す文字
列を前記出力領域に複写することを特徴とする。
SUMMARY OF THE INVENTION A character string replacement processing method of the present invention is a character replacement processing method in a C processor preprocessor for replacing a character string to be replaced in an input character string. A stack having a replacement character string table for storing column definition information is provided, and a stack having a pointer to the replacement character string in the table and a pointer to the argument of the replaced character string on the input area as an element is prepared, Whether the above character string is replaced or not is determined, and when the replacement is not necessary, the character string on the input area is output to an output area provided in advance, and when the replacement is necessary, the replacement character string table is referred to. A pointer to the replacement character string and a pointer to the argument of the replaced character string on the input area are stored in the stack, and the character string pointed to by the pointer in the stack is stored in the output area. Characterized by copying.

【0007】[0007]

【実施例】次に、本発明の詳細を、Cコンパイラのプリ
プロセッサにおける文字列の置換処理を用いて、図面を
参照しながら説明する。
DESCRIPTION OF THE PREFERRED EMBODIMENTS Next, details of the present invention will be described with reference to the drawings by using a character string replacing process in a preprocessor of a C compiler.

【0008】図1は、本発明の一実施例の処理の流れ図
である。図1を参照して本実施例の動作を説明する。
FIG. 1 is a flow chart of processing of an embodiment of the present invention. The operation of this embodiment will be described with reference to FIG.

【0009】置換文字列テーブルの生成処理(S1)
は、置換しようとする文字列の定義をあらかじめトーク
ンとしてテーブルに格納するための処理である。置換文
字列テーブルは、図2の(T7)に示すように、置換文
字列名(t9)とトークン(t10)の集まりで構成さ
れる。トークンには引数ドークンと文字列トークンがあ
る。
Generation process of replacement character string table (S1)
Is a process for storing the definition of the character string to be replaced in the table as a token in advance. As shown in (T7) of FIG. 2, the replacement character string table is composed of a collection of replacement character string names (t9) and tokens (t10). Tokens include argument Dokun and string tokens.

【0010】例えば、「#define f(x,y)
x+y」という定義は、図2の(T8)という置換文
字列テーブルに格納する。置換文字列名は「f」であ
り、欄t9中に文字列として格納する。(t11)は引
数トークンであり、定義中の文字列に引数がある場合、
その引数と対応しており(この列の場合「x」と
「y」)、被置換文字列を見つけたときに、その被置換
文字列の引数の文字列でこのトークンを置き換えること
を示している。
For example, "#define f (x, y)
The definition "x + y" is stored in the replacement character string table (T8) in FIG. The replacement character string name is “f” and is stored as a character string in the field t9. (T11) is an argument token, and when there is an argument in the character string being defined,
Corresponds to that argument ("x" and "y" for this column), and indicates that when it finds the replaced string, it replaces this token with the argument string of that replaced string. There is.

【0011】(t12)は文字列トークンであり、定義
文字列に記述されている引数以外の文字列であることを
示している。
(T12) is a character string token, which indicates that it is a character string other than the argument described in the definition character string.

【0012】次に制御をスタックの生成処理(S2)に
移す。スタックの生成処理(S2)では、文字列の先頭
を指すポインタを要素にもつテーブル(これをスタッフ
と呼ぶ)を生成する。次に制御を置換文字列の検索処理
(S3)に移す。置換文字列の検索処理(S3)では、
入力領域上に置換すべき文字列があるかどうかを検索す
る。もし、置換すべき文字列が存在した場合、制御を入
力領域上の文字列のポインタをスタックに格納する処理
(S4)に移し、置換すべき文字列が存在しない場合、
制御を入力領域上に文字列を出力領域へ複写する処理
(S6)に移す。
Next, the control is transferred to the stack generation process (S2). In the stack generation process (S2), a table (which is called a stuff) having a pointer that points to the beginning of the character string as an element is generated. Next, the control is transferred to the replacement character string search process (S3). In the replacement character string search process (S3),
Search for a character string to be replaced in the input area. If there is a character string to be replaced, the control is moved to the process of storing the pointer of the character string in the input area on the stack (S4), and if the character string to be replaced does not exist,
The control is transferred to a process (S6) of copying the character string on the input area to the output area.

【0013】入力領域上の文字列のポインタをスタック
に格納する処理(S4)では、先に生成した置換文字列
テーブルを参照し、置換文字列名に対応する被置換文字
列の引数と文字列トークンから、引数トークンは対応す
る引数の文字列の先頭ポインタを、文字列トークンは、
定義の引数以外の文字列へのポインタをそれぞれ格納す
る。このときスタックに格納する方法として、先入れ後
出し方式を用いる。
In the process of storing the pointer of the character string on the input area in the stack (S4), the previously generated replacement character string table is referred to, and the argument and character string of the replaced character string corresponding to the replacement character string name. From the token, the argument token is the start pointer of the string of the corresponding argument, and the string token is
Stores pointers to character strings other than the definition arguments. At this time, the first-in first-out method is used as a method of storing in the stack.

【0014】この列の場合、図3に示すように、置換文
字列テーブルは、置換文字列名が「f」で、トークンと
して「引数トークン1(t11)」と「文字列トークン
(t12)」と「引数トークン2(t11)」から構成
されている。トークンの並びが「引数トークン1」、
「文字列トークン」、「引数トークン2」と続いている
ため、スタックにこの順に格納する。このとき、スタッ
クに格納する方法として、先入れ後出し方式を採るの
で、まず「引数トークン2」に対応する文字列のポイン
タ、この場合「200」の先頭ポインタをスタックに格
納する(p13)。次に、文字列トークンに対応する
「△+△」の先頭ポインタをスタックに格納する(p1
4)。さらに、「引数トークン1」に対応する「10
0」の先頭ポインタをスタックに格納する(p15)。
In the case of this column, as shown in FIG. 3, in the replacement character string table, the replacement character string name is "f" and the tokens are "argument token 1 (t11)" and "character string token (t12)". And "argument token 2 (t11)". The sequence of tokens is "argument token 1",
Since "character string token" and "argument token 2" follow, they are stored in this order in the stack. At this time, since the first-in, last-out method is adopted as the method of storing in the stack, first, the pointer of the character string corresponding to "argument token 2", in this case, the leading pointer of "200" is stored in the stack (p13). Next, the top pointer of “Δ + Δ” corresponding to the character string token is stored in the stack (p1
4). Furthermore, "10" corresponding to "argument token 1"
The leading pointer of "0" is stored in the stack (p15).

【0015】次に制御をスタック中のポインタが指す文
字列の複写処理(S5)に移す。スタック中のポインタ
が指す文字列の複写処理(S5)では、スタックを参照
して、スタックに格納されているポインタが指す入力領
域上の文字列および定義の引数以外の文字列を出力領域
へ複写する。この例の場合、図4に示すように、まずス
タックに最後に積まれたポインタ(p15)の指す文字
列「100」を出力領域へ複写する(c16)。さら
に、スタックに2番目に積まれたポインタ(p14)が
指す文字列「△+△」を複写し(c17)、最後にスタ
ックに最初に積まれたポインタ(p13)が指す文字列
「200」を出力領域に複写する(c18)。
Next, the control is transferred to the copy processing (S5) of the character string pointed to by the pointer in the stack. In the copy processing of the character string pointed to by the pointer in the stack (S5), the stack is referenced, and the character string on the input area pointed to by the pointer stored in the stack and the character string other than the defined argument are copied to the output area. To do. In the case of this example, as shown in FIG. 4, first, the character string "100" pointed by the pointer (p15) lastly stacked on the stack is copied to the output area (c16). Further, the character string “Δ + Δ” pointed to by the pointer (p14) secondly stacked on the stack is copied (c17), and the character string “200” finally pointed by the pointer (p13) first stacked on the stack is copied. Is copied to the output area (c18).

【0016】すべての複写を終了すると、制御を再ひ置
換文字列の検索処理(S3)に移す。
When all the copying is completed, the control is transferred to the replacement character string retrieving process (S3).

【0017】置換文字列の検索処理(S3)において、
入力領域上で検索した文字列が置換する必要がない文字
列のとき、そのまま、出力領域へ複写する(S6)。こ
の例の場合、図5に示すように、「if(」は置換する
必要がない文字列なので、そのまま出力領域に複写する
(c19)。
In the replacement character string retrieval process (S3),
When the character string searched in the input area is a character string that does not need to be replaced, it is copied as it is to the output area (S6). In the case of this example, as shown in FIG. 5, since "if (" is a character string that does not need to be replaced, it is directly copied to the output area (c19).

【0018】[0018]

【発明の効果】以上説明したように本発明によれば、文
字列へのポインタをもつスタックを用意し、そのスタッ
ク中のポインタが指す文字列を必要なときに一度だけ複
写するため、従来の方式よりも高速に処理できる効果が
ある。
As described above, according to the present invention, a stack having a pointer to a character string is prepared, and the character string pointed to by the pointer in the stack is copied only once when necessary. It has the effect of processing at a higher speed than the method.

【0019】また、このスタックを用意することによ
り、退避領域が不要であり、スタックの要素は、置換文
字列が存在した場合、そのトークンの数だけしか使用し
ないので、メモリの使用効率が良いという効果がある。
Further, by providing this stack, the save area is unnecessary, and the element of the stack uses only the number of the tokens when the replacement character string exists, so that the memory is efficiently used. effective.

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

【図1】本発明の一実施例を示す処理の流れ図である。FIG. 1 is a flow chart of processing showing an embodiment of the present invention.

【図2】置換文字列テーブルの構成例を示す図である。FIG. 2 is a diagram showing a configuration example of a replacement character string table.

【図3】本発明例における動作説明図である。FIG. 3 is an operation explanatory diagram in the example of the present invention.

【図4】本発明例における動作説明図である。FIG. 4 is an operation explanatory diagram in the example of the present invention.

【図5】本発明例における動作説明図である。FIG. 5 is an operation explanatory diagram in the example of the present invention.

【図6】従来技術の処理の流れ図である。FIG. 6 is a flow chart of processing of a conventional technique.

【図7】従来技術の実施例の動作説明図である。FIG. 7 is an operation explanatory diagram of the example of the related art.

【図8】コンパイラの処理の流れ図である。FIG. 8 is a flowchart of processing of a compiler.

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

S1 置換文字よりテーブルの生成処理 S2 スタックの生成処理 S3 置換文字列の検索処理 S4 スタックへの格納処理 S5 スタックへの参照と出力領域への複写処理 S6 出力領域への複写処理 S20 置換文字列テーブルの生成処理 S21 置換文字列の検索処理 S22 入力領域上の文字列の退避領域への退避処理 S23 置換文字列テーブルの参照と出力領域への複
写処理 S24 退避領域上の文字列の出力領域への複写処理 S25 出力領域への複写処理
S1 Replacement character table generation processing S2 Stack generation processing S3 Replacement character string search processing S4 Stack storage processing S5 Stack reference and output area copy processing S6 Output area copy processing S20 Replacement character string table S21 Replacement character string search processing S22 Character string on input area is saved to save area S23 Replacement character string table is referenced and output area is copied S24 Character string on save area is output to output area Copy process S25 Copy process to output area

Claims (1)

【特許請求の範囲】[Claims] 【請求項1】 入力された文字列中の置換すべき文字列
の置換を行うCコンハイラのプリプロセッサにおける文
字列置換処理方法において、置換する文字列の定義情報
を格納する置換文字列テーブルを備え、前記テーブル中
の置換文字列へのポインタと入力領域上の被置換文字列
の引数へのポインタを要素としてもつスタックを用意
し、前記入力領域上の文字列の置換の有無を判定し、前
記置換が必要でない場合前記入力領域上の文字列を予め
備えた出力領域に出力し、前記置換が必要な場合前記置
換文字列テーブルを参照して前記置換文字列へのポイン
タと前記入力領域上の被置換文字列の引数へのポインタ
を前記スタックに格納し、前記スタック中のポインタが
指す文字列を前記出力領域に複写することを特徴とする
文字列置換処理方法。
1. A character string replacement processing method in a C processor preprocessor for replacing a character string to be replaced in an input character string, comprising a replacement character string table for storing definition information of a character string to be replaced, A stack having, as elements, a pointer to the replacement character string in the table and a pointer to the argument of the replaced character string on the input area is prepared, the presence or absence of replacement of the character string on the input area is determined, and the replacement is performed. If it is not necessary, the character string in the input area is output to the output area provided in advance, and when the replacement is necessary, the replacement character string table is referred to and the pointer to the replacement character string and the object in the input area are referenced. A character string replacement processing method, wherein a pointer to an argument of a replacement character string is stored in the stack, and the character string pointed to by the pointer in the stack is copied to the output area.
JP21383792A 1992-08-11 1992-08-11 Processing method for substituting character string Pending JPH0659902A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP21383792A JPH0659902A (en) 1992-08-11 1992-08-11 Processing method for substituting character string

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP21383792A JPH0659902A (en) 1992-08-11 1992-08-11 Processing method for substituting character string

Publications (1)

Publication Number Publication Date
JPH0659902A true JPH0659902A (en) 1994-03-04

Family

ID=16645852

Family Applications (1)

Application Number Title Priority Date Filing Date
JP21383792A Pending JPH0659902A (en) 1992-08-11 1992-08-11 Processing method for substituting character string

Country Status (1)

Country Link
JP (1) JPH0659902A (en)

Similar Documents

Publication Publication Date Title
JP3178475B2 (en) Data processing device
JP3554459B2 (en) Text data registration search method
JPH03266039A (en) Free format data link processing system
JPH07141201A (en) Improved method for two-path compiler
JPH0659902A (en) Processing method for substituting character string
JP2004199264A (en) Database processing method, apparatus for executing the same, and processing program therefor
JPH05298173A (en) Distributed file synchronizing and updating system
JP2001338004A (en) High-level synthesis system, high-level synthesis method, and computer-readable recording medium storing high-level synthesis method execution program
JP2721377B2 (en) BASIC program compression method
JPH096629A (en) Program conversion method
JPH0667949A (en) File record generation system
JPH02302869A (en) File edition system
JPH05181722A (en) Access method for index organizing file
JPH05334249A (en) Nesting management system for catalog in interactive processing system
JPH04304537A (en) Library file management system
JPH05346847A (en) File provided with input file restoration part and generator for the file
JPH05181656A (en) Symbol information management system
JPH06230951A (en) Program development supporting device
JPH03113651A (en) Garbage correction processing system
JPS63178321A (en) Tree scanning method
JPS63201847A (en) Restoring system for deleted file
JPH02263265A (en) Tabulation processor
JP2000029750A (en) Memory dump file reconstituting system
JPS59119459A (en) Garbage collection system
JPH07210570A (en) Directed graph editing processor

Legal Events

Date Code Title Description
A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 19990907