Thanks for your very quick response. Now i have understood how lexer and parser works. 1. As i have set of commands to parse if there is any unknown command found it breaks the parsing and returns with the error. But how to continue the parsing even though it finds unknown command after returning the error.
I have added the functions "getErrorMessage(RecognitionException e, String[] tokenNames), getTokenErrorDisplay(Token t) to a grammar file. 2. Added package at the beginning of header to grammar code. I could see the package name for parser file but not for the lexer. Why? - regards Virg On Wed, Dec 3, 2008 at 12:13 PM, Gavin Lambert <[EMAIL PROTECTED]> wrote: > At 18:28 3/12/2008, virg g wrote: > >> ok. Is there anyway i can mention the commands and its paramters without >> mentioning them in the quotes? >> > > Yes -- either declare a named token for it instead (as you did for TESTCMD) > or define an explicit lexer rule: > > CMD : 'CMD'; > > Then you can refer to it as CMD in all the parser rules instead of 'CMD', > and it'll have a nicer name in the generated code to boot. > > Eliminating quoted constants from parser rules like this will also let you > group all of your lexer rules together in one place, making it easier to > spot surprises and harder to forget that ANTLR is not a scannerless parser. > > The literal rule is combination of "OR" of Number, ALPHA and STRING. So >> for the command " TESTCMD CNT=2 VAL=TYPE:CNT" where for VAL paramters CNT >> will match ALPHA lexer rule right? as it works if it is "TEST". Otherwise i >> have to add expilcitely all the quoted values to "literal" rule like this. >> sorry if understanding is wrong. >> >> literal : (NUMBER|ALPHA|STRING |TESTCMD|'CNT'|'VAL'|'TYPE') >> > > Nope, that's exactly right (that you do have to explicitly mention them, I > mean). As each of those are unique token types, if you want 'literal' to > match all of them then you have to actually mention all of them. > > Despite the string "CNT" being *compatible* with the rule ALPHA, the simple > fact is that when the lexer ran it didn't generate an ALPHA, it generated a > CNT (or a T14, or whatever). The parser doesn't know that this is > acceptable where an ALPHA is unless you tell it. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
