blob: 991762f4e62dd94aef44ffe871b8351840763586 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`token` --- Constants used with Python parse trees
2=======================================================
3
4.. module:: token
5 :synopsis: Constants representing terminal nodes of the parse tree.
6.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
7
8
9This module provides constants which represent the numeric values of leaf nodes
10of the parse tree (terminal tokens). Refer to the file :file:`Grammar/Grammar`
11in the Python distribution for the definitions of the names in the context of
12the language grammar. The specific numeric values which the names map to may
13change between Python versions.
14
Georg Brandleec2d762010-10-17 09:46:11 +000015The module also provides a mapping from numeric codes to names and some
16functions. The functions mirror definitions in the Python C header files.
Georg Brandl116aa622007-08-15 14:28:22 +000017
18
19.. data:: tok_name
20
21 Dictionary mapping the numeric values of the constants defined in this module
22 back to name strings, allowing more human-readable representation of parse trees
23 to be generated.
24
25
26.. function:: ISTERMINAL(x)
27
28 Return true for terminal token values.
29
30
31.. function:: ISNONTERMINAL(x)
32
33 Return true for non-terminal token values.
34
35
36.. function:: ISEOF(x)
37
38 Return true if *x* is the marker indicating the end of input.
39
40
Georg Brandleec2d762010-10-17 09:46:11 +000041The token constants are:
42
43.. data:: ENDMARKER
44 NAME
45 NUMBER
46 STRING
47 NEWLINE
48 INDENT
49 DEDENT
50 LPAR
51 RPAR
52 LSQB
53 RSQB
54 COLON
55 COMMA
56 SEMI
57 PLUS
58 MINUS
59 STAR
60 SLASH
61 VBAR
62 AMPER
63 LESS
64 GREATER
65 EQUAL
66 DOT
67 PERCENT
68 BACKQUOTE
69 LBRACE
70 RBRACE
71 EQEQUAL
72 NOTEQUAL
73 LESSEQUAL
74 GREATEREQUAL
75 TILDE
76 CIRCUMFLEX
77 LEFTSHIFT
78 RIGHTSHIFT
79 DOUBLESTAR
80 PLUSEQUAL
81 MINEQUAL
82 STAREQUAL
83 SLASHEQUAL
84 PERCENTEQUAL
85 AMPEREQUAL
86 VBAREQUAL
87 CIRCUMFLEXEQUAL
88 LEFTSHIFTEQUAL
89 RIGHTSHIFTEQUAL
90 DOUBLESTAREQUAL
91 DOUBLESLASH
92 DOUBLESLASHEQUAL
93 AT
94 OP
95 ERRORTOKEN
96 N_TOKENS
97 NT_OFFSET
98
99
Georg Brandl116aa622007-08-15 14:28:22 +0000100.. seealso::
101
102 Module :mod:`parser`
103 The second example for the :mod:`parser` module shows how to use the
104 :mod:`symbol` module.
105