Difference between revisions of "Basic Pascal Tutorial/Compilers/ja"

From Lazarus wiki
Jump to navigationJump to search
Line 27: Line 27:
 
DOS や Windows ベースの Pascal におけるデファクト・スタンダードはボーランドの Pascal である。それが出てくる前はほとんどの Pascal コンパイラは出来が悪くてのろく、Pascalの標準からは外れており、数百ドルもした。1994年にボーランドがターボ・パスカルを出した。それは100ドル以下で既存のコンパイラより桁違いに速く、豊富なソースコードとユーティリティ・プログラムがついてきた。
 
DOS や Windows ベースの Pascal におけるデファクト・スタンダードはボーランドの Pascal である。それが出てくる前はほとんどの Pascal コンパイラは出来が悪くてのろく、Pascalの標準からは外れており、数百ドルもした。1994年にボーランドがターボ・パスカルを出した。それは100ドル以下で既存のコンパイラより桁違いに速く、豊富なソースコードとユーティリティ・プログラムがついてきた。
  
This product was a great success and was prominent for almost a decade. But in the 1990s, the world was moving to Windows. In 1993, the last version of Turbo Pascal, version 7 for DOS, came out. After that, the demand for DOS programs plummeted and Borland (briefly known as Inprise) focused on producing Windows IDE/compilers (e.g. Delphi). Later, Borland sold its compilers to Embarcadero, who still regularly update Delphi.
+
この製品はすばらしい成功をおさめ、ほぼ10年間突出していた。 しかし、1990年代になって、世界はウインドウに移行した。1993年にターボ・パスカルの最終バージョンであるバージョン7 for DOS が出た。その後、DOS プログラムに対する需要は急激に落ち込み、ボーランド(短期間、Inpriseとして知られていた)はウインドウ用のIDE/コンパイラ(すなわち、Delphi)に注力した。後にボーランドはそのコンパイラを Embarcadero に売却し、 Embarcadero は今なお定期的に Delphi をバージョンアップさせている。
  
