32.5. token โ€” Constants used with Python parse treesยถ

Source code: 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ยถ

Dictionary mapping the numeric values of the constants defined in this module back to name strings, allowing more human-readable representation of parse trees to be generated.

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ยถ

See also

Module parser

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