Jan Newger wrote: > Sam Harwell wrote: >> It's a good idea to override ReportError, and this will almost surely >> provide you with the results you want. You can also put a breakpoint in >> NoViableAltException's constructor. >> > > So you are proposing that I override ReportError and re-throw the > exception? I basically want this code to work as expected (taken from > http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3): > > try { > parser.expr(); > } catch (RecognitionException e) { > Console.Error.WriteLine(e.StackTrace); > } > > Since the RecognitionException is swallowed within the parser itself and > the default implementation of ReportError doesn't rethrow it by itself, > this code doesn't work as expected, i.e. the catch block can never be > executed. Correct? >
I poked a little bit through the source code of the C# runtime. IMHO the code shown above, which was taken from the antlr website, is wrong, because it implies that the RecognitionException might reach the catch block. As outlined previously, the parser will never throw this exception because each rule swallows the exception and the error condition is signlaed via the ReportError method. On the other hand, the lexer also never seems to throw this kind of exception. It seems to me that the lexer throws e.g. MismatchedTokenException, but it never throws NoViableAltException and therefore no RecognitionException. Please correct me if I'm wrong. Thanks Jan List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
