unable to catch warning in error listener

21 views
Skip to first unread message

Peter Cheung

unread,
Sep 18, 2017, 12:39:26 PM9/18/17
to antlr-discussion
Hi
   I have this "warning(125): :32:5: implicit definition of token MISSING_STATEMENT in parser". But i can't catch warning in my error listener:

public class MyBaseErrorListener extends BaseErrorListener {

public boolean compilerError = false;

@Override
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line, final int position, final String msg, final RecognitionException e) {
compilerError = true;
ModuleLib.log("ERROR :" + line + ":" + position + ": " + msg);
}

public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, BitSet ambigAlts, ATNConfigSet configs) {
ModuleLib.log("reportAmbiguity");
}

public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet conflictingAlts, ATNConfigSet configs) {
ModuleLib.log("reportAttemptingFullContext");
}

public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, ATNConfigSet configs) {
ModuleLib.log("reportContextSensitivity");
}
}

Tool tool = new Tool();
Grammar grammar = tool.createGrammar(ast);
tool.process(grammar, false);
MyBaseErrorListener errorListener = new MyBaseErrorListener();
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
ParserInterpreter parser = grammar.createParserInterpreter(tokenStream);
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);

String startRule = "assemble";
Rule start = grammar.getRule(startRule);
ParserRuleContext parserRuleContext = parser.parse(start.index);

thanks
from Peter (mche...@hotmail.com)

Mike Lischke

unread,
Sep 19, 2017, 7:36:55 AM9/19/17
to antlr-di...@googlegroups.com

> I have this "warning(125): :32:5: implicit definition of token MISSING_STATEMENT in parser". But i can't catch warning in my error listener:

No wonder, this warning is issued by ANTLR when generating the files from the grammar, not your parser.

>
> public class MyBaseErrorListener extends BaseErrorListener {

Mike
--
www.soft-gems.net

Reply all
Reply to author
Forward
0 new messages