Arun Ramakrishnan
2012-11-29 19:12:35 UTC
As the title suggests, I want to exit upon any recognition error and
disable any recovery mechanisms.
using antlr 3.4.
I am trying out the instructions in the book ANTLR definitive reference.
********* QUOTE FROM BOOK *****************
To make your recognizer (parser or tree parser) exit immediately upon
recognition error, you must override two methods, mismatch( ) and
recoverFromMismatchSet( ), and alter how the parser responds to thrown
exceptions.
Download errors/Bail.g
grammar Bail;
@members {
protected void mismatch(IntStream input, int ttype, BitSet follow)
throws RecognitionException
{
throw new MismatchedTokenException(ttype, input);
}
public void recoverFromMismatchedSet(IntStream input,
RecognitionException e,
BitSet follow)
throws RecognitionException
{
throw e;
}
}
// Alter code generation so catch-clauses get replace with
// this action.
@rulecatch {
catch (RecognitionException e) {
throw e;
}
}
*****************************************************
Here is the couple of problems.
a) the mismatch method doset exist in my parser inheritance chain ( neither
in Parser or BaseRecognizer )
b) the recoverFromMismatchedSet
method<https://github.com/antlr/antlr3/blob/master/runtime/Java/src/main/java/org/antlr/runtime/BaseRecognizer.java#L588>return
type is Object not void.
c) It is for this reason its always a good idea to annotate overriden
methods.
d) The book just says override these methods without much on what these
methods are supposed to do.
Anyone know how to go about this.
thanks
Arun
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
disable any recovery mechanisms.
using antlr 3.4.
I am trying out the instructions in the book ANTLR definitive reference.
********* QUOTE FROM BOOK *****************
To make your recognizer (parser or tree parser) exit immediately upon
recognition error, you must override two methods, mismatch( ) and
recoverFromMismatchSet( ), and alter how the parser responds to thrown
exceptions.
Download errors/Bail.g
grammar Bail;
@members {
protected void mismatch(IntStream input, int ttype, BitSet follow)
throws RecognitionException
{
throw new MismatchedTokenException(ttype, input);
}
public void recoverFromMismatchedSet(IntStream input,
RecognitionException e,
BitSet follow)
throws RecognitionException
{
throw e;
}
}
// Alter code generation so catch-clauses get replace with
// this action.
@rulecatch {
catch (RecognitionException e) {
throw e;
}
}
*****************************************************
Here is the couple of problems.
a) the mismatch method doset exist in my parser inheritance chain ( neither
in Parser or BaseRecognizer )
b) the recoverFromMismatchedSet
method<https://github.com/antlr/antlr3/blob/master/runtime/Java/src/main/java/org/antlr/runtime/BaseRecognizer.java#L588>return
type is Object not void.
c) It is for this reason its always a good idea to annotate overriden
methods.
d) The book just says override these methods without much on what these
methods are supposed to do.
Anyone know how to go about this.
thanks
Arun
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address