@@ -416,11 +416,10 @@ \subsection{Numeric literals}
416416the letter `l' looks too much like the digit `1'.
417417
418418Plain integer decimal literals must be at most $ 2 ^{31} - 1 $ (i.e., the
419- largest positive integer, assuming 32-bit arithmetic); plain octal and
419+ largest positive integer, assuming 32-bit arithmetic). Plain octal and
420420hexadecimal literals may be as large as $ 2 ^{32} - 1 $ , but values
421- larger than $ 2 ^{31} - 1 $ are converted to a signed value in the range
422- $ -2 ^{31} \dots 2 ^{31} - 1 $ by subtracting $ 2 ^{32}$ . There is no limit
423- for long integer literals.
421+ larger than $ 2 ^{31} - 1 $ are converted to a negative value by
422+ subtracting $ 2 ^{32}$ . There is no limit for long integer literals.
424423
425424Some examples of plain and long integer literals:
426425
@@ -571,7 +570,7 @@ \section{The standard type hierarchy}
571570Below is a list of the types that are built into Python. Extension
572571modules written in C can define additional types. Future versions of
573572Python may add types to the type hierarchy (e.g., rational or complex
574- numbers, efficientlt stored arrays of integers, etc.).
573+ numbers, efficiently stored arrays of integers, etc.).
575574\index {type}
576575\index {type hierarchy}
577576\index {extension module}
@@ -1619,8 +1618,9 @@ \section{Comparisons}
16191618comparison of their sorted (key, value) lists.%
16201619\footnote {This is expensive since it requires sorting the keys first,
16211620but about the only sensible definition. It was tried to compare
1622- dictionaries using the rule below for most other types, but this gave
1623- surprises in cases like \verb |if d == {}: ... |.}
1621+ dictionaries by identity only, but this caused surprises because
1622+ people expected to be able to test a dictionary for emptiness by
1623+ comparing it to {\tt \{\} }.}
16241624
16251625\item
16261626Most other types compare unequal unless they are the same object;
@@ -2313,10 +2313,94 @@ \section{Class definitions} \label{class}
23132313
23142314\section {P.M. }
23152315
2316- XXX Syntax for scripts, modules
2317- XXX Syntax for interactive input, eval, exec, execfile, input
23182316XXX New definition of expressions (as conditions)
23192317
2318+ \chapter {Top-level components }
2319+
2320+ The Python interpreter can get its input from a number of sources:
2321+ from a script passed to it as standard input or as program argument,
2322+ typed in interactively, from a module source file, etc. This chapter
2323+ gives the syntax used in these cases.
2324+
2325+ \section {Complete Python programs }
2326+
2327+ While a language specification need not prescribe how the language
2328+ interpreter is invoked, it is useful to have a notion of a complete
2329+ Python program. A complete Python program is executed in a minimally
2330+ initialized environment: all built-in and standard modules are
2331+ available, but none have been initialized, except for \verb \sys \
2332+ (various system services), \verb \builtin \ (built-in functions,
2333+ exceptions and \verb \None \) and \verb \__main__ \. The latter is used
2334+ to provide the local and global name space for execution of the
2335+ complete program.
2336+
2337+ The syntax for a complete Python program is that for file input,
2338+ described in the next section.
2339+
2340+ The interpreter may also be invoked in interactive mode; in this case,
2341+ it does not read and execute a complete program but reads and executes
2342+ one statement (possibly compound) at a time. The initial environment
2343+ is identical to that of a complete program; each statement is executed
2344+ in the name space of \verb \__main__ \.
2345+
2346+ Under {\UNIX }, a complete program can be passed to the interpreter in
2347+ three forms: with the {\bf -c} {\it string} command line option, as a
2348+ file passed as the first command line argument, or as standard input.
2349+ If the file or standard input is a tty device, the interpreter enters
2350+ interactive mode; otherwise, it executes the file as a complete
2351+ program.
2352+
2353+ \section {File input }
2354+
2355+ All input read from non-interactive files has the same form:
2356+
2357+ \begin {verbatim }
2358+ file_input: (NEWLINE | statement)*
2359+ \end {verbatim }
2360+
2361+ This syntax is used in the following situations:
2362+
2363+ \begin {itemize }
2364+
2365+ \item when parsing a complete Python program (from a file or from a string);
2366+
2367+ \item when parsing a module;
2368+
2369+ \item when parsing a string passed to \verb \exec() \;
2370+
2371+ \item when parsing a file passed to \verb \execfile() \;
2372+
2373+ \end {itemize }
2374+
2375+ \section {Interactive input }
2376+
2377+ Input in interactive mode is parsed using the following grammar:
2378+
2379+ \begin {verbatim }
2380+ interactive_input: [stmt_list] NEWLINE | compound_stmt NEWLINE
2381+ \end {verbatim }
2382+
2383+ Note that a (top-level) compound statement must be followed by a blank
2384+ line in interactive mode; this is needed to help the parser detect the
2385+ end of the input.
2386+
2387+ \section {Expression input }
2388+
2389+ There are two forms of expression input. Both ignore leading
2390+ whitespace.
2391+
2392+ The string argument to \verb \eval() \ must have the following form:
2393+
2394+ \begin {verbatim }
2395+ eval_input: condition_list NEWLINE*
2396+ \end {verbatim }
2397+
2398+ The input line read by \verb \input() \ must have the following form:
2399+
2400+ \begin {verbatim }
2401+ input_input: condition_list NEWLINE
2402+ \end {verbatim }
2403+
23202404\input {ref.ind } % The index
23212405
23222406\end {document }
0 commit comments