[antlr-interest] @rulecatch in a C environment

Jim Idle jimi at temporal-wave.com
Wed Apr 9 09:55:39 PDT 2008


Doh! we should pay attention the error! ;-)

This method is part of the recognizer interface, hence it is not in the parser context, but the parser context's recognizer pointer:

@parser::apifuncs
{
	RECOGNIZER->displayRecognitionError = xxxxx;
}

> -----Original Message-----
> From: Pierre Attar [mailto:pat at tireme.fr]
> Sent: Wednesday, April 09, 2008 9:03 AM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] @rulecatch in a C environment
> 
> Jim,
> 
> I've tried this right capitalization before, this morning in France,
> and it does not works too :
> .. FFormParser.c(326) : error C2039: 'displayRecognitionError' : is not
> a member of 'FFormParser_Ctx_struct'
>     ..FFormParser.h(317) : see declaration of 'FFormParser_Ctx_struct'
> 
> Any other idea ?
> 
> Pierre
> 
> Jim Idle a écrit :
> > Pierre,
> >
> > The capitalization is wrong, it is:
> >
> > displayRecognitionError
> >
> > Jim
> >
> >
> >> -----Original Message-----
> >> From: Pierre Attar [mailto:pat at tireme.fr]
> >> Sent: Wednesday, April 09, 2008 5:53 AM
> >> To: Jim Idle
> >> Cc: antlr-interest at antlr.org
> >> Subject: Re: [antlr-interest] @rulecatch in a C environment
> >>
> >> Jim,
> >>
> >> Thanks a lot for your answer. I've now remove all "after" clauses
> and
> >> try to work on the displayrecognitionError function.
> >>
> >> As you should have notice, I'm not a C guru and trying to do your
> mind,
> >> I got the following error :
> >>
> >> ..FFormParser.c(326) : error C2039: 'displayrecognitionError' : is
> not
> >> a
> >> member of 'FFormParser_Ctx_struct'
> >> 2>        ..\antlrgen\FFormParser.h(317) : see declaration of
> >> 'FFormParser_Ctx_struct'
> >>
> >> Which means, I assume, that I also need somewhere to declare the my
> >> overwriting function? Can you explain me the way to do that ?
> >>
> >> Pierre
> >>
> >> Jim Idle a écrit :
> >>
> >>> We need to add better support so that targets can tell you whether
> >>>
> >> the section you are using is supported. @after currently isn't
> >> officially supported though I have been playing around with it.
> >>
> >>> Rather than try to do this through things like rule catch, just
> >>>
> >> override the displayRecognitionError routine, or routines tath are
> >> called before that is called if you find a need.
> >>
> >>> At that point you can find out everything you would normally need
> to
> >>>
> >> know, including what rule/alt the parser was in and the expected
> token
> >> set (if this can be worked out) and so on.
> >>
> >>> >From the C API docs:
> >>>
> >>> Unless you wish to create your own tree structures using the built
> in
> >>>
> >> ANTLR AST rewriting
> >>
> >>> notation, you will rarely need to override the default
> implementation
> >>>
> >> of runtime methods. The
> >>
> >>> exception to this will be the syntax err reporting method, which is
> >>>
> >> essentially a stub function
> >>
> >>> that you will usually want to provide your own implementation for.
> >>>
> >> You should consider the built in function
> >>
> >>> displayRecognitionError() as an example of where to start as there
> >>>
> >> can be no really useful
> >>
> >>> generic error message display.
> >>>
> >>>
> >>> In your grammar you can do this:
> >>>
> >>> @parser::apifuncs
> >>> {
> >>> 	// Override the standard error display and install my own.
> >>>       // Look at the runtime library code to see what the default
> one
> >>>       // does to find things out, then do what I want in my
> version.
> >>>       ..
> >>> 	ctx->displayrecognitionError = myDisplayrecognitionError;
> >>> }
> >>>
> >>> Jim
> >>>
> >>>
> >>>
> >>>> -----Original Message-----
> >>>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >>>> bounces at antlr.org] On Behalf Of Pierre Attar
> >>>> Sent: Tuesday, April 08, 2008 6:14 AM
> >>>> To: antlr-interest at antlr.org
> >>>> Subject: [antlr-interest] @rulecatch in a C environment
> >>>>
> >>>> Hi,
> >>>>
> >>>> I want to catch recognition errors on my parsing. In order to
> >>>>
> >> achieve
> >>
> >>>> this, I've creating the following rulecatch:
> >>>>
> >>>> @rulecatch {
> >>>>     pANTLR3_EXCEPTION exe = EXCEPTION;
> >>>>     if(NULL != exe) {
> >>>>         char    buffer[100];
> >>>>         sprintf(buffer, "\%s", exe->name);
> >>>>         cout << "Got an exception in parsing recognition: " <<
> >>>>
> >> buffer;;
> >>
> >>>>     }
> >>>> }
> >>>>
> >>>> This works fine except that when nothing is provided, the
> generation
> >>>>
> >> is
> >>
> >>>> :
> >>>>     if (HASEXCEPTION())
> >>>>     {PREPORTERROR();
> >>>>         PRECOVER(); }
> >>>>     else
> >>>>     {{resultTree= doc;}}
> >>>>
> >>>> ... where the line is an @after clause.
> >>>>
> >>>>
> >>>> My problem ? As soon as I put my rulecatcher, the after clause is
> no
> >>>> more generated.
> >>>>
> >>>> I would be very glad to understand what I've done wrong here and
> >>>>
> >> also,
> >>
> >>>> if someone have a sample I may clone, it would help me.
> >>>>
> >>>> Thanks a lot, Pierre
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >
> >
> >
> >
> >
> >
> >
> >






More information about the antlr-interest mailing list