maybe you can make StateId have an integer component? And then precompute this BiMap as you add states to the grammar?