[antlr-interest] Error reporting with the C runtime: tokenNames

Jim Idle jimi at temporal-wave.com
Wed May 20 08:03:10 PDT 2009


Ned Gill wrote:
> On Tue, 19 May 2009 16:28:45 +0100, Jim Idle <jimi at temporal-wave.com> 
> wrote:
>
>> It is the same as the other targets, in that you need to create a local
>> function that returns/displays/adds to the message, the name you want to
>> use for error display. It is just a switch statement on the token type
>> basically, or you could create a local map and initialize it the first
>> time it is required. It is just a bit of slog really.
>
> Sounds like it. I think the information I need is in the <Name>.tokens 
> file, though, so possibly I could generate some code from that.
Generally not as though it might be what you need in this case, you may 
well want to say near: punctuation character ','. Or, at the 'spline' 
operator '+*^" and so on. BUt if the tokens file gives you what you 
need, then a few minutes of awk should transform it in to a C struct for 
you :-)
>
>
>>> I'm already maintaining my own version of C.stg for other reasons, so I
>>> could make changes to that if necessary.
>>>
>> Let me know if there is something that you changed that really needs to
>> be in the main template - I know of at least two things that I need to
>> resolve (@after for instance), but obviously would prefer that you can
>> use the main branch.
>
> The changes are fairly trivial:
>
> - fixed a few compiler warnings (for my grammar at least)
OK - I want the output to go through -Wall/W4 without any warnings so I 
will check your changes.
> - added some types to cTypeInitMap (some standard, some specific to my 
> project)
Sure - not much we can do about that.
> - #undef ADD (which is defined by a system header somwhere, annoyingly)
Ah - the way to get around that is not to undef ADD but to change your 
token name to KADD, then you can ignore the system header.
> - a quick fix to get my grammar building under MinGW.
Should already do so, but I am trying to keep MingW supported, so I 
should like to try and incorporate your changes.
>
> I've attached a diff against C.stg from 3.1.3.
>
Thanks - I will look at bringing in the fixes.

jim


More information about the antlr-interest mailing list