Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I get an exception thrown in the lexer to escape out to the parsers invoker?

0
Posted

How can I get an exception thrown in the lexer to escape out to the parsers invoker?

0

Location: http://www.jguru.com/faq/view.jsp?EID=127 Created: Sep 3, 1999 Author: Terence Parr (http://www.jguru.com/guru/viewbio.jsp?EID=1) [Version 2.7.0 or greater; earlier versions didn’t have the TokenStreamException hierarchy] Use a filter rule to trap invalid sequences and throw a TokenStreamRecognitionException, which is a TokenStream exception indicating that an invalid token was found. The parser or method that invokes the parser must catch this TokenStreamException. Remember that the filter option changes the behavior of your lexer. When you set a filter rule, there is no such thing as a syntax error. Anything short of a completely recognized (non-protected) lexer rule will result in the filter rule being called. In other words, the lexer will enter the filter rule with input state rewound to the way it was when the lexer was asked for a token. The following parser/lexer combo illustrates the strategy. The language is just a set of IDs separated by white space. Upon input “ab

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.