!7 abstract sclass InFlight { L actions() { null; } abstract L consumeToken(S token); } InFlight > JustAction { O action; *() {} *(O *action) {} L actions() { ret ll(action); } L consumeToken(S token) { null; } } InFlight > AcceptWord { S word; InFlight next; *() {} *(S *word, InFlight *next) {} L consumeToken(S token) { if (!eqic(token, word)) null; ret ll(next); } } sclass Parsing { Iterator it; new L inFlight; *(S text, InFlight... l) { addAll(inFlight, l); it = javaTokC(text).iterator(); } void run { actions(); while (it.hasNext()) step(); } void step { S token = it.next(); new L l2; for (InFlight f : inFlight) addAll(l2, f.consumeToken(token)); print("New number: " + l(l2)); inFlight = l2; actions(); } void actions { for (InFlight f : inFlight) for (O action : unnull(f.actions())) runAction(action); } void runAction(O o) { print("Action! " + struct(o)); } } p { Parsing pp = new Parsing("I am here", JustAction("start"), AcceptWord("yes", JustAction("yes")), AcceptWord("i", AcceptWord("am", AcceptWord("here", JustAction("I am here!")); pp.run(); }