<s> '''<STR_LIT>''' <EOL> from struct import * <EOL> def actioncmp ( ap1 , ap2 ) : <EOL> '''<STR_LIT>''' <EOL> rc = ap1 . sp . index - ap2 . sp . index <EOL> if rc == <NUM_LIT:0> : <EOL> rc = ap1 . type - ap2 . type <EOL> if rc == <NUM_LIT:0> and ap1 . type == REDUCE : <EOL> rc = ap1 . x . rp . index - ap2 . x . rp . index <EOL> assert rc != <NUM_LIT:0> or ap1 == ap2 <EOL> return rc <EOL> def Action_sort ( ap ) : <EOL> '''<STR_LIT>''' <EOL> from msort import msort <EOL> ap = msort ( ap , '<STR_LIT>' , actioncmp ) <EOL> return ap <EOL> def Action_add ( app , type , sp , arg ) : <EOL> new = action ( <EOL> next = app , <EOL> type = type , <EOL> sp = sp , <EOL> collide = None , <EOL> stp = None , <EOL> rp = None , <EOL> ) <EOL> app = new <EOL> if type == SHIFT : <EOL> new . x . stp = arg <EOL> else : <EOL> new . x . rp = arg <EOL> return app </s>
