トップレベル要素
****************

Python インタプリタは、標準入力や、プログラムの引数として与えられたス
クリプト、対話的にタイプ入力された命令、モジュールのソースファイルなど
、様々な入力源から入力を得ることができます。この章では、それぞれの場合
に用いられる構文法について説明しています。


完全な Python プログラム
========================

While a language specification need not prescribe how the language
interpreter is invoked, it is useful to have a notion of a complete
Python program.  A complete Python program is executed in a minimally
initialized environment: all built-in and standard modules are
available, but none have been initialized, except for "sys" (various
system services), "__builtin__" (built-in functions, exceptions and
"None") and "__main__".  The latter is used to provide the local and
global namespace for execution of the complete program.

完全な Python プログラムの構文は、下の節で述べるファイル入力のためのも
のです。

インタプリタは、対話的モード (interactive mode) で起動されることもあり
ます; この場合、インタプリタは完全なプログラムを読んで実行するのではな
く、一度に単一の実行文 (複合文のときもあります) を読み込んで実行します
。初期状態の環境は、完全なプログラムを実行するときの環境と同じです; 各
実行文は、 "__main__" の名前空間内で実行されます。

Under Unix, a complete program can be passed to the interpreter in
three forms: with the "-c" *string* command line option, as a file
passed as the first command line argument, or as standard input. If
the file or standard input is a tty device, the interpreter enters
interactive mode; otherwise, it executes the file as a complete
program.


ファイル入力
============

非対話的なファイルから読み出された入力は、全て同じ形式:

   file_input ::= (NEWLINE | statement)*

をとります。この構文法は、以下の状況で用いられます:

* (ファイルや文字列内の) 完全な Python プログラムを構文解析するとき;

* モジュールを構文解析するとき;

* when parsing a string passed to the "exec" statement;


対話的入力
==========

対話モードでの入力は、以下の文法の下に構文解析されます:

   interactive_input ::= [stmt_list] NEWLINE | compound_stmt NEWLINE

対話モードでは、(トップレベルの) 複合文の最後に空白行を入れなくてはな
らないことに注意してください; これは、複合文の終端をパーザが検出するた
めの手がかりとして必要です。


式入力
======

There are two forms of expression input.  Both ignore leading
whitespace. The string argument to "eval()" must have the following
form:

   eval_input ::= expression_list NEWLINE*

The input line read by "input()" must have the following form:

   input_input ::= expression_list NEWLINE

Note: to read 『raw』 input line without interpretation, you can use
the built-in function "raw_input()" or the "readline()" method of file
objects.
