[antlr-interest] C target: How to handle lexer exceptions??

register reg.ini register72 at gmail.com
Tue Apr 7 03:08:37 PDT 2009


I add another small detail that seems to me more of a  bug than a feature:

The reportError function in antlr3lexer.c does not increment the
state->errorCount
attribute of the recognizer and this is why
lxr->pLexer->rec->getNumberOfSyntaxErrors(lxr->pLexer->rec)
always returns 0;

Luca

On Tue, Apr 7, 2009 at 10:20 AM, register reg.ini <register72 at gmail.com>wrote:

> I have done a little more research and found that the lexer main loop is
> found in the nextTokenStr function.
> This function handles lexer exceptions and tries to recover from them. This
> means that after a successful recovery the
>
> lexer->rec->state->error and  lexer->rec->state->failed attributes are set
> to FALSE and that the final state of the lexer does not necessarily contain
> information about previous occurred errors. It seems to me that I have to
> overload lexer's reportError or displayRecognitionError functions in a way
> suitable for my needs. Does the C runtime provide a facility to embed this
> overload directly in the grammar (like java's @member or *catch* sections
> ) or should I add the overload in the generated code?
>
> Thanks,
>
> Luca
>
>
> P.S: Tim, sorry for posting my previous mail only to you and not on the
> mailing list. I didn't mean to be rude: I just hit the wrong button.
>
>
>   On Mon, Apr 6, 2009 at 5:37 PM, register reg.ini <register72 at gmail.com>wrote:
>
>> Sorry to ask more questions but I am hitting a stumbling block.
>>
>> I tryed the following since it is the only thing that makes sense to me
>> after reading the source code:
>>
>>
>> tstream->tstream->_LT(tstream->tstream, 1);
>>
>> pANTLR3_LEXER lexer;
>>
>> lexer = (pANTLR3_LEXER)(tstream->tstream->tokenSource->super);
>>
>> size_t nerr=lexer->rec->getNumberOfSyntaxErrors(lexer->rec);
>>
>> if(nerr!=0)
>>
>> printf(
>> "Syntax errors \n");
>>
>>
>>
>> but this does not work. I really don't understand the relation between the
>> recognizers, lexers and parsers....
>>
>> Also I really don't understand why one should use a catch all lexer rule
>> like ANY: how could I then detect the offending lexer rule? I don't see any
>> example of this pattern anywhere ( I own Terence's book) maybe a few
>> examples could help in clarifying matters.
>>
>> Thanks for your help, I really appreciate it very much.
>>
>> Regards,
>>
>> Luca
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090407/95c19191/attachment.html 


More information about the antlr-interest mailing list