Meena Vinod wrote:
Hi,
  Is there a way where in if there is a lexer error,the antlr reports the error and exits without creating the parser for it ?
for ex:
In the calling program:

 

lex = LexerNew(input);

if (lex == NULL)

{

fprintf(stderr, "Unable to create the lexer due to malloc() failure1\n");

exit(ANTLR3_ERR_NOMEM);

}

tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lex));

 

if (tokens == NULL)

{

fprintf(stderr, "Out of memory trying to allocate token stream\n");

exit(ANTLR3_ERR_NOMEM);

}

//want the lexer to exit here only in case of a lexer error


Invoke the lexer separately by asking for the first token. This will cause the tokens to be gathered (the lexer will run to completion). Then check if it issued any errors (you should probably override the error reporting mechanism) and stop if it did.

However, you should code your lexer such that it does not give errors, at least not from the runtime. See lots of past posts about this on this list. Ideally, you want your process to go as far as it can without giving up such that your end user receives as much information as possible about what is wrong before having to run your parser again. See:

http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+point%2C+dot%2C+range%2C+time+specs

For some concrete examples.

Jim

--~--~---------~--~----~------------~-------~--~----~
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/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to