Okay you know what? I give up. This seems to be some kind of weird pastiche of copy-pasted code with no effort made to make it clear what is going on. So I'm not even going to try to understand and review the rest of this until you clean it up.

Some guidelines:

* Variables and state/nonterminal ids need to be descriptive. Not "Foo-s-5", not "ThingHelper", not "SpecialThing", not "WrappedThing", etc. Actually describing the states and nonterminals they correspond to.
* Update the diagram so that it contains a clear flow of StateIds with a basic example.

Also, it's not clear to me why you