I'm delving into the parser profiling features, which I found referenced in
this article on parser performance. I'm using the Java runtime 4.x. That article has some simple code for enabling profiling and then outputting the details (which I converted from Kotlin to Java). I'm specifically digging into some ambiguities in my grammar(s) for the sake of increasing performance and allowing SLL prediction. I understand at a high level what creates ambiguities, but I'm struggling a little to determine how to interpret the information in the AmbiguityInfo instances returned by the profiler. I've done a few hours of research on Google and in the source and came up mostly empty handed. I'm aware there are some nice IntelliJ tools, but I'm not using that IDE right now and would like to still develop an understanding of what the data means on my own outside of any particular tool.
So, looking at each AmbiguityInfo instance returned by the profiler, I can get
- the rule name via the decision property (which appears to be the same as the rule name in the containing DecisionInfo class)
- The start/stop index, which I can use to get the related source from the input tokenstream
- I'm not sure how to read fullCtx, or what it means in terms that I care about or if it's just telling me the predication mode I had configured, which is obviously information I already know.
- ambigAlts bitset is a bit of a mystery in terms of turning it into something meaningful. I understand at a high level it is meant to represent the alternatives that were ambiguous, but I don't know how to map the ints in the bitset back to the actual parts of the grammar they represent. Especially when the rue in question has no explicit alternatives (using a pipe). I mean, I get how a rule with no explicit alternatives but containing asterisks or pluses can have multiple paths through, I just don't know how to take the ambigAlts bit set and translate that to the specific portions of the grammar they represent.
- configs is just a huge amount of information that I can't get to make sense in a meaningful way. I'm not not clear if all the configs related directly to the ambiguity at hand, or if it's just everything the parser knew about at the time. I found a handy bit of code
config.context.toStrings( parser, config.state.stateNumber )
which appears to print out a rule stack for each config, but it's not clear which of these configs relate to the specific ambiguity or what to do with the information.
I have more specific examples I can share, and the grammars are open source so I don't mind sharing them as well, but I wanted to wait to get off in the deep weeds of that and just see if I could get some direction on how to interpret the ambiguity info classes in order to create some visualization tools for myself.
Thanks!
~Brad