<s> """<STR_LIT>""" <EOL> import pickle <EOL> class Grammar ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . symbol2number = { } <EOL> self . number2symbol = { } <EOL> self . states = [ ] <EOL> self . dfas = { } <EOL> self . labels = [ ( <NUM_LIT:0> , "<STR_LIT>" ) ] <EOL> self . keywords = { } <EOL> self . tokens = { } <EOL> self . symbol2label = { } <EOL> self . start = <NUM_LIT> <EOL> def dump ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> with open ( filename , "<STR_LIT:wb>" ) as f : <EOL> pickle . dump ( self . __dict__ , f , <NUM_LIT:2> ) <EOL> def load ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> with open ( filename , "<STR_LIT:rb>" ) as f : <EOL> d = pickle . load ( f ) <EOL> self . __dict__ . update ( d ) <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> new = self . __class__ ( ) <EOL> for dict_attr in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) : <EOL> setattr ( new , dict_attr , getattr ( self , dict_attr ) . copy ( ) ) <EOL> new . labels = self . labels [ : ] <EOL> new . states = self . states [ : ] <EOL> new . start = self . start <EOL> return new <EOL> def report ( self ) : <EOL> """<STR_LIT>""" <EOL> from pprint import pprint <EOL> print ( "<STR_LIT>" ) <EOL> pprint ( self . symbol2number ) <EOL> print ( "<STR_LIT>" ) <EOL> pprint ( self . number2symbol ) <EOL> print ( "<STR_LIT>" ) <EOL> pprint ( self . states ) <EOL> print ( "<STR_LIT>" ) <EOL> pprint ( self . dfas ) <EOL> print ( "<STR_LIT>" ) <EOL> pprint ( self . labels ) <EOL> print ( "<STR_LIT:start>" , self . start ) </s>
