Reductions need to be performed in a careful order in GLR parser, to
make sure we gather all alternatives before creating an ambigous forest
node.
This patch encodes the nonterminal order into the rule id, so that we
can efficiently to determinal ordering of reductions in GLR parser.
This patch also abstracts to a TestGrammar, which is shared among tests.
This is a part of the GLR parser, https://reviews.llvm.org/D121368,
https://reviews.llvm.org/D121150
I think it's easier to understand if we sort the *symbols* and leave this comment as-is.
It feels a bit strange to sort the symbols alphabetically but sort the rules by some other property of the symbols.
It's also important to describe what relation we're sorting by!
I'd say "The symbols are topologically sorted: if S := T then S has a higher SymbolID than T."