This document is for an old version of Python that is no longer supported. You should upgrade and read the documentação do Python para versão estável atual.

# 32.5. `token` — Constants used with Python parse trees

Código-fonte: Lib/token.py

This module provides constants which represent the numeric values of leaf nodes of the parse tree (terminal tokens). Refer to the file `Grammar/Grammar` in the Python distribution for the definitions of the names in the context of the language grammar. The specific numeric values which the names map to may change between Python versions.

The module also provides a mapping from numeric codes to names and some functions. The functions mirror definitions in the Python C header files.

`token.``tok_name`

  Dicionário que mapeia os valores numéricos das constantes definidas neste módulo de volta para cadeias de nomes, permitindo que seja gerada uma representação mais legível de árvores de análise.

`token.``ISTERMINAL`(x)

  Return true for terminal token values.

`token.``ISNONTERMINAL`(x)

  Return true for non-terminal token values.

`token.``ISEOF`(x)

  Return true if x is the marker indicating the end of input.

The token constants are:

`token.``ENDMARKER`
`token.``NAME`
`token.``NUMBER`
`token.``STRING`
`token.``NEWLINE`
`token.``INDENT`
`token.``DEDENT`
`token.``LPAR`
`token.``RPAR`
`token.``LSQB`
`token.``RSQB`
`token.``COLON`
`token.``COMMA`
`token.``SEMI`
`token.``PLUS`
`token.``MINUS`
`token.``STAR`
`token.``SLASH`
`token.``VBAR`
`token.``AMPER`
`token.``LESS`
`token.``GREATER`
`token.``EQUAL`
`token.``DOT`
`token.``PERCENT`
`token.``BACKQUOTE`
`token.``LBRACE`
`token.``RBRACE`
`token.``EQEQUAL`
`token.``NOTEQUAL`
`token.``LESSEQUAL`
`token.``GREATEREQUAL`
`token.``TILDE`
`token.``CIRCUMFLEX`
`token.``LEFTSHIFT`
`token.``RIGHTSHIFT`
`token.``DOUBLESTAR`
`token.``PLUSEQUAL`
`token.``MINEQUAL`
`token.``STAREQUAL`
`token.``SLASHEQUAL`
`token.``PERCENTEQUAL`
`token.``AMPEREQUAL`
`token.``VBAREQUAL`
`token.``CIRCUMFLEXEQUAL`
`token.``LEFTSHIFTEQUAL`
`token.``RIGHTSHIFTEQUAL`
`token.``DOUBLESTAREQUAL`
`token.``DOUBLESLASH`
`token.``DOUBLESLASHEQUAL`
`token.``AT`
`token.``OP`
`token.``ERRORTOKEN`
`token.``N_TOKENS`
`token.``NT_OFFSET`

Ver também

Module `parser`

  The second example for the `parser` module shows how to use the `symbol` module.