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

Wei.Wei at uni-konstanz.de Wei.Wei at uni-konstanz.de
Thu Apr 2 00:36:23 PDT 2009


Dear Jim,

this is very helpful. Thank you!

Best regards,
Wei

On Wed, 1 Apr 2009, Jim Idle wrote:

> Wei.Wei at uni-konstanz.de wrote:
> > 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++.
> >   
> I thought I replied to this? Please use the Java grammar in the 
> downloaded examples for the C target and not the Java version of it. It 
> is under the C directory in the downloaded examples. The Java version 
> contains embedded Java code in the lexer, which clearly will not compile 
> in C or C++ and needs to be changed to be C code. The example grammar in 
> the C directory already does this.
> 
> Jim
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 

-- 
Dr. Wei Wei
Fach D 67, University of Konstanz
78457 Konstanz
Germany
Phone: +49 (0)7531 88 4445
Fax: +49 (0)7531 88 3577


More information about the antlr-interest mailing list