[antlr-interest] Problems with the C version of ANTLR

Andreas Volz lists at brachttal.net
Sun Sep 6 00:40:44 PDT 2009


Hello,

I tried some Java examples for ANTLR and it worked nice. But I need a
parser for C (for later C++ usage). As easy it was to get a working
Java example as hard is it to get a C example working.

I've read this doc:

http://www.antlr.org/api/C/index.html

-> Generating Code for the C Target 

I'm a little confused about this table:

Suffix 	Grammar should contain...
.g3l 	A lexer grammar specification only.
.g3p 	A parser grammar specification only.
.g3pl 	A combined lexer and parser specification.
.g3t 	A tree grammar specification. 

All examples I've seen contains only grammar.g files. Is this simply a
new handling to split my grammar file?

How ever. I go with my grammar.g file that I've used for the Java
example.

VCard.g:
http://codepad.org/hiVS9kte

First question is if it's also possible to insert the main code for C
in the grammar file like with Java?

Then I installed ANTLR-3.0.1 (Ubuntu) from repository and the C runtime
from ANTLR-3.0.1 from source. This should fit together.

Now I took an C example and modified it to compile for my grammar. At
first I compiled the grammar and got these files:

VCardLexer.c
VCardLexer.h
VCardParser.c
VCardParser.h

I modified them from an example:

VCard.c:
http://codepad.org/uoMWeBW7

VCard.h:
http://codepad.org/ADTKm47X

Makefile.C:
http://codepad.org/YWC4E4ti

This compiles, but I get a "Segmentation fault" as result. I've not yet
debugged into it, because I like to ensure that I did all steps correct.

You could see that I commented out all the "langAST" and "treePsr"
variables, because they didn't compile. Who creates the "pLangDumpDecl"
and "LangParser_decl_return" type? I don't see it generated by the code
generator. Do I need those for my example?

And the last question is why is it so hard to get the C target working
comparing to the Java target? :-)

regards
	Andreas


More information about the antlr-interest mailing list