1 / 12

情報科学1( G1) #10

情報科学1( G1) #10. テキスト編集のプログラミング エディタ プログラムの作成 繰り返し While 文. エディタ. コンピュータ との対話 Computer : Command: User : i ( 文字列を挿入せよ) Computer : Insert What? User : abcdaefgh Computer : *abcdaefgh (ポインタの位置を*で表す) Computer : Command: User : p ( ポインタの位置を合わせよ)

Download Presentation

情報科学1( G1) #10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 情報科学1(G1)#10 • テキスト編集のプログラミング • エディタ プログラムの作成 • 繰り返し • While 文

  2. エディタ コンピュータとの対話 Computer : Command: User : i (文字列を挿入せよ) Computer : Insert What? User : abcdaefgh Computer : *abcdaefgh (ポインタの位置を*で表す) Computer : Command: User : p (ポインタの位置を合わせよ) Computer : Point to What? User : aef Computer : abcd*aefgh

  3. ポインタ:変更が行なわれる位置を示す目印 2番目のaにポインタをあわせる. abcdaefgh | ポインタの直前に'bbb'を挿入する. abcdbbbaefgh | ポインタの場所から4文字を削除する. abcdefgh |

  4. 必要なコマンド • 挿入i(insert) • ポインタの移動p (point) • 削除d (delete) • など..

  5. エディタプログラムの作成 • 単語'Command:'を出力する. • ユーザのコマンドを入力する. • もしコマンドが 'i' ならば,挿入を実行する. • もしコマンドが 'p' ならば,ポインタの移動を実行する. • もしコマンドが.... (以下省略)

  6. エディタプログラムの作成 writeln('Command:'); readln(command); if command = 'i' then begin 挿入を実行する end; if command = 'p' then begin ポインタの移動を実行す end;

  7. 繰り返し while文 • while条件 do文 • (「条件」が成立する時,「文」を実行)を繰り返し行なう. • 成立しない場合は,次の文へ

  8. program RepetitionA; begin while true do begin writeln('Begin the loop.'); writeln('Here is some more'); end; end. Begin the loop. Here is some more を延々と出力するプログラム. 「条件」 true:常に成立する.(つまり止まらない) 止める場合:CTL+C

  9. i = 0 i = 1 i = 2 . . . . と9まで出力するプログラム. program RepetitionB; var i :integer; begin i := 0; while i < 10 do begin writeln('i = ',i); i := i+1; end; end.

  10. エディタプログラムの作成 繰り返しコマンドを受け付けるようにする. 0.‘Enter Editor.’と出力する. 1.単語‘Command:’を出力する. 2.ユーザのコマンドを入力する. 3.もしコマンドが ‘q‘ ならエディタを終了する. 4.もしコマンドが ‘i’ ならば,挿入を実行する. 5.もしコマンドが ‘p’ ならば,ポインタの移動を実行する. 6.もしコマンドが.... (以下省略) ……… N. 1.へもどる.

  11. エディタプログラムの作成 writeln('Enter Editor.'); text := ''; ptr := 0; command := ''; while command <>'q' do begin writeln('Command:'); readln(command); if command = 'i' then begin 挿入を実行する end; ....... end; writeln('Exit Editor');

  12. エディタプログラムの作成 writeln('Enter Editor.'); text := ''; ptr := 0; command := ''; while command <>'q' do begin writeln('Command:'); readln(command); if command = 'i' then begin 挿入を実行する end; ....... end; writeln('Exit Editor'); textの初期値は長さ0の文字列 pointerの初期値は文字列の先頭 commandの初期値は長さ0の文字列

More Related