<s> """<STR_LIT>""" <EOL> import featureSpecification <EOL> import ellyBits <EOL> _dfrs = ellyBits . EllyBits ( ) <EOL> _dfrs . complement ( ) <EOL> class BasicRule ( object ) : <EOL> """<STR_LIT>""" <EOL> _index = <NUM_LIT:0> <EOL> def __init__ ( self , typ , fet ) : <EOL> """<STR_LIT>""" <EOL> self . cogs = None <EOL> self . gens = None <EOL> self . styp = typ <EOL> self . sfet = fet <EOL> self . sftr = _dfrs <EOL> self . bias = <NUM_LIT:0> <EOL> self . seqn = BasicRule . _index <EOL> BasicRule . _index += <NUM_LIT:1> <EOL> @ staticmethod <EOL> def ruleCount ( ) : <EOL> """<STR_LIT>""" <EOL> return BasicRule . _index <EOL> class ExtendingRule ( BasicRule ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , typ , fet , frs = _dfrs ) : <EOL> """<STR_LIT>""" <EOL> super ( ExtendingRule , self ) . __init__ ( typ , fet ) <EOL> self . utfet = featureSpecification . FeatureSpecification ( None ) <EOL> self . sftr = frs <EOL> self . nmrg = <NUM_LIT:1> <EOL> def __unicode__ ( self ) : <EOL> """<STR_LIT>""" <EOL> bhx = self . sfet . hexadecimal ( False ) + '<STR_LIT:->' + self . sftr . hexadecimal ( False ) <EOL> syn = unicode ( self . styp ) + '<STR_LIT:[>' + bhx + '<STR_LIT:]>' <EOL> msk = unicode ( self . utfet ) <EOL> cgs = '<STR_LIT>' + str ( self . cogs != None ) <EOL> return unicode ( self . seqn ) + '<STR_LIT>' + syn + '<STR_LIT>' + '<STR_LIT>' + msk + cgs <EOL> class SplittingRule ( BasicRule ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , typ , fet , frs = _dfrs ) : <EOL> """<STR_LIT>""" <EOL> super ( SplittingRule , self ) . __init__ ( typ , fet ) <EOL> self . ltfet = featureSpecification . FeatureSpecification ( None ) <EOL> self . rtfet = featureSpecification . FeatureSpecification ( None ) <EOL> self . sftr = frs <EOL> self . rtyp = - <NUM_LIT:1> <EOL> self . nmrg = <NUM_LIT:2> <EOL> def __unicode__ ( self ) : <EOL> """<STR_LIT>""" <EOL> lms = str ( self . ltfet ) <EOL> rms = str ( self . rtfet ) <EOL> ryn = unicode ( self . rtyp ) + '<STR_LIT:U+0020>' + rms <EOL> bhx = self . sfet . hexadecimal ( False ) + '<STR_LIT:->' + self . sftr . hexadecimal ( False ) <EOL> syn = unicode ( self . styp ) + '<STR_LIT:[>' + bhx + '<STR_LIT:]>' <EOL> cgs = '<STR_LIT>' + str ( self . cogs != None ) <EOL> return unicode ( self . seqn ) + '<STR_LIT>' + syn + '<STR_LIT>' + '<STR_LIT>' + lms + '<STR_LIT:U+0020>' + ryn + cgs <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import symbolTable <EOL> sym = symbolTable . SymbolTable ( ) <EOL> fs = featureSpecification . FeatureSpecification ( sym , '<STR_LIT>' ) <EOL> pf = fs . positive <EOL> nf = fs . negative <EOL> nf . complement ( ) <EOL> print '<STR_LIT>' , pf , nf <EOL> r = [ ] <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> ru = ExtendingRule ( <NUM_LIT:0> , pf , nf ) <EOL> r . append ( ru ) <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> ru = SplittingRule ( <NUM_LIT:0> , pf , nf ) <EOL> r . append ( ru ) <EOL> rr = ExtendingRule ( <NUM_LIT:0> , pf ) <EOL> r . append ( rr ) <EOL> for ru in r : <EOL> print type ( ru ) , unicode ( ru ) <EOL> print '<STR_LIT>' , BasicRule . ruleCount ( ) </s>
