관리-도구
편집 파일: grammar.cpython-35.opt-1.pyc
��Yf0 � @ s� d Z d d l Z d d l Z d d l m Z m Z Gd d � d e � Z d d � Z d Z i Z x? e j � D]1 Z e ro e j � \ Z Z e e e � e e <qo Wd S) a� This module defines the data structures used to represent a grammar. These are a bit arcane because they are derived from the data structures used by Python's 'pgen' parser generator. There's also a table here mapping operators to their names in the token module; the Python tokenize module reports all operators as the fallback token code OP, but the parser needs the actual token code. � N� )�token�tokenizec @ sR e Z d Z d Z d d � Z d d � Z d d � Z d d � Z d d � Z d S) �Grammara� Pgen parsing tables conversion class. Once initialized, this class supplies the grammar tables for the parsing engine implemented by parse.py. The parsing engine accesses the instance variables directly. The class here does not provide initialization of the tables; several subclasses exist to do this (see the conv and pgen modules). The load() method reads the tables from a pickle file, which is much faster than the other ways offered by subclasses. The pickle file is written by calling dump() (after loading the grammar tables using a subclass). The report() method prints a readable representation of the tables to stdout, for debugging. The instance variables are as follows: symbol2number -- a dict mapping symbol names to numbers. Symbol numbers are always 256 or higher, to distinguish them from token numbers, which are between 0 and 255 (inclusive). number2symbol -- a dict mapping numbers to symbol names; these two are each other's inverse. states -- a list of DFAs, where each DFA is a list of states, each state is a list of arcs, and each arc is a (i, j) pair where i is a label and j is a state number. The DFA number is the index into this list. (This name is slightly confusing.) Final states are represented by a special arc of the form (0, j) where j is its own state number. dfas -- a dict mapping symbol numbers to (DFA, first) pairs, where DFA is an item from the states list above, and first is a set of tokens that can begin this grammar rule (represented by a dict whose values are always 1). labels -- a list of (x, y) pairs where x is either a token number or a symbol number, and y is either None or a string; the strings are keywords. The label number is the index in this list; label numbers are used to mark state transitions (arcs) in the DFAs. start -- the number of the grammar's start symbol. keywords -- a dict mapping keyword strings to arc labels. tokens -- a dict mapping token numbers to arc labels. c C sX i | _ i | _ g | _ i | _ d g | _ i | _ i | _ i | _ d | _ d S)Nr �EMPTY� )r r ) � symbol2number� number2symbol�states�dfas�labels�keywords�tokens�symbol2label�start)�self� r �:/opt/alt/python35/lib64/python3.5/lib2to3/pgen2/grammar.py�__init__M s zGrammar.__init__c C s? t | d � �) } t | j � } t j | | d � Wd QRXd S)a� Dump the grammar tables to a pickle file. dump() recursively changes all dict to OrderedDict, so the pickled file is not exactly the same as what was passed in to dump(). load() uses the pickled file to create the tables, but only changes OrderedDict to dict at the top level; it does not recursively change OrderedDict to dict. So, the loaded tables are different from the original tables that were passed to load() in that some of the OrderedDict (from the pickled file) are not changed back to dict. For parsing, this has no effect on performance because OrderedDict uses dict's __getitem__ with nothing in between. �wb� N)�open�_make_deterministic�__dict__�pickle�dump)r �filename�f�dr r r r X s zGrammar.dumpc C s<