Difference between revisions of "Basic Pascal Tutorial/Chapter 1/Program Structure/ja"

From Free Pascal wiki
Jump to navigationJump to search
Line 40: Line 40:
 
Turbo Pascal とほとんどの他の現代のコンパイラは {コメント} のような自由形式のカッコのコメント文をサポートしている。左の中カッコはコメントの最初を意味し、終わりの中カッコはコメント終わりを意味する。中カッコはまたコンパイラへの指示のためにも使われる。
 
Turbo Pascal とほとんどの他の現代のコンパイラは {コメント} のような自由形式のカッコのコメント文をサポートしている。左の中カッコはコメントの最初を意味し、終わりの中カッコはコメント終わりを意味する。中カッコはまたコンパイラへの指示のためにも使われる。
  
Commenting makes your code easier to understand. If you write your code without comments, you may come back to it weeks, months, or years later without a guide to why you coded the program that way. In particular, you may want to document the major design of your program and insert comments in your code when you deviate from that design for a good reason.
+
コメントをつけるとコードは理解しやすくなる。もし、コメントなしにコードを書いたなら、数週間後か数ヶ月後、あるいは数年後になぜそのようなやり方でコードを書いたのかわからないまま、それに戻ってくる羽目になるかもしれない。特に、プログラムの大きなデザインを文書化したい場合、そして何らかの理由でそのデザインから逸脱する場合にはコードにコメントを入れたいと望むことになるだろう。
  
 
In addition, comments are often used to take problematic code out of action without deleting it. Remember the earlier restriction on nesting comments? It just so happens that braces {} take precedence over parentheses-stars (* *). You will not get an error if you do this:
 
In addition, comments are often used to take problematic code out of action without deleting it. Remember the earlier restriction on nesting comments? It just so happens that braces {} take precedence over parentheses-stars (* *). You will not get an error if you do this:

Revision as of 19:51, 7 July 2015

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

基礎1A - プログラム構造 (著者: Tao Yue, 状態: 修正あり)

Pascal プログラムの基本的な構造は以下の通りである。

PROGRAM プログラム名 (ファイルリスト);

CONST

 (* 定数宣言 *)

TYPE

 (* タイプの宣言 *)

VAR

 (* 変数の宣言 *)

(* サブプログラムの定義 *)

BEGIN

 (* 実行文 *)

END.

The PROGRAM 文は Free Pascal ではオプションである。

必要がなければ省略できるものもあるが、プログラムの要素は正しい順序でなくてはならない。ここには何も実行しないが、必要とされるすべての要素を持つプログラムを示している。

program DoNothing; begin end.

コメント文はコンパイルも実行もされないコードのことである。Free Pascal は2種類のタイプのコメント文をサポートしている。自由形式と行ベースである。Free-form のコメント文は「(*」で始まり、「*)」で終わるか、もっと一般的なのは「{」で始まり、「}」で終わる。コメント文は以下に示すような入れ子にはできない。

       (* (* *) *)

これはエラーになる。なぜならコンパイラはまず「(*」と最初の「*)」を認識し、最初のコメント文の間にある2番目の「(*」を無視してしまうからである。2番目の「*)」はそれと対応する「(*」にマッチしないままになってしまう。このような begin-end のコメントの問題点は多くの言語が行ベースのコメントシステムを用いる理由である。

Free Pascal は行ベースのコメント文として「//」も採用している。2つのスラッシュが現れたら、引用文字列や自由形式コメント文の中にある時以外は、行の残りは無視される。

Turbo Pascal とほとんどの他の現代のコンパイラは {コメント} のような自由形式のカッコのコメント文をサポートしている。左の中カッコはコメントの最初を意味し、終わりの中カッコはコメント終わりを意味する。中カッコはまたコンパイラへの指示のためにも使われる。

コメントをつけるとコードは理解しやすくなる。もし、コメントなしにコードを書いたなら、数週間後か数ヶ月後、あるいは数年後になぜそのようなやり方でコードを書いたのかわからないまま、それに戻ってくる羽目になるかもしれない。特に、プログラムの大きなデザインを文書化したい場合、そして何らかの理由でそのデザインから逸脱する場合にはコードにコメントを入れたいと望むことになるだろう。

In addition, comments are often used to take problematic code out of action without deleting it. Remember the earlier restriction on nesting comments? It just so happens that braces {} take precedence over parentheses-stars (* *). You will not get an error if you do this:

{ (* Comment *) }

Whitespace (spaces, tabs, and end-of-lines) are ignored by the Pascal compiler unless they are inside a literal string. However, to make your program readable by human beings, you should indent your statements and put separate statements on separate lines. Indentation is often an expression of individuality by programmers, but collaborative projects usually select one common style to allow everyone to work from the same page.