context undo lex ignore /( ' ' | '\t')+/ literal `* `( `) `^ `; token NL /'\n'/ token id /[a-zA-Z_]+/ end Map: map def item [id] { Map->insert( lhs, lhs ) } | [`( item* `)] { Map->insert( lhs, lhs ) } def no_accum_item [id] | [`( no_accum_item* `)] def A1 [] def A2 [] def start [A1 item* `^] | [A2 no_accum_item* `; NL] { for I: item in Map { print "map el: [I] } } end Undo: undo = new undo() Undo->Map = new map() cons I: undo::item "a" Undo->Map->insert( I, I ) parse Input: undo::start(Undo)[ stdin ] print( Input ) ###### IN ####### a a a ( a a ) a; ###### EXP ####### map el: a a a a ( a a ) a;