reportAttemptingFullContext - is it supposed to be fatal, or my mistake?

239 views
Skip to first unread message

rtm...@googlemail.com

unread,
Apr 13, 2022, 11:03:21 AM4/13/22
to antlr-discussion

Hi all,
I'm getting reportAttemptingFullContext problems which it dies from, the "error" report is (it does actually report a stack overflow):

line 13:34 reportAttemptingFullContext d=22 (opt_negated_predicate), input='notexists(select111asdd)'
Stack overflow.


but this <https://stackoverflow.com/questions/71056312/antlr-how-to-avoid-reportattemptingfullcontext-and-reportambiguity> says

"reportAmbiguity and reportAttemptingFullContext are not an indication that there was a syntax error. You can listen in on these events to know if they happen, but ANTLR has a deterministic approach to resolving this ambiguity (it uses the first alternative). If you do not treat those as errors, you will get a proper parse tree out of your parse."

and there is a definite ambiguity there (harmless, or should be but for ANTLR blowing up).

I don't think I've done anything clever with error handler (as seems to have happened in <https://github.com/antlr/antlr4/issues/2623>), I'm not advanced enough to do anything smart, code is simply this:

var str = new AntlrInputStream(input);
var lexer = new LDBLexer(str);
var tokens = new CommonTokenStream(lexer);
var parser = new LDBParser(tokens);
var listener = new ErrorListener<IToken>(parser, lexer, tokens);
parser.AddErrorListener(listener);
parser.AddErrorListener(new DiagnosticErrorListener(false));
lexer.AddErrorListener(new ErrorListener<int>(parser, lexer, tokens));
parser.Interpreter.PredictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION;
var tree = parser.start_parse();


so why is it erroring out? This is not critical but is a bit of a blocker for me.

thanks

jan

Terence Parr

unread,
Apr 13, 2022, 11:45:22 AM4/13/22
to antlr-di...@googlegroups.com
I don’t think it should die from that. Which target are you using?
Ter 

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/0c0f7d25-b53c-4052-80fc-36a2086d4243n%40googlegroups.com.
--
Dictation in use. Please excuse homophones, malapropisms, and nonsense.

rtm...@googlemail.com

unread,
Apr 13, 2022, 11:55:32 AM4/13/22
to antlr-discussion
Then let's assume it's something silly I've done (to be determined).

Target is C#

cheers

jan

Terence Parr

unread,
Apr 13, 2022, 12:13:42 PM4/13/22
to antlr-discussion
That stack overflow message is a bit concerning. Perhaps there is infinite recursion there somewhere?Yes there's definitely a loop here. The report function calls

  recognizer.notifyErrorListeners(message);

 which is no doubt getting back to the same listener somehow... can you try without the first of these calls:

parser.AddErrorListener(listener);
parser.AddErrorListener(new DiagnosticErrorListener(false));

Ter

rtm...@googlemail.com

unread,
Apr 13, 2022, 12:37:43 PM4/13/22
to antlr-discussion
comment out both lines, it works with (presumably correct)ambiguity msg:

>>>>  Running alt syntax check: disjunction of simple predicates negated
line 1:139 reportAttemptingFullContext d=22 (opt_negated_predicate), input='notexists(select1asdd)'
line 1:139 reportAttemptingFullContext d=22 (opt_negated_predicate), input='notexists(select1asdd)'
line 1:139 reportAmbiguity d=22 (opt_negated_predicate): ambigAlts={1, 2}, input='notexists(select1asdd)'
line 1:139 reportAmbiguity d=22 (opt_negated_predicate): ambigAlts={1, 2}, input='notexists(select1asdd)'



comment out only the 'parser.AddErrorListener(listener);'
and leaving in the 'parser.AddErrorListener(new DiagnosticErrorListener(false));'
it works with same ambig msg

HTH

Actually that ambiguity has to go (sigh, the MSSQL grammar is a bloody mess and that bleeds into the parse tree and into the AST, and ugh, it all becomes sewage) so I guess it's a non problem for me soon.

Anything else I can help with?

Terence Parr

unread,
Apr 13, 2022, 2:59:20 PM4/13/22
to antlr-discussion
I don't see this class in distribution so maybe custom thing doing wrong notifications?

var listener = new ErrorListener<IToken>(parser, lexer, tokens);

Ter


rtm...@googlemail.com

unread,
Apr 13, 2022, 3:53:57 PM4/13/22
to antlr-discussion
Assuredly I don't have the knowledge to do a custom anything. I need to get into understanding ANTLR error handling properly at some point but it isn't happening today. That line would have been cargo-culted from elsewhere, I can't recall now.

Thanks for looking at this!

jan

rtm...@googlemail.com

unread,
Apr 15, 2022, 6:34:34 AM4/15/22
to antlr-discussion
Whatever I've done obviously wasn't wise, would it be an idea to add a check in ANTLR for such mistakes?

jan

Terence Parr

unread,
Apr 15, 2022, 1:33:25 PM4/15/22
to antlr-di...@googlegroups.com
I could add a warning but I'm not sure specifically what has gone wrong.
Ter

Dictation in use. Please excuse homophones, malapropisms, and nonsense.


rtm...@googlemail.com

unread,
Apr 16, 2022, 7:36:41 AM4/16/22
to antlr-discussion
Honestly, anything that would clarify would help.

cheers

jan

Mike Cargal

unread,
Apr 17, 2022, 9:15:33 AM4/17/22
to antlr-discussion
If you can post a link to your ErrorListener, we might be able to assist (if it's small, maybe even just response with it).  

You'll make it easier for someone trying to help you if you have a code sample someone can run to see your error triggered.  

A StackOverflow, is *usually* some sort of infinite recursion (I know... obvious). I'm not sure anyone can say much more than that without taking a look at your listener.

Reply all
Reply to author
Forward
0 new messages