[antlr-interest] Bad exception handling ?
julius_siska
julius_siska at yahoo.com
Tue Aug 5 00:35:37 PDT 2003
Hi,
I have following problem. I have grammar file with tokens AK, KI, EC
and ZD. One of parsing rules is:
(AK)? (KI)? EC (ZD)?
Parsed input stream contains just tokens:
AK ZD
(obviously missing EC token)
Relevant part of generated Java parser code to my grammar is as
follows (for brevity I ommit unnecessary curly braces):
switch ( LA(1)) {
case AK:
match(AK);
break;
case KI:
case EC:
break;
default:
throw new NoViableAltException(LT(1), getFilename());
}
switch ( LA(1)) {
case KI:
match(KI);
break;
case EC:
break;
default:
!!! throw new NoViableAltException(LT(1), getFilename());
}
match(EC);
During parsing, is in line marked by !!! thrown NoViableAltException,
because in the stream is not the EC token present.
But the parser just print error message line:xxx:y: unexpected token
ZD. Thrown exception is caught somewehre inside ANTLR, but I would
need to have it thrown outside to know that something is wrong in my
program. I think this exception should be thrown from parser.file()
method.
Can somebody help me, how to get this exception out of ANTLR and into
my program where I can handle it and reject such input stream ?
Thanks in advance,
Julius Siska
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list