summaryrefslogtreecommitdiffstats
path: root/Doc/ref8.tex
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-08-14 09:17:29 (GMT)
committerGuido van Rossum <guido@python.org>1992-08-14 09:17:29 (GMT)
commitda43a4ab88608b59d5025161db39af841889bb99 (patch)
treeaec44ebe27879c10e645d2aa6cca53333d721503 /Doc/ref8.tex
parent46f3e00407d614e0a1003379197c75e1b835e629 (diff)
downloadcpython-da43a4ab88608b59d5025161db39af841889bb99.zip
cpython-da43a4ab88608b59d5025161db39af841889bb99.tar.gz
cpython-da43a4ab88608b59d5025161db39af841889bb99.tar.bz2
Initial revision
Diffstat (limited to 'Doc/ref8.tex')
-rw-r--r--Doc/ref8.tex108
1 files changed, 108 insertions, 0 deletions
diff --git a/Doc/ref8.tex b/Doc/ref8.tex
new file mode 100644
index 0000000..59ef58c
--- /dev/null
+++ b/Doc/ref8.tex
@@ -0,0 +1,108 @@
+\chapter{Top-level components}
+
+The Python interpreter can get its input from a number of sources:
+from a script passed to it as standard input or as program argument,
+typed in interactively, from a module source file, etc. This chapter
+gives the syntax used in these cases.
+\index{interpreter}
+
+\section{Complete Python programs}
+\index{program}
+
+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 \verb\sys\
+(various system services), \verb\builtin\ (built-in functions,
+exceptions and \verb\None\) and \verb\__main__\. The latter is used
+to provide the local and global name space for execution of the
+complete program.
+\bimodindex{sys}
+\bimodindex{__main__}
+\bimodindex{builtin}
+
+The syntax for a complete Python program is that for file input,
+described in the next section.
+
+The interpreter may also be invoked in interactive mode; in this case,
+it does not read and execute a complete program but reads and executes
+one statement (possibly compound) at a time. The initial environment
+is identical to that of a complete program; each statement is executed
+in the name space of \verb\__main__\.
+\index{interactive mode}
+
+Under {\UNIX}, a complete program can be passed to the interpreter in
+three forms: with the {\bf -c} {\it 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.
+\index{UNIX}
+\index{command line}
+\index{standard input}
+
+\section{File input}
+
+All input read from non-interactive files has the same form:
+
+\begin{verbatim}
+file_input: (NEWLINE | statement)*
+\end{verbatim}
+
+This syntax is used in the following situations:
+
+\begin{itemize}
+
+\item when parsing a complete Python program (from a file or from a string);
+
+\item when parsing a module;
+
+\item when parsing a string passed to \verb\exec()\;
+\bifuncindex{exec}
+
+\item when parsing a file passed to \verb\execfile()\;
+\bifuncindex{execfile}
+
+\end{itemize}
+
+\section{Interactive input}
+
+Input in interactive mode is parsed using the following grammar:
+
+\begin{verbatim}
+interactive_input: [stmt_list] NEWLINE | compound_stmt NEWLINE
+\end{verbatim}
+
+Note that a (top-level) compound statement must be followed by a blank
+line in interactive mode; this is needed to help the parser detect the
+end of the input.
+
+\section{Expression input}
+\index{input}
+
+There are two forms of expression input. Both ignore leading
+whitespace.
+
+The string argument to \verb\eval()\ must have the following form:
+\bifuncindex{eval}
+
+\begin{verbatim}
+eval_input: condition_list NEWLINE*
+\end{verbatim}
+
+The input line read by \verb\input()\ must have the following form:
+\bifuncindex{input}
+
+\begin{verbatim}
+input_input: condition_list NEWLINE
+\end{verbatim}
+
+Note: to read `raw' input line without interpretation, you can use the
+built-in function \verb\raw_input()\ or the \verb\readline()\ method
+of file objects.
+\obindex{file}
+\index{input!raw}
+\index{raw input}
+\bifuncindex{raw_index}
+\ttindex{readline}