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 A1 [] def A2 [] def start [A1 item* `^] | [A2 item* `; NL] { for I: item in Map print "map el: [I] } end Undo: undo = new undo() Undo->Map = new map() parse Input: undo::start(Undo)[ stdin ] print( Input ) ###### IN ####### a b c ( d e ) f; ###### EXP ####### map el: ( d e ) map el: a map el: b map el: c map el: d map el: e map el: f a b c ( d e ) f;