[antlr-interest] Question: Compiling generated parser code using C target with VC++

Wei.Wei at uni-konstanz.de Wei.Wei at uni-konstanz.de
Wed Apr 1 09:16:56 PDT 2009


Dear all,

we are using ANTLR3 (ver. 3.1.3) to generate a Java parser using C target. 
The generated code is supposed to be compiled with Visual Studio 2008, and 
later used in a VC++ project.

The grammar file that we used is Java 1.5 grammar for ANTLR v3 written by 
Terence Parr. We found it in the list of grammar files at

http://www.antlr.org/grammar/list.

We inserted the following language option into the above mentioned grammar 
file:

options 
{
    language = C;
    ASTLabelType=pANTLR3_BASE_TREE;    
} 

To integrate ANTLR3 into VS2008, we followed the instructions for using C 
target on the Wiki page at

http://www.antlr.org/wiki/display/ANTLR3/Using+the+ANTLR3+C+Target

We successfully built the C runtime library (version 3.1.3) with 
antlr3c_dll.lib generated. Then, we created a new VS project, and included 
the references to the necessary header and library files in the project. 
We also imported the custom build rules that we found within the 
vsrulefiles subfolder inside the antlr3.1.3 release package.

Next, we added the Java grammar file into the project. The 
antlr3lexerandparser.rules rule automatically applied to generate the 
source code of both parser and lexer. However, when we tried to compile 
the generated C code, we got the compilation errors like the one below:

javaparser.c(21743) : error C2231: '.getLine' : left operand points to
'struct', use '->'

We also tried to define "_cplusplus" and then got compilation errors like 
this:

sourceannotations.h(42) : error C2061: syntax error : identifier 
'vc_attributes'

We suspect the reason of compile failures to be the incompatibility of the 
C target with C++. However, we see in the list of ANTLR3 targets list that 
the C target should be compatible with C++ as of ver. 3.1.

We will greatly appreciate if you can give some hints where we might have 
done things wrong, and advise us how to successfully compile the C code of
the parser in VC++.

Thank you in advance.
 
Greetings,
Wei


More information about the antlr-interest mailing list