Kerala Cyber
Warriors
KCW Uploader V1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>9. Full Grammar specification — Python 2.7.18 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/language_data.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 2.7.18 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="The Python Standard Library" href="../library/index.html" />
<link rel="prev" title="8. Top-level components" href="toplevel_components.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="file:///usr/share/doc/python2.7/html/reference/grammar.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
</head><body>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
This document is for an old version of Python that is <a href="https://devguide.python.org/devcycle/#end-of-life-branches">no longer supported</a>.
You should install the python3 and python3-doc packages and read the
<a href="file:///usr/share/doc/python3-doc/html/reference/grammar.html"> Python documentation for the Python3 version packaged in this release</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../library/index.html" title="The Python Standard Library"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="toplevel_components.html" title="8. Top-level components"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="../index.html">Python 2.7.18 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Language Reference</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="full-grammar-specification">
<h1>9. Full Grammar specification<a class="headerlink" href="#full-grammar-specification" title="Permalink to this headline">ΒΆ</a></h1>
<p>This is the full Python grammar, as it is read by the parser generator and used
to parse Python source files:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Grammar for Python</span>
<span class="c1"># Note: Changing the grammar specified in this file will most likely</span>
<span class="c1"># require corresponding changes in the parser module</span>
<span class="c1"># (../Modules/parsermodule.c). If you can't make the changes to</span>
<span class="c1"># that module yourself, please co-ordinate the required changes</span>
<span class="c1"># with someone who can; ask around on python-dev for help. Fred</span>
<span class="c1"># Drake <fdrake@acm.org> will probably be listening there.</span>
<span class="c1"># NOTE WELL: You should also follow all the steps listed in PEP 306,</span>
<span class="c1"># "How to Change Python's Grammar"</span>
<span class="c1"># Start symbols for the grammar:</span>
<span class="c1"># single_input is a single interactive statement;</span>
<span class="c1"># file_input is a module or sequence of commands read from an input file;</span>
<span class="c1"># eval_input is the input for the eval() and input() functions.</span>
<span class="c1"># NB: compound_stmt in single_input is followed by extra NEWLINE!</span>
<span class="n">single_input</span><span class="p">:</span> <span class="n">NEWLINE</span> <span class="o">|</span> <span class="n">simple_stmt</span> <span class="o">|</span> <span class="n">compound_stmt</span> <span class="n">NEWLINE</span>
<span class="n">file_input</span><span class="p">:</span> <span class="p">(</span><span class="n">NEWLINE</span> <span class="o">|</span> <span class="n">stmt</span><span class="p">)</span><span class="o">*</span> <span class="n">ENDMARKER</span>
<span class="n">eval_input</span><span class="p">:</span> <span class="n">testlist</span> <span class="n">NEWLINE</span><span class="o">*</span> <span class="n">ENDMARKER</span>
<span class="n">decorator</span><span class="p">:</span> <span class="s1">'@'</span> <span class="n">dotted_name</span> <span class="p">[</span> <span class="s1">'('</span> <span class="p">[</span><span class="n">arglist</span><span class="p">]</span> <span class="s1">')'</span> <span class="p">]</span> <span class="n">NEWLINE</span>
<span class="n">decorators</span><span class="p">:</span> <span class="n">decorator</span><span class="o">+</span>
<span class="n">decorated</span><span class="p">:</span> <span class="n">decorators</span> <span class="p">(</span><span class="n">classdef</span> <span class="o">|</span> <span class="n">funcdef</span><span class="p">)</span>
<span class="n">funcdef</span><span class="p">:</span> <span class="s1">'def'</span> <span class="n">NAME</span> <span class="n">parameters</span> <span class="s1">':'</span> <span class="n">suite</span>
<span class="n">parameters</span><span class="p">:</span> <span class="s1">'('</span> <span class="p">[</span><span class="n">varargslist</span><span class="p">]</span> <span class="s1">')'</span>
<span class="n">varargslist</span><span class="p">:</span> <span class="p">((</span><span class="n">fpdef</span> <span class="p">[</span><span class="s1">'='</span> <span class="n">test</span><span class="p">]</span> <span class="s1">','</span><span class="p">)</span><span class="o">*</span>
<span class="p">(</span><span class="s1">'*'</span> <span class="n">NAME</span> <span class="p">[</span><span class="s1">','</span> <span class="s1">'**'</span> <span class="n">NAME</span><span class="p">]</span> <span class="o">|</span> <span class="s1">'**'</span> <span class="n">NAME</span><span class="p">)</span> <span class="o">|</span>
<span class="n">fpdef</span> <span class="p">[</span><span class="s1">'='</span> <span class="n">test</span><span class="p">]</span> <span class="p">(</span><span class="s1">','</span> <span class="n">fpdef</span> <span class="p">[</span><span class="s1">'='</span> <span class="n">test</span><span class="p">])</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">])</span>
<span class="n">fpdef</span><span class="p">:</span> <span class="n">NAME</span> <span class="o">|</span> <span class="s1">'('</span> <span class="n">fplist</span> <span class="s1">')'</span>
<span class="n">fplist</span><span class="p">:</span> <span class="n">fpdef</span> <span class="p">(</span><span class="s1">','</span> <span class="n">fpdef</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span>
<span class="n">stmt</span><span class="p">:</span> <span class="n">simple_stmt</span> <span class="o">|</span> <span class="n">compound_stmt</span>
<span class="n">simple_stmt</span><span class="p">:</span> <span class="n">small_stmt</span> <span class="p">(</span><span class="s1">';'</span> <span class="n">small_stmt</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">';'</span><span class="p">]</span> <span class="n">NEWLINE</span>
<span class="n">small_stmt</span><span class="p">:</span> <span class="p">(</span><span class="n">expr_stmt</span> <span class="o">|</span> <span class="n">print_stmt</span> <span class="o">|</span> <span class="n">del_stmt</span> <span class="o">|</span> <span class="n">pass_stmt</span> <span class="o">|</span> <span class="n">flow_stmt</span> <span class="o">|</span>
<span class="n">import_stmt</span> <span class="o">|</span> <span class="n">global_stmt</span> <span class="o">|</span> <span class="n">exec_stmt</span> <span class="o">|</span> <span class="n">assert_stmt</span><span class="p">)</span>
<span class="n">expr_stmt</span><span class="p">:</span> <span class="n">testlist</span> <span class="p">(</span><span class="n">augassign</span> <span class="p">(</span><span class="n">yield_expr</span><span class="o">|</span><span class="n">testlist</span><span class="p">)</span> <span class="o">|</span>
<span class="p">(</span><span class="s1">'='</span> <span class="p">(</span><span class="n">yield_expr</span><span class="o">|</span><span class="n">testlist</span><span class="p">))</span><span class="o">*</span><span class="p">)</span>
<span class="n">augassign</span><span class="p">:</span> <span class="p">(</span><span class="s1">'+='</span> <span class="o">|</span> <span class="s1">'-='</span> <span class="o">|</span> <span class="s1">'*='</span> <span class="o">|</span> <span class="s1">'/='</span> <span class="o">|</span> <span class="s1">'%='</span> <span class="o">|</span> <span class="s1">'&='</span> <span class="o">|</span> <span class="s1">'|='</span> <span class="o">|</span> <span class="s1">'^='</span> <span class="o">|</span>
<span class="s1">'<<='</span> <span class="o">|</span> <span class="s1">'>>='</span> <span class="o">|</span> <span class="s1">'**='</span> <span class="o">|</span> <span class="s1">'//='</span><span class="p">)</span>
<span class="c1"># For normal assignments, additional restrictions enforced by the interpreter</span>
<span class="n">print_stmt</span><span class="p">:</span> <span class="s1">'print'</span> <span class="p">(</span> <span class="p">[</span> <span class="n">test</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span> <span class="p">]</span> <span class="o">|</span>
<span class="s1">'>>'</span> <span class="n">test</span> <span class="p">[</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span><span class="p">)</span><span class="o">+</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span> <span class="p">]</span> <span class="p">)</span>
<span class="n">del_stmt</span><span class="p">:</span> <span class="s1">'del'</span> <span class="n">exprlist</span>
<span class="n">pass_stmt</span><span class="p">:</span> <span class="s1">'pass'</span>
<span class="n">flow_stmt</span><span class="p">:</span> <span class="n">break_stmt</span> <span class="o">|</span> <span class="n">continue_stmt</span> <span class="o">|</span> <span class="n">return_stmt</span> <span class="o">|</span> <span class="n">raise_stmt</span> <span class="o">|</span> <span class="n">yield_stmt</span>
<span class="n">break_stmt</span><span class="p">:</span> <span class="s1">'break'</span>
<span class="n">continue_stmt</span><span class="p">:</span> <span class="s1">'continue'</span>
<span class="n">return_stmt</span><span class="p">:</span> <span class="s1">'return'</span> <span class="p">[</span><span class="n">testlist</span><span class="p">]</span>
<span class="n">yield_stmt</span><span class="p">:</span> <span class="n">yield_expr</span>
<span class="n">raise_stmt</span><span class="p">:</span> <span class="s1">'raise'</span> <span class="p">[</span><span class="n">test</span> <span class="p">[</span><span class="s1">','</span> <span class="n">test</span> <span class="p">[</span><span class="s1">','</span> <span class="n">test</span><span class="p">]]]</span>
<span class="n">import_stmt</span><span class="p">:</span> <span class="n">import_name</span> <span class="o">|</span> <span class="n">import_from</span>
<span class="n">import_name</span><span class="p">:</span> <span class="s1">'import'</span> <span class="n">dotted_as_names</span>
<span class="n">import_from</span><span class="p">:</span> <span class="p">(</span><span class="s1">'from'</span> <span class="p">(</span><span class="s1">'.'</span><span class="o">*</span> <span class="n">dotted_name</span> <span class="o">|</span> <span class="s1">'.'</span><span class="o">+</span><span class="p">)</span>
<span class="s1">'import'</span> <span class="p">(</span><span class="s1">'*'</span> <span class="o">|</span> <span class="s1">'('</span> <span class="n">import_as_names</span> <span class="s1">')'</span> <span class="o">|</span> <span class="n">import_as_names</span><span class="p">))</span>
<span class="n">import_as_name</span><span class="p">:</span> <span class="n">NAME</span> <span class="p">[</span><span class="s1">'as'</span> <span class="n">NAME</span><span class="p">]</span>
<span class="n">dotted_as_name</span><span class="p">:</span> <span class="n">dotted_name</span> <span class="p">[</span><span class="s1">'as'</span> <span class="n">NAME</span><span class="p">]</span>
<span class="n">import_as_names</span><span class="p">:</span> <span class="n">import_as_name</span> <span class="p">(</span><span class="s1">','</span> <span class="n">import_as_name</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span>
<span class="n">dotted_as_names</span><span class="p">:</span> <span class="n">dotted_as_name</span> <span class="p">(</span><span class="s1">','</span> <span class="n">dotted_as_name</span><span class="p">)</span><span class="o">*</span>
<span class="n">dotted_name</span><span class="p">:</span> <span class="n">NAME</span> <span class="p">(</span><span class="s1">'.'</span> <span class="n">NAME</span><span class="p">)</span><span class="o">*</span>
<span class="n">global_stmt</span><span class="p">:</span> <span class="s1">'global'</span> <span class="n">NAME</span> <span class="p">(</span><span class="s1">','</span> <span class="n">NAME</span><span class="p">)</span><span class="o">*</span>
<span class="n">exec_stmt</span><span class="p">:</span> <span class="s1">'exec'</span> <span class="n">expr</span> <span class="p">[</span><span class="s1">'in'</span> <span class="n">test</span> <span class="p">[</span><span class="s1">','</span> <span class="n">test</span><span class="p">]]</span>
<span class="n">assert_stmt</span><span class="p">:</span> <span class="s1">'assert'</span> <span class="n">test</span> <span class="p">[</span><span class="s1">','</span> <span class="n">test</span><span class="p">]</span>
<span class="n">compound_stmt</span><span class="p">:</span> <span class="n">if_stmt</span> <span class="o">|</span> <span class="n">while_stmt</span> <span class="o">|</span> <span class="n">for_stmt</span> <span class="o">|</span> <span class="n">try_stmt</span> <span class="o">|</span> <span class="n">with_stmt</span> <span class="o">|</span> <span class="n">funcdef</span> <span class="o">|</span> <span class="n">classdef</span> <span class="o">|</span> <span class="n">decorated</span>
<span class="n">if_stmt</span><span class="p">:</span> <span class="s1">'if'</span> <span class="n">test</span> <span class="s1">':'</span> <span class="n">suite</span> <span class="p">(</span><span class="s1">'elif'</span> <span class="n">test</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">'else'</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">]</span>
<span class="n">while_stmt</span><span class="p">:</span> <span class="s1">'while'</span> <span class="n">test</span> <span class="s1">':'</span> <span class="n">suite</span> <span class="p">[</span><span class="s1">'else'</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">]</span>
<span class="n">for_stmt</span><span class="p">:</span> <span class="s1">'for'</span> <span class="n">exprlist</span> <span class="s1">'in'</span> <span class="n">testlist</span> <span class="s1">':'</span> <span class="n">suite</span> <span class="p">[</span><span class="s1">'else'</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">]</span>
<span class="n">try_stmt</span><span class="p">:</span> <span class="p">(</span><span class="s1">'try'</span> <span class="s1">':'</span> <span class="n">suite</span>
<span class="p">((</span><span class="n">except_clause</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">)</span><span class="o">+</span>
<span class="p">[</span><span class="s1">'else'</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">]</span>
<span class="p">[</span><span class="s1">'finally'</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">]</span> <span class="o">|</span>
<span class="s1">'finally'</span> <span class="s1">':'</span> <span class="n">suite</span><span class="p">))</span>
<span class="n">with_stmt</span><span class="p">:</span> <span class="s1">'with'</span> <span class="n">with_item</span> <span class="p">(</span><span class="s1">','</span> <span class="n">with_item</span><span class="p">)</span><span class="o">*</span> <span class="s1">':'</span> <span class="n">suite</span>
<span class="n">with_item</span><span class="p">:</span> <span class="n">test</span> <span class="p">[</span><span class="s1">'as'</span> <span class="n">expr</span><span class="p">]</span>
<span class="c1"># NB compile.c makes sure that the default except clause is last</span>
<span class="n">except_clause</span><span class="p">:</span> <span class="s1">'except'</span> <span class="p">[</span><span class="n">test</span> <span class="p">[(</span><span class="s1">'as'</span> <span class="o">|</span> <span class="s1">','</span><span class="p">)</span> <span class="n">test</span><span class="p">]]</span>
<span class="n">suite</span><span class="p">:</span> <span class="n">simple_stmt</span> <span class="o">|</span> <span class="n">NEWLINE</span> <span class="n">INDENT</span> <span class="n">stmt</span><span class="o">+</span> <span class="n">DEDENT</span>
<span class="c1"># Backward compatibility cruft to support:</span>
<span class="c1"># [ x for x in lambda: True, lambda: False if x() ]</span>
<span class="c1"># even while also allowing:</span>
<span class="c1"># lambda x: 5 if x else 2</span>
<span class="c1"># (But not a mix of the two)</span>
<span class="n">testlist_safe</span><span class="p">:</span> <span class="n">old_test</span> <span class="p">[(</span><span class="s1">','</span> <span class="n">old_test</span><span class="p">)</span><span class="o">+</span> <span class="p">[</span><span class="s1">','</span><span class="p">]]</span>
<span class="n">old_test</span><span class="p">:</span> <span class="n">or_test</span> <span class="o">|</span> <span class="n">old_lambdef</span>
<span class="n">old_lambdef</span><span class="p">:</span> <span class="s1">'lambda'</span> <span class="p">[</span><span class="n">varargslist</span><span class="p">]</span> <span class="s1">':'</span> <span class="n">old_test</span>
<span class="n">test</span><span class="p">:</span> <span class="n">or_test</span> <span class="p">[</span><span class="s1">'if'</span> <span class="n">or_test</span> <span class="s1">'else'</span> <span class="n">test</span><span class="p">]</span> <span class="o">|</span> <span class="n">lambdef</span>
<span class="n">or_test</span><span class="p">:</span> <span class="n">and_test</span> <span class="p">(</span><span class="s1">'or'</span> <span class="n">and_test</span><span class="p">)</span><span class="o">*</span>
<span class="n">and_test</span><span class="p">:</span> <span class="n">not_test</span> <span class="p">(</span><span class="s1">'and'</span> <span class="n">not_test</span><span class="p">)</span><span class="o">*</span>
<span class="n">not_test</span><span class="p">:</span> <span class="s1">'not'</span> <span class="n">not_test</span> <span class="o">|</span> <span class="n">comparison</span>
<span class="n">comparison</span><span class="p">:</span> <span class="n">expr</span> <span class="p">(</span><span class="n">comp_op</span> <span class="n">expr</span><span class="p">)</span><span class="o">*</span>
<span class="n">comp_op</span><span class="p">:</span> <span class="s1">'<'</span><span class="o">|</span><span class="s1">'>'</span><span class="o">|</span><span class="s1">'=='</span><span class="o">|</span><span class="s1">'>='</span><span class="o">|</span><span class="s1">'<='</span><span class="o">|</span><span class="s1">'<>'</span><span class="o">|</span><span class="s1">'!='</span><span class="o">|</span><span class="s1">'in'</span><span class="o">|</span><span class="s1">'not'</span> <span class="s1">'in'</span><span class="o">|</span><span class="s1">'is'</span><span class="o">|</span><span class="s1">'is'</span> <span class="s1">'not'</span>
<span class="n">expr</span><span class="p">:</span> <span class="n">xor_expr</span> <span class="p">(</span><span class="s1">'|'</span> <span class="n">xor_expr</span><span class="p">)</span><span class="o">*</span>
<span class="n">xor_expr</span><span class="p">:</span> <span class="n">and_expr</span> <span class="p">(</span><span class="s1">'^'</span> <span class="n">and_expr</span><span class="p">)</span><span class="o">*</span>
<span class="n">and_expr</span><span class="p">:</span> <span class="n">shift_expr</span> <span class="p">(</span><span class="s1">'&'</span> <span class="n">shift_expr</span><span class="p">)</span><span class="o">*</span>
<span class="n">shift_expr</span><span class="p">:</span> <span class="n">arith_expr</span> <span class="p">((</span><span class="s1">'<<'</span><span class="o">|</span><span class="s1">'>>'</span><span class="p">)</span> <span class="n">arith_expr</span><span class="p">)</span><span class="o">*</span>
<span class="n">arith_expr</span><span class="p">:</span> <span class="n">term</span> <span class="p">((</span><span class="s1">'+'</span><span class="o">|</span><span class="s1">'-'</span><span class="p">)</span> <span class="n">term</span><span class="p">)</span><span class="o">*</span>
<span class="n">term</span><span class="p">:</span> <span class="n">factor</span> <span class="p">((</span><span class="s1">'*'</span><span class="o">|</span><span class="s1">'/'</span><span class="o">|</span><span class="s1">'%'</span><span class="o">|</span><span class="s1">'//'</span><span class="p">)</span> <span class="n">factor</span><span class="p">)</span><span class="o">*</span>
<span class="n">factor</span><span class="p">:</span> <span class="p">(</span><span class="s1">'+'</span><span class="o">|</span><span class="s1">'-'</span><span class="o">|</span><span class="s1">'~'</span><span class="p">)</span> <span class="n">factor</span> <span class="o">|</span> <span class="n">power</span>
<span class="n">power</span><span class="p">:</span> <span class="n">atom</span> <span class="n">trailer</span><span class="o">*</span> <span class="p">[</span><span class="s1">'**'</span> <span class="n">factor</span><span class="p">]</span>
<span class="n">atom</span><span class="p">:</span> <span class="p">(</span><span class="s1">'('</span> <span class="p">[</span><span class="n">yield_expr</span><span class="o">|</span><span class="n">testlist_comp</span><span class="p">]</span> <span class="s1">')'</span> <span class="o">|</span>
<span class="s1">'['</span> <span class="p">[</span><span class="n">listmaker</span><span class="p">]</span> <span class="s1">']'</span> <span class="o">|</span>
<span class="s1">'{'</span> <span class="p">[</span><span class="n">dictorsetmaker</span><span class="p">]</span> <span class="s1">'}'</span> <span class="o">|</span>
<span class="s1">'`'</span> <span class="n">testlist1</span> <span class="s1">'`'</span> <span class="o">|</span>
<span class="n">NAME</span> <span class="o">|</span> <span class="n">NUMBER</span> <span class="o">|</span> <span class="n">STRING</span><span class="o">+</span><span class="p">)</span>
<span class="n">listmaker</span><span class="p">:</span> <span class="n">test</span> <span class="p">(</span> <span class="n">list_for</span> <span class="o">|</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span> <span class="p">)</span>
<span class="n">testlist_comp</span><span class="p">:</span> <span class="n">test</span> <span class="p">(</span> <span class="n">comp_for</span> <span class="o">|</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span> <span class="p">)</span>
<span class="n">lambdef</span><span class="p">:</span> <span class="s1">'lambda'</span> <span class="p">[</span><span class="n">varargslist</span><span class="p">]</span> <span class="s1">':'</span> <span class="n">test</span>
<span class="n">trailer</span><span class="p">:</span> <span class="s1">'('</span> <span class="p">[</span><span class="n">arglist</span><span class="p">]</span> <span class="s1">')'</span> <span class="o">|</span> <span class="s1">'['</span> <span class="n">subscriptlist</span> <span class="s1">']'</span> <span class="o">|</span> <span class="s1">'.'</span> <span class="n">NAME</span>
<span class="n">subscriptlist</span><span class="p">:</span> <span class="n">subscript</span> <span class="p">(</span><span class="s1">','</span> <span class="n">subscript</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span>
<span class="n">subscript</span><span class="p">:</span> <span class="s1">'.'</span> <span class="s1">'.'</span> <span class="s1">'.'</span> <span class="o">|</span> <span class="n">test</span> <span class="o">|</span> <span class="p">[</span><span class="n">test</span><span class="p">]</span> <span class="s1">':'</span> <span class="p">[</span><span class="n">test</span><span class="p">]</span> <span class="p">[</span><span class="n">sliceop</span><span class="p">]</span>
<span class="n">sliceop</span><span class="p">:</span> <span class="s1">':'</span> <span class="p">[</span><span class="n">test</span><span class="p">]</span>
<span class="n">exprlist</span><span class="p">:</span> <span class="n">expr</span> <span class="p">(</span><span class="s1">','</span> <span class="n">expr</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span>
<span class="n">testlist</span><span class="p">:</span> <span class="n">test</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span>
<span class="n">dictorsetmaker</span><span class="p">:</span> <span class="p">(</span> <span class="p">(</span><span class="n">test</span> <span class="s1">':'</span> <span class="n">test</span> <span class="p">(</span><span class="n">comp_for</span> <span class="o">|</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span> <span class="s1">':'</span> <span class="n">test</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]))</span> <span class="o">|</span>
<span class="p">(</span><span class="n">test</span> <span class="p">(</span><span class="n">comp_for</span> <span class="o">|</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span><span class="p">]))</span> <span class="p">)</span>
<span class="n">classdef</span><span class="p">:</span> <span class="s1">'class'</span> <span class="n">NAME</span> <span class="p">[</span><span class="s1">'('</span> <span class="p">[</span><span class="n">testlist</span><span class="p">]</span> <span class="s1">')'</span><span class="p">]</span> <span class="s1">':'</span> <span class="n">suite</span>
<span class="n">arglist</span><span class="p">:</span> <span class="p">(</span><span class="n">argument</span> <span class="s1">','</span><span class="p">)</span><span class="o">*</span> <span class="p">(</span><span class="n">argument</span> <span class="p">[</span><span class="s1">','</span><span class="p">]</span>
<span class="o">|</span><span class="s1">'*'</span> <span class="n">test</span> <span class="p">(</span><span class="s1">','</span> <span class="n">argument</span><span class="p">)</span><span class="o">*</span> <span class="p">[</span><span class="s1">','</span> <span class="s1">'**'</span> <span class="n">test</span><span class="p">]</span>
<span class="o">|</span><span class="s1">'**'</span> <span class="n">test</span><span class="p">)</span>
<span class="c1"># The reason that keywords are test nodes instead of NAME is that using NAME</span>
<span class="c1"># results in an ambiguity. ast.c makes sure it's a NAME.</span>
<span class="n">argument</span><span class="p">:</span> <span class="n">test</span> <span class="p">[</span><span class="n">comp_for</span><span class="p">]</span> <span class="o">|</span> <span class="n">test</span> <span class="s1">'='</span> <span class="n">test</span>
<span class="n">list_iter</span><span class="p">:</span> <span class="n">list_for</span> <span class="o">|</span> <span class="n">list_if</span>
<span class="n">list_for</span><span class="p">:</span> <span class="s1">'for'</span> <span class="n">exprlist</span> <span class="s1">'in'</span> <span class="n">testlist_safe</span> <span class="p">[</span><span class="n">list_iter</span><span class="p">]</span>
<span class="n">list_if</span><span class="p">:</span> <span class="s1">'if'</span> <span class="n">old_test</span> <span class="p">[</span><span class="n">list_iter</span><span class="p">]</span>
<span class="n">comp_iter</span><span class="p">:</span> <span class="n">comp_for</span> <span class="o">|</span> <span class="n">comp_if</span>
<span class="n">comp_for</span><span class="p">:</span> <span class="s1">'for'</span> <span class="n">exprlist</span> <span class="s1">'in'</span> <span class="n">or_test</span> <span class="p">[</span><span class="n">comp_iter</span><span class="p">]</span>
<span class="n">comp_if</span><span class="p">:</span> <span class="s1">'if'</span> <span class="n">old_test</span> <span class="p">[</span><span class="n">comp_iter</span><span class="p">]</span>
<span class="n">testlist1</span><span class="p">:</span> <span class="n">test</span> <span class="p">(</span><span class="s1">','</span> <span class="n">test</span><span class="p">)</span><span class="o">*</span>
<span class="c1"># not used in grammar, but may appear in "node" passed from Parser to Compiler</span>
<span class="n">encoding_decl</span><span class="p">:</span> <span class="n">NAME</span>
<span class="n">yield_expr</span><span class="p">:</span> <span class="s1">'yield'</span> <span class="p">[</span><span class="n">testlist</span><span class="p">]</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="toplevel_components.html"
title="previous chapter">8. Top-level components</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../library/index.html"
title="next chapter">The Python Standard Library</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/reference/grammar.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../library/index.html" title="The Python Standard Library"
>next</a> |</li>
<li class="right" >
<a href="toplevel_components.html" title="8. Top-level components"
>previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="../index.html">Python 2.7.18 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Language Reference</a> »</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 1990-2024, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on November 21, 2024.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.8.5.
</div>
</body>
</html>
-=[ KCW uplo4d3r c0ded by cJ_n4p573r ]=-
Ⓒ2017 ҠЄГѦLѦ СүѣЄГ ЩѦГГіѺГՏ