Class DiagnosticErrorListener

  • All Implemented Interfaces:
    ANTLRErrorListener

    public class DiagnosticErrorListener
    extends BaseErrorListener
    This implementation of ANTLRErrorListener can be used to identify certain potential correctness and performance problems in grammars. "Reports" are made by calling Parser.notifyErrorListeners(java.lang.String) with the appropriate message.
    • Ambiguities: These are cases where more than one path through the grammar can match the input.
    • Weak context sensitivity: These are cases where full-context prediction resolved an SLL conflict to a unique alternative which equaled the minimum alternative of the SLL conflict.
    • Strong (forced) context sensitivity: These are cases where the full-context prediction resolved an SLL conflict to a unique alternative, and the minimum alternative of the SLL conflict was found to not be a truly viable alternative. Two-stage parsing cannot be used for inputs where this situation occurs.
    Author:
    Sam Harwell
    • Field Detail

      • exactOnly

        protected final boolean exactOnly
        When true, only exactly known ambiguities are reported.
    • Constructor Detail

      • DiagnosticErrorListener

        public DiagnosticErrorListener()
        Initializes a new instance of DiagnosticErrorListener which only reports exact ambiguities.
      • DiagnosticErrorListener

        public DiagnosticErrorListener​(boolean exactOnly)
        Initializes a new instance of DiagnosticErrorListener, specifying whether all ambiguities or only exact ambiguities are reported.
        Parameters:
        exactOnly - true to report only exact ambiguities, otherwise false to report all ambiguities.
    • Method Detail

      • reportAttemptingFullContext

        public void reportAttemptingFullContext​(Parser recognizer,
                                                DFA dfa,
                                                int startIndex,
                                                int stopIndex,
                                                BitSet conflictingAlts,
                                                ATNConfigSet configs)
        Description copied from interface: ANTLRErrorListener
        This method is called when an SLL conflict occurs and the parser is about to use the full context information to make an LL decision.

        If one or more configurations in configs contains a semantic predicate, the predicates are evaluated before this method is called. The subset of alternatives which are still viable after predicates are evaluated is reported in conflictingAlts.

        This method is not used by lexers.

        Specified by:
        reportAttemptingFullContext in interface ANTLRErrorListener
        Overrides:
        reportAttemptingFullContext in class BaseErrorListener
        Parameters:
        recognizer - the parser instance
        dfa - the DFA for the current decision
        startIndex - the input index where the decision started
        stopIndex - the input index where the SLL conflict occurred
        conflictingAlts - The specific conflicting alternatives. If this is null, the conflicting alternatives are all alternatives represented in configs. At the moment, conflictingAlts is non-null (for the reference implementation, but Sam's optimized version can see this as null).
        configs - the ATN configuration set where the SLL conflict was detected
      • getDecisionDescription

        protected String getDecisionDescription​(Parser recognizer,
                                                DFA dfa)
      • getConflictingAlts

        protected BitSet getConflictingAlts​(BitSet reportedAlts,
                                            ATNConfigSet configs)
        Computes the set of conflicting or ambiguous alternatives from a configuration set, if that information was not already provided by the parser.
        Parameters:
        reportedAlts - The set of conflicting or ambiguous alternatives, as reported by the parser.
        configs - The conflicting or ambiguous configuration set.
        Returns:
        Returns reportedAlts if it is not null, otherwise returns the set of alternatives represented in configs.