How to catch the exception in the lexer? In parser if a rule is failed (or mismatched with the given input stream ) Antlr will throw the exception and we can easily catch this exception.Catch the exception in the lexer in Antlr3.Ref:Error handeling in antlr 3.0...
attribute :
Value1 integer1["Value1"] { System.out.println("Accepted"); }
| Value2 integer2["Value2"] { System.out.println("Accepted"); }
;
catch[Exception e] {System.out.println("General error Reported");}
It will work in parser.But how can I catch the exception in the lexer itself?.Say in parser I am having the rule like
str:STRING|DIGIT;
and in lexer STRING is defined as
STRING : ('"' 'a'..'z' '"');
My input stream is "God"....If I miss the double quote or if I put the extra double quote then I want that exception should be caught in the lexer itself...Is there any method to do this? Is it possible?