<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"ref.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"ref.html" title='Python Reference Manual'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"prev" href=
"implementations.html" />
<link rel=
"parent" href=
"introduction.html" />
<link rel=
"next" href=
"lexical.html" />
<meta name='aesop' content='information'
/>
<title>1.2 Notation
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"1.1 Alternate Implementations"
href=
"implementations.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"1. Introduction"
href=
"introduction.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"2. Lexical analysis"
href=
"lexical.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Reference Manual
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"implementations.html">1.1 Alternate Implementations
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"introduction.html">1. Introduction
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"lexical.html">2. Lexical analysis
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION003200000000000000000"></A><A NAME=
"notation"></A><a id='l2h-
1' xml:id='l2h-
1'
></a>
The descriptions of lexical analysis and syntax use a modified BNF
grammar notation. This uses the following style of definition:
<div class=
"productions">
<td><a id='tok-name' xml:id='tok-name'
>name
</a></td>
<td><a class='grammartoken'
href=
"notation.html#tok-lc_letter">lc_letter
</a> (
<a class='grammartoken'
href=
"notation.html#tok-lc_letter">lc_letter
</a> |
"_")*
</td></tr>
<td><a id='tok-lc_letter' xml:id='tok-lc_letter'
>lc_letter
</a></td>
<a class=
"grammar-footer"
href=
"grammar.txt" type=
"text/plain"
>Download entire grammar as text.
</a>
The first line says that a
<code>name
</code> is an
<code>lc_letter
</code> followed by
a sequence of zero or more
<code>lc_letter
</code>s and underscores. An
<code>lc_letter
</code> in turn is any of the single characters
"<tt class="character
">a</tt>"
through
"<tt class="character
">z</tt>". (This rule is actually adhered to for the
names defined in lexical and grammar rules in this document.)
Each rule begins with a name (which is the name defined by the rule)
and
<code>::=
</code>. A vertical bar (
<code>|
</code>) is used to separate
alternatives; it is the least binding operator in this notation. A
star (
<code>*
</code>) means zero or more repetitions of the preceding item;
likewise, a plus (
<code>+
</code>) means one or more repetitions, and a
phrase enclosed in square brackets (
<code>[ ]
</code>) means zero or one
occurrences (in other words, the enclosed phrase is optional). The
<code>*
</code> and
<code>+
</code> operators bind as tightly as possible;
parentheses are used for grouping. Literal strings are enclosed in
quotes. White space is only meaningful to separate tokens.
Rules are normally contained on a single line; rules with many
alternatives may be formatted alternatively with each line after the
first beginning with a vertical bar.
In lexical definitions (as the example above), two more conventions
are used: Two literal characters separated by three dots mean a choice
of any single character in the given (inclusive) range of ASCII
characters. A phrase between angular brackets (
<code><...
></code>) gives an
informal description of the symbol defined; e.g., this could be used
to describe the notion of `control character' if needed.
Even though the notation used is almost the same, there is a big
difference between the meaning of lexical and syntactic definitions:
a lexical definition operates on the individual characters of the
input source, while a syntax definition operates on the stream of
tokens generated by the lexical analysis. All uses of BNF in the next
chapter (``Lexical Analysis'') are lexical definitions; uses in
subsequent chapters are syntactic definitions.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"1.1 Alternate Implementations"
href=
"implementations.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"1. Introduction"
href=
"introduction.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"2. Lexical analysis"
href=
"lexical.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Reference Manual
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"implementations.html">1.1 Alternate Implementations
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"introduction.html">1. Introduction
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"lexical.html">2. Lexical analysis
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.