c# 4.0 - How to collect errors during run time given by a parser in Antlr4 -
i have upgraded antlr 3 antlr 4. using code catch exceptions using code. not working antlr 4.
partial class xparser { public override void reporterror(recognitionexception e) { base.reporterror(e); console.writeline("error in parser @ line " + ":" + e.offendingtoken.column + e.offendingtoken.line + e.message); } }
this error appears
'parser.reporterror(antlr4.runtime.recognitionexception)': no suitable method found override
in antlr 4 expected way of accumulating errors occurs in input stream. unable find way achieve on net. please provide me guidelines.
edit:
i have implemented xparser below
partial class xparser : iantlrerrorlistener<itoken> { public void syntaxerror(irecognizer recognizer, itoken offendingsymbol, int line, int charpositioninline, string msg, recognitionexception e) { console.writeline("error in parser @ line " + ":" + e.offendingtoken.column + e.offendingtoken.line + e.message); } }
as said can extend parser class using of mentioned classes. unable register listener, in main program confused passing argument listener
. please me registering.
as can see these classes has capability of producing more meaningful error messages don't they?
you need implement iantlrerrorlistener<itoken>
. if want report errors have above, should focus on syntaxerror
method. several base classes available if want extend one.
the error listener attached parser instance calling parser.adderrorlistener(listener)
.
edit: need create new class implements error listener interface. attach listener parser. parser not implement error listener interface.
Comments
Post a Comment