0

EDIT 2: Full edit.

So, I want to implement an ErrorListener in my code. But I have a few problems and I have no idea how to solve them. Searching for Java equivalents was my first idea, but not many seem to do anything with the ErrorListener, which makes it harder for me.

So, this is my ErrorListener:

public class CodeError : BaseErrorListener
{
    public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
    {
                 Console.WriteLine("Error in parser at line " + ":" + e.OffendingToken.Column + e.OffendingToken.Line + e.Message);
                 base.SyntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
    }

And that's how I implemented it in my main code:

Debugger.CodeError ld = new Debugger.CodeError();
parser.AddErrorListener(ld);

I tried it and I always got this error: test

Community
  • 1
  • 1
  • Please don't post screenshots of your code, instead just paste it here, select it and hit Ctrl+K. The C# way is the same, in your case I guess `OffendingToken` is `null`, but as *"didn't work"* is not a meaningful problem statement it's impossible to answer this question accurately without the full error message. – Lucas Trzesniewski Mar 21 '15 at 14:09
  • @LucasTrzesniewski Edited the question. Hope it's more clear now. – Tetragrammaton Mar 21 '15 at 14:16
  • 1
    Yeah, most probably `OffendingToken` is `null` (see that `ReportMissingToken` call? there's no *offending* token). See [this question](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) for more instructions about resolving this. – Lucas Trzesniewski Mar 21 '15 at 14:50

0 Answers0