Commit a1cce714 authored by Fred Drake's avatar Fred Drake

Converted some {tabular}s to use {tablei*} environments.

parent 30e52653
\chapter{Lexical analysis} \chapter{Lexical analysis\label{lexical}}
A Python program is read by a \emph{parser}. Input to the parser is a A Python program is read by a \emph{parser}. Input to the parser is a
stream of \emph{tokens}, generated by the \emph{lexical analyzer}. This stream of \emph{tokens}, generated by the \emph{lexical analyzer}. This
...@@ -33,7 +33,7 @@ set. ...@@ -33,7 +33,7 @@ set.
A Python program is divided into a number of \emph{logical lines}. A Python program is divided into a number of \emph{logical lines}.
\index{line structure} \index{line structure}
\subsection{Logical Lines} \subsection{Logical lines}
The end of The end of
a logical line is represented by the token NEWLINE. Statements cannot a logical line is represented by the token NEWLINE. Statements cannot
...@@ -259,17 +259,11 @@ def finally in print ...@@ -259,17 +259,11 @@ def finally in print
Certain classes of identifiers (besides keywords) have special Certain classes of identifiers (besides keywords) have special
meanings. These are: meanings. These are:
\begin{center} \begin{tableii}{l|l}{code}{Form}{Meaning}
\begin{tabular}{|l|l|} \lineii{_*}{Not imported by \samp{from \var{module} import *}}
\hline \lineii{__*__}{System-defined name}
Form & Meaning \\ \lineii{__*}{Class-private name mangling}
\hline \end{tableii}
\code{_*} & Not imported by \code{from \var{module} import *} \\
\code{__*__} & System-defined name \\
\code{__*} & Class-private name mangling \\
\hline
\end{tabular}
\end{center}
(XXX need section references here.) (XXX need section references here.)
...@@ -322,27 +316,21 @@ to those used by Standard \C{}. The recognized escape sequences are: ...@@ -322,27 +316,21 @@ to those used by Standard \C{}. The recognized escape sequences are:
\index{Standard C} \index{Standard C}
\index{C} \index{C}
\begin{center} \begin{tableii}{l|l}{code}{Escape Sequence}{Meaning}
\begin{tabular}{|l|l|} \lineii{\e\var{newline}} {Ignored}
\hline \lineii{\e\e} {Backslash (\code{\e})}
Escape Sequence & Meaning \\ \lineii{\e'} {Single quote (\code{'})}
\hline \lineii{\e"} {Double quote (\code{"})}
\code{\e}\emph{newline} & Ignored \\ \lineii{\e a} {\ASCII{} Bell (BEL)}
\code{\e\e} & Backslash (\code{\e}) \\ \lineii{\e b} {\ASCII{} Backspace (BS)}
\code{\e'} & Single quote (\code{'}) \\ \lineii{\e f} {\ASCII{} Formfeed (FF)}
\code{\e"} & Double quote (\code{"}) \\ \lineii{\e n} {\ASCII{} Linefeed (LF)}
\code{\e a} & \ASCII{} Bell (BEL) \\ \lineii{\e r} {\ASCII{} Carriage Return (CR)}
\code{\e b} & \ASCII{} Backspace (BS) \\ \lineii{\e t} {\ASCII{} Horizontal Tab (TAB)}
\code{\e f} & \ASCII{} Formfeed (FF) \\ \lineii{\e v} {\ASCII{} Vertical Tab (VT)}
\code{\e n} & \ASCII{} Linefeed (LF) \\ \lineii{\e\var{ooo}} {\ASCII{} character with octal value \emph{ooo}}
\code{\e r} & \ASCII{} Carriage Return (CR) \\ \lineii{\e x\var{hh...}} {\ASCII{} character with hex value \emph{hh...}}
\code{\e t} & \ASCII{} Horizontal Tab (TAB) \\ \end{tableii}
\code{\e v} & \ASCII{} Vertical Tab (VT) \\
\code{\e}\emph{ooo} & \ASCII{} character with octal value \emph{ooo} \\
\code{\e x}\emph{hh...} & \ASCII{} character with hex value \emph{hh...} \\
\hline
\end{tabular}
\end{center}
\index{ASCII@\ASCII{}} \index{ASCII@\ASCII{}}
In strict compatibility with Standard \C, up to three octal digits are In strict compatibility with Standard \C, up to three octal digits are
......
\chapter{Execution model} \chapter{Execution model\label{execmodel}}
\index{execution model} \index{execution model}
\section{Code blocks, execution frames, and namespaces} \label{execframes} \section{Code blocks, execution frames, and namespaces} \label{execframes}
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
\indexii{execution}{frame} \indexii{execution}{frame}
\index{namespace} \index{namespace}
A {\em code block} is a piece of Python program text that can be A \dfn{code block} is a piece of Python program text that can be
executed as a unit, such as a module, a class definition or a function executed as a unit, such as a module, a class definition or a function
body. Some code blocks (like modules) are normally executed only once, others body. Some code blocks (like modules) are normally executed only once, others
(like function bodies) may be executed many times. Code blocks may (like function bodies) may be executed many times. Code blocks may
...@@ -29,7 +29,7 @@ passed to the built-in function \function{eval()} and to the ...@@ -29,7 +29,7 @@ passed to the built-in function \function{eval()} and to the
read and evaluated by the built-in function \function{input()} is a read and evaluated by the built-in function \function{input()} is a
code block. code block.
A code block is executed in an execution frame. An {\em execution A code block is executed in an execution frame. An \dfn{execution
frame} contains some administrative information (used for debugging), frame} contains some administrative information (used for debugging),
determines where and how execution continues after the code block's determines where and how execution continues after the code block's
execution has completed, and (perhaps most importantly) defines two execution has completed, and (perhaps most importantly) defines two
...@@ -37,11 +37,11 @@ namespaces, the local and the global namespace, that affect ...@@ -37,11 +37,11 @@ namespaces, the local and the global namespace, that affect
execution of the code block. execution of the code block.
\indexii{execution}{frame} \indexii{execution}{frame}
A {\em namespace} is a mapping from names (identifiers) to objects. A \dfn{namespace} is a mapping from names (identifiers) to objects.
A particular namespace may be referenced by more than one execution A particular namespace may be referenced by more than one execution
frame, and from other places as well. Adding a name to a namespace frame, and from other places as well. Adding a name to a namespace
is called {\em binding} a name (to an object); changing the mapping of is called \dfn{binding} a name (to an object); changing the mapping of
a name is called {\em rebinding}; removing a name is {\em unbinding}. a name is called \dfn{rebinding}; removing a name is \dfn{unbinding}.
Namespaces are functionally equivalent to dictionaries (and often Namespaces are functionally equivalent to dictionaries (and often
implemented as dictionaries). implemented as dictionaries).
\index{namespace} \index{namespace}
...@@ -49,8 +49,8 @@ implemented as dictionaries). ...@@ -49,8 +49,8 @@ implemented as dictionaries).
\indexii{rebinding}{name} \indexii{rebinding}{name}
\indexii{unbinding}{name} \indexii{unbinding}{name}
The {\em local namespace} of an execution frame determines the default The \dfn{local namespace} of an execution frame determines the default
place where names are defined and searched. The {\em global place where names are defined and searched. The \dfn{global
namespace} determines the place where names listed in \keyword{global} namespace} determines the place where names listed in \keyword{global}
statements are defined and searched, and where names that are not statements are defined and searched, and where names that are not
bound anywhere in the current code block are searched. bound anywhere in the current code block are searched.
...@@ -105,36 +105,43 @@ imported (i.e., when it is loaded). Note that in almost all cases, ...@@ -105,36 +105,43 @@ imported (i.e., when it is loaded). Note that in almost all cases,
the global namespace is the namespace of the containing module --- the global namespace is the namespace of the containing module ---
scopes in Python do not nest! scopes in Python do not nest!
\begin{center} \begin{tableiv}{l|l|l|l}{textrm}%
\begin{tabular}{|l|l|l|l|} {Code block type}{Global namespace}{Local namespace}{Notes}
\hline \lineiv{Module}%
Code block type & Global namespace & Local namespace & Notes \\ {n.s. for this module}%
\hline {same as global}{}
Module & n.s. for this module & same as global & \\ \lineiv{Script (file or command)}%
Script (file or command) & n.s. for \module{__main__} & same as global {n.s. for \module{__main__}}%
& (1) \\ {same as global}{(1)}
Interactive command & n.s. for \module{__main__} & same as global & \\ \lineiv{Interactive command}%
Class definition & global n.s. of containing block & new n.s. & \\ {n.s. for \module{__main__}}%
Function body & global n.s. of containing block & new n.s. & (2) \\ {same as global}{}
String passed to \keyword{exec} statement \lineiv{Class definition}%
& global n.s. of containing block {global n.s. of containing block}%
& local n.s. of containing block & (2), (3) \\ {new n.s.}{}
String passed to \function{eval()} \lineiv{Function body}%
& global n.s. of caller & local n.s. of caller & (2), (3) \\ {global n.s. of containing block}%
File read by \function{execfile()} {new n.s.}{(2)}
& global n.s. of caller & local n.s. of caller & (2), (3) \\ \lineiv{String passed to \keyword{exec} statement}%
Expression read by \function{input()} {global n.s. of containing block}%
& global n.s. of caller & local n.s. of caller & \\ {local n.s. of containing block}{(2), (3)}
\hline \lineiv{String passed to \function{eval()}}%
\end{tabular} {global n.s. of caller}%
\end{center} {local n.s. of caller}{(2), (3)}
\lineiv{File read by \function{execfile()}}%
{global n.s. of caller}%
{local n.s. of caller}{(2), (3)}
\lineiv{Expression read by \function{input()}}%
{global n.s. of caller}%
{local n.s. of caller}{}
\end{tableiv}
\refbimodindex{__main__} \refbimodindex{__main__}
Notes: Notes:
\begin{description} \begin{description}
\item[n.s.] means {\em namespace} \item[n.s.] means \emph{namespace}
\item[(1)] The main module for a script is always called \item[(1)] The main module for a script is always called
\module{__main__}; ``the filename don't enter into it.'' \module{__main__}; ``the filename don't enter into it.''
...@@ -154,7 +161,7 @@ dictionary representing the current global and local namespace, ...@@ -154,7 +161,7 @@ dictionary representing the current global and local namespace,
respectively. The effect of modifications to this dictionary on the respectively. The effect of modifications to this dictionary on the
namespace are undefined.% namespace are undefined.%
\footnote{The current implementations return the dictionary actually \footnote{The current implementations return the dictionary actually
used to implement the namespace, {\em except} for functions, where used to implement the namespace, \emph{except} for functions, where
the optimizer may cause the local namespace to be implemented the optimizer may cause the local namespace to be implemented
differently, and \function{locals()} returns a read-only dictionary.} differently, and \function{locals()} returns a read-only dictionary.}
...@@ -162,8 +169,8 @@ differently, and \function{locals()} returns a read-only dictionary.} ...@@ -162,8 +169,8 @@ differently, and \function{locals()} returns a read-only dictionary.}
Exceptions are a means of breaking out of the normal flow of control Exceptions are a means of breaking out of the normal flow of control
of a code block in order to handle errors or other exceptional of a code block in order to handle errors or other exceptional
conditions. An exception is {\em raised} at the point where the error conditions. An exception is \emph{raised} at the point where the error
is detected; it may be {\em handled} by the surrounding code block or is detected; it may be \emph{handled} by the surrounding code block or
by any code block that directly or indirectly invoked the code block by any code block that directly or indirectly invoked the code block
where the error occurred. where the error occurred.
\index{exception} \index{exception}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment