[antlr-interest] Extracting meaning out of Antlr's exceptions
rmsanjivp <rmsanjivp at yahoo.com>
rmsanjivp at yahoo.com
Thu Jan 23 22:45:58 PST 2003
Hi!
I am trying to make out a meaningful error message from the
exception thrown by the Antlr. I am catching the exception in the
grammar rule and trying to make out the meaning. Consider the
following:
expr: m1:mult_expr ( (p:PLUS | m:MINUS) m2:mult_expr)*;
exception
catch[TokenStreamException ex]
{
// will this section catch unrecognized symbol from the lexer
}
catch[RecognitionException ex]
{
// I want to make a decision if the operator is missing or
// operand is missing. Will the following code help??
if( p == NULL && m == NULL)
printf("Operator Missing\n")
else if( (p != NULL || m != NULL) && #m2 == NULL)
printf("OPerand Missing\n");
}
Similar kind of exception handling for mult_expr rule.
I want to know how to make what is the real problem. I can have an
input that has unrecognized symbol by lexer. How do I catch that in
the exception handler in the grammar? I have gone through the list
of ecception thrown on different problems. I found that
RecognitionException handles both unrecognized input from the lexer
and unexpected token from the input. How do I differentiate between
them? Is there a way to catch these exception and generate really
meaningfule messages??
Is the way I catch exception in the rule fine?
Kindly advise.
Thanks,
Sanjiv
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list