This tutorial will only deal with console-based programming, where the computer prints lines of data to the screen and the user interacts with the program using a keyboard. The goal of the tutorial is to teach how to program in Pascal. Once you've learned that, you can easily look at a reference book or another web page and pick up graphics and windowing systems on your own.
+
このチュートリアルではコンソールベースのプログラミングのみを扱う。従って、コンピュータはデータの行をディスプレイに表示し、ユーザーはキーボードを通してコンピュータとやりとりする。このチュートリアルの目標は Pascal でいかにプログラムするかを教えることである。いったん、それを学びさえすれば参考文献やウェブページを見て自らのコンピュータでグラフィックシステムとウインドウシステムを簡単に習得できる。
  
 
Although old commercial Pascal compilers are often available for download (e.g. Turbo Pascal 5.5 from the Borland Museum and Symantec Think Pascal (Macintosh), see The Free Country's Free Pascal Compiler List), computers have progressed much since the 1980s and early 1990s. We are no longer stuck with 8.3 filenames on DOS or non-preemptive multitasking on Mac OS. Using an old compiler is fun in the same sense as playing an old game on an emulator is fun, but the open source movement has produced good compilers for modern operating systems, and a beginner will find it much easier to use those.
 
Although old commercial Pascal compilers are often available for download (e.g. Turbo Pascal 5.5 from the Borland Museum and Symantec Think Pascal (Macintosh), see The Free Country's Free Pascal Compiler List), computers have progressed much since the 1980s and early 1990s. We are no longer stuck with 8.3 filenames on DOS or non-preemptive multitasking on Mac OS. Using an old compiler is fun in the same sense as playing an old game on an emulator is fun, but the open source movement has produced good compilers for modern operating systems, and a beginner will find it much easier to use those.

Revision as of 19:22, 23 June 2015

български (bg) Deutsch (de) English (en) español (es) français (fr) italiano (it) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

Pascal コンパイラ (原著者: Tao Yue, 修正あり)

この文書ではコンパイラの基本を説明すると同時によく知られている Pascal コンパイラへのリンクを提供し、Free Pascal のセットアップの仕方を解説する。

コンピュータ言語とコンパイラについて

コンピュータ言語について語るとき、基本的に使われることになる3つの主要な用語がある。

   機械語 -- コンピュータのCPUに基本的な指示を与える実際のバイナリコード。 たいていは、2つの数字を足すとかデータをあるメモリー位置から別の位置に移動するといったとても単純なコマンドである。
   アセンブリ言語 -- バイナリ数の文字列を記憶することなく、直接コンピュータに人間がプログラムする方法。マシン語のコードと一対一の対応がある。たとえば、インテルの x86 マシン語では、 ADD と MOV は加算の操作と移動の操作の簡略記号である。
   高級言語 -- 人間が一つずつ進める必要なく、複雑なプログラムを書くことを可能にする。高級言語には Pascal, C, C++, FORTRAN, Java, Visual Basic, C#, Java, など他にも多数が含まれる。 高級言語における一つのコマンド、たとえばある文字列をファイルに書き込むなどは何十、あるいは何百と言うことさえあるかもしれない機械語の指示に変換される。 

マイクロプロセッサが直接に実行できるのは機械語だけである。アセンブリ言語はアセンブルされるか、機械語に変換される。Pascalのような高級言語で書かれたプログラムも実行される前に機械語に変換されなくてはならない。

変換を実行するプログラムはコンパイラと呼ばれる。このプログラムは複数のコード行から機械語を作り出すだけではなく、コードがより速く走るように最適化し、エラーに対応するコードを書き加え、他の場所に蓄えられているサブルーチンとリンクを行うのでかなり複雑である。たとえば、コンピュータに何かをディスプレイ画面に表示せよと伝えたとすると、コンパイラはこれをあらかじめ書かれていたモジュールへの呼び出しだと翻訳する。それから、あなたのコードは実行可能なプログラムが結果を生み出す前に、コンパイラの製作者が提供したコードとリンクされなくてはならない。

高級言語では覚えておくべき3つの基本用語がここでもある。

   ソースコード -- あなたが書いたコードのこと。これは普通、用いられた言語を示す拡張子がつけられる。たとえば、Pascal のソースコードはたいてい「.pas」で終わるし、 C++ のコードは「.cpp」で終わる。
   オブジェクト・コード -- コンパイルした結果である。 オブジェクト・コードは普通、プログラムのあるモジュールだけを含み、不完全なのでまだ走らせることができない。 DOS/Windows システムでは、これはたいてい「.obj」という拡張子になっている。
   実行コード -- 最終的な結果である。機能するためのプログラムに必要なオブジェク・トコード・モジュールはすべて一緒にリンクされる。 DOS/Windowsシステムでは通常、これは「.exe」という拡張子を持つ。 

コンパイラについての補足

DOS や Windows ベースの Pascal におけるデファクト・スタンダードはボーランドの Pascal である。それが出てくる前はほとんどの Pascal コンパイラは出来が悪くてのろく、Pascalの標準からは外れており、数百ドルもした。1994年にボーランドがターボ・パスカルを出した。それは100ドル以下で既存のコンパイラより桁違いに速く、豊富なソースコードとユーティリティ・プログラムがついてきた。

この製品はすばらしい成功をおさめ、ほぼ10年間突出していた。 しかし、1990年代になって、世界はウインドウに移行した。1993年にターボ・パスカルの最終バージョンであるバージョン7 for DOS が出た。その後、DOS プログラムに対する需要は急激に落ち込み、ボーランド(短期間、Inpriseとして知られていた)はウインドウ用のIDE/コンパイラ(すなわち、Delphi)に注力した。後にボーランドはそのコンパイラを Embarcadero に売却し、 Embarcadero は今なお定期的に Delphi をバージョンアップさせている。

このチュートリアルではコンソールベースのプログラミングのみを扱う。従って、コンピュータはデータの行をディスプレイに表示し、ユーザーはキーボードを通してコンピュータとやりとりする。このチュートリアルの目標は Pascal でいかにプログラムするかを教えることである。いったん、それを学びさえすれば参考文献やウェブページを見て自らのコンピュータでグラフィックシステムとウインドウシステムを簡単に習得できる。

Although old commercial Pascal compilers are often available for download (e.g. Turbo Pascal 5.5 from the Borland Museum and Symantec Think Pascal (Macintosh), see The Free Country's Free Pascal Compiler List), computers have progressed much since the 1980s and early 1990s. We are no longer stuck with 8.3 filenames on DOS or non-preemptive multitasking on Mac OS. Using an old compiler is fun in the same sense as playing an old game on an emulator is fun, but the open source movement has produced good compilers for modern operating systems, and a beginner will find it much easier to use those. [edit] Open Source Compilers

The two main open-source compiler projects are:

   GNU Pascal
   Free Pascal 

Free Pascal is generally considered friendlier for novices, and strives to emulate Borland Pascal in many ways, though both will serve fine for learning Pascal.

As most users of this tutorial will be running Windows, here's how to set up Free Pascal and get to the point where you're compiling a program on a modern Windows operating system:

   Download the Win32 installer for Free Pascal from the Free Pascal download page.
   Run the file you just downloaded and go through the wizard to setup Free Pascal.
   Open Free Pascal using the shortcut (by default it is located in Start -> Free Pascal.
   Type in a program (flip to the next lesson to get a "Hello, world." program).
   Save the file with File-Save As ...
   Run the program from the Run menu. This will automatically compile the program if you've made any changes, then run the program. It will also run the program without compiling if you've not made any changes since the last time you compiled. 

With programs that don't expect user input, you'll see the program flash on a black screen. But the program completes in the blink of an eye and you are returned to the IDE without seeing the results of your work. There are two ways around this:

   Select User screen from the Debug menu to see the results of the program.
   Add a readln statement at the end of every program. This will make the program wait for the user to press the Enter key before the program ends and returns to the IDE. 

Userscreen.png

Note that an .exe file was created in the directory where you saved your program. This is the executable. You can go to the Command Prompt, change to the directory, and run this executable straight. You can also double-click on it in Windows Explorer (and it will still flash by quickly if it ends without requiring user input).