[antlr-interest] ANTLR + C Target Questions

Jim Idle jimi at temporal-wave.com
Fri Apr 24 11:43:02 PDT 2009


Michael Coupland wrote:
> Hi, I'm experimenting with using ANTLR to parse a custom file type,
> and I have a few questions/comments about ANTLR and the C Target:
>
>
> 1) Consider the following grammar:
>
>        grammar schema;
>
>        options
>        {
>                language = C;
>        }
>
>        root : letter* ;
>   
root: letter* EOF;

No exceptions in C so that top rule can only set flags.
>
>
> 2) The C Target generates many structs with members called "free"
> which, while not technically a reserved word, isn't an ideal choice
> for an indentifier name. There are codebases where free is #defined to
> be something else, which can lead to problems in the generated code
> that uses 'free' as a normal identifier. I haven't yet looked into
> modifying the C target to solve this locally, which doesn't seem like
> a huge task, but it would be nice if the default behavior were to use
> some other less-overloaded identifier.
>   
Maybe, but as free is a function in every C runtime that I know of, 
#defining it in a system header file would break a lot more than the 
ANTLR runtime. Which system are you thinking of that #defines free? The 
trade off is the use of an intuitive method name vs something like 
'release' or 'close'.
>
>
> 3) I can't seem to find documentation on how the C Target's error
> handling works. Clearly the documentation at
> http://www.antlr.org/wiki/display/ANTLR3/Error+reporting+and+recovery
> isn't directly relevant. Where can I find more information about this?
>   
It  basically does the same thing as the other targets, but without 
exceptions.
> Is there a good way to understand how the C Target emulates the Java
> Target's use of exceptions, 
Well, it doesn't really.
> apart from reading generated code? There
> don't seem to be any examples that deal with custom error reporting
> using the C Target.
>   
Many past posts though:

http://markmail.org/search/list:antlr?q=C+displayRecognitionError

The docs at: http://antlr.org/api/C/index.html document 
displayRecognitionError which, just like in Java, is what you must 
override to implement your own error display. Also, I have commented 
that routine to death so that you can copy it and modify it to do what 
you need personally. Just read through the function.
>
>
> 4) I was running into some problems with scope variables, and saw this
> thread: http://www.antlr.org/pipermail/antlr-interest/2009-March/033769.html
> but the link to http://antlr.org/downloads doesn't seem to work.
> http://www.antlr.org/hudson/job/ANTLR_Tool/lastSuccessfulBuild/ seems
> like a good place to get the latest development build, but I can't
> seem to actually find a download link anywhere?
It is download rather than downloads. From hudson just click on the 
project. The first thing that comes up is a list of source code 
artifacts that you can download???

http://antlr.org/hudson/job/ANTLR%20C%20Runtime/

Jim


More information about the antlr-interest mailing list