Replies: 2 comments 15 replies
-
As I am still not completely clear on all this, too, I'll first start with "ambigAlts". Yes, it is a bitset of the number alts that are in conflict. For example,
For rule 2 ("x"), there are two "alts": However, alts can be nested, e.g., As far as I know, there is nothing in the runtime API that gives the alternative from an alt number. In fact, there is nothing it seems to go from a NFA state number back to a position in the grammar. (I would like this in order to implement LR0 items.) (Note: I'm trying to figure all this out because I offer a command-line toolkit to debug grammars. trperf implements the "performance" panel in the Intellij Antlr plugin in a command-line interface. This comes in handy with the usual Bash commands sort, uniq, column, etc. IDEs cannot be used in scripts to automate grammar debugging and refactoring.) |
Beta Was this translation helpful? Give feedback.
-
Basically though, you can read your rules left to right and count. But Box
grammar is really only ambiguous because of keywords being allowed as
identifiers.
Brad - content out the keyword alt in the id rule.
…On Wed, Sep 11, 2024 at 19:32 Ken Domino ***@***.***> wrote:
"configs" is a collection of "closures" from a state. In the classic
definition from graph theory, the transitive closure G* of a directed graph
G is a graph that has an edge (u, v) whenever G has a directed path from u
to v. In Antlr, we're especially interested in NFA states that have epsilon
transitions (i.e., no input is required to move to the target state). Also,
an NFA can "call" another NFA for another rule. In Antlr, the closure of an
NFA state is a "config," which is a sequence of "calls" and "returns." It
represents a DFA state.
The main issue with configs is that I don't think it is that useful in
understanding ambiguity. You can use the state numbers in the config to
show the rules for a possible derivation, but it doesn't show you the
actual different parse trees possible. ParserInterpreter
<https://github.com/antlr/antlr4/blob/811b7fda58bd14d7f0abc496b6fd651dfa01ed97/runtime/Java/src/org/antlr/v4/runtime/ParserInterpreter.java>
is code that can enumerate the different parse trees in an ambiguous parse
<https://github.com/antlr/antlr4/blob/811b7fda58bd14d7f0abc496b6fd651dfa01ed97/tool/src/org/antlr/v4/tool/GrammarParserInterpreter.java#L200-L310>.
The main problem for me is that much of this code does not exists in the
CSharp target.
—
Reply to this email directly, view it on GitHub
<#4693 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMC7KIAG4Z3SYGCP54TZWDVKLAVCNFSM6AAAAABN62KETSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANRSGA2TOMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Cross-posted from here.
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
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
Beta Was this translation helpful? Give feedback.
All reactions