[antlr-interest] Error compiling generated C code (possibly 32/64 bit conflict?)

Andy Grove andy.grove at codefutures.com
Tue Jan 20 15:44:34 PST 2009


Ah. That makes sense.

Thank you for your help - we will fix up our tokens as you suggest and  
give this another go.

Thanks,

Andy.

On Jan 20, 2009, at 3:08 PM, Jim Idle wrote:

> Andy Grove wrote:
>>
>> Jim,
>>
>> Thanks for the prompt response. Yes, I did run "make install" and  
>> the antlr3 header files are in /usr/local/include. I get different  
>> errors if I remove those headers so the header files are being  
>> discovered.
>>
>> I am using this syntax to call the compiler:
>>
>> g++ -I$ANTLR_INCLUDE_PATH -O0 -g3 -Wall -c -fmessage-length=0 -fPIC  
>> -MMD -MP -MF"src/sqlparser/DbsMySQL_CPPLexer.d" -MT"src/sqlparser/ 
>> DbsMySQL_CPPLexer.d" -o"output/DbsMySQL_CPPLexer.o" "src/sqlparser/ 
>> DbsMySQL_CPPLexer.c"
>>
>> I'm compiling as C++. Is this supported? I'd like to call into C++  
>> code from the parser.
>
> Yes, it is supported. You are getting errors because you have  
> defined some of your token names such that they clash with standard  
> C/C++ macros. Specifically you need to rename your NULL and DELETE  
> tokens as KNULL and KDELETE. Fix these and lets try simpler compiles.
>
> As a design pattern though, create a helper class and just call  
> that, keep the code you embed in actions to a minimum for  
> maintenance reasons. Let's try a simpler compile, first just as C:
>
> gcc -I /usr/local/include -c src/sqlparser/DbsMySQL_CPPLexer.c
>
> Then the same with g++
>
> g++ -I /usr/local/include -c src/sqlparser/DbsMySQL_CPPLexer.c
>
> If you turn on all the possible C++ warnings and errors, then it is  
> likely you will get a lot as this is meant to compile at -Wall with  
> gcc, but I make no claims for g++ ;-) You can compile your own C++  
> and so on with all the C++ warnings of course.
>
> Jim
>
>>
>> To provide a bit more detail, here is a larger portion of error  
>> output:
>>
>> In file included from src/sqlparser/DbsMySQL_CPPLexer.c:27:
>> src/sqlparser/DbsMySQL_CPPLexer.h:371:1: warning: "NULL" redefined
>> In file included from /usr/include/rpc/netdb.h:42,
>>                  from /usr/include/netdb.h:33,
>>                  from /usr/local/include/antlr3defs.h:253,
>>                  from /usr/local/include/antlr3.h:4,
>>                  from src/sqlparser/DbsMySQL_CPPLexer.h:144,
>>                  from src/sqlparser/DbsMySQL_CPPLexer.c:27:
>> /usr/lib/gcc/x86_64-redhat-linux/4.3.2/include/stddef.h:400:1:  
>> warning: this is the location of the previous definition
>> In file included from src/sqlparser/DbsMySQL_CPPLexer.c:27:
>> src/sqlparser/DbsMySQL_CPPLexer.h:414:1: warning: "DELETE" redefined
>> In file included from /usr/include/arpa/nameser.h:531,
>>                  from /usr/local/include/antlr3defs.h:249,
>>                  from /usr/local/include/antlr3.h:4,
>>                  from src/sqlparser/DbsMySQL_CPPLexer.h:144,
>>                  from src/sqlparser/DbsMySQL_CPPLexer.c:27:
>> /usr/include/arpa/nameser_compat.h:127:1: warning: this is the  
>> location of the previous definition
>> src/sqlparser/DbsMySQL_CPPLexer.c: In function  
>> 'DbsMySQL_CPPLexer_Ctx_struct*  
>> DbsMySQL_CPPLexerNew(ANTLR3_INPUT_STREAM_struct*)':
>> src/sqlparser/DbsMySQL_CPPLexer.c:447: error: invalid conversion  
>> from 'int' to 'ANTLR3_RECOGNIZER_SHARED_STATE_struct*'
>> src/sqlparser/DbsMySQL_CPPLexer.c:447: error:   initializing  
>> argument 2 of 'DbsMySQL_CPPLexer_Ctx_struct*  
>> DbsMySQL_CPPLexerNewSSD(ANTLR3_INPUT_STREAM_struct*,  
>> ANTLR3_RECOGNIZER_SHARED_STATE_struct*)'
>> src/sqlparser/DbsMySQL_CPPLexer.c: In function  
>> 'DbsMySQL_CPPLexer_Ctx_struct*  
>> DbsMySQL_CPPLexerNewSSD(ANTLR3_INPUT_STREAM_struct*,  
>> ANTLR3_RECOGNIZER_SHARED_STATE_struct*)':
>> src/sqlparser/DbsMySQL_CPPLexer.c:465: error: ISO C++ forbids  
>> comparison between pointer and integer
>> src/sqlparser/DbsMySQL_CPPLexer.c:468: error: invalid conversion  
>> from 'int' to 'DbsMySQL_CPPLexer_Ctx_struct*'
>> src/sqlparser/DbsMySQL_CPPLexer.c:488: error: ISO C++ forbids  
>> comparison between pointer and integer
>> src/sqlparser/DbsMySQL_CPPLexer.c:491: error: invalid conversion  
>> from 'int' to 'DbsMySQL_CPPLexer_Ctx_struct*'
>> src/sqlparser/DbsMySQL_CPPLexer.c: At global scope:
>> src/sqlparser/DbsMySQL_CPPLexer.c:681: error: invalid conversion  
>> from 'int' to 'const ANTLR3_INT32*'
>>
>>
>> Thanks,
>>
>> Andy.
>>
>>
>> On Tue, Jan 20, 2009 at 2:19 PM, Jim Idle <jimi at temporal-wave.com>  
>> wrote:
>> Andy Grove wrote:
>> > Hi,
>> >
>> > I installed the ANTLR C runtime (version 3.1.1) and compiled it  
>> from
>> > source successfully on Fedora 10 x86_64 (using the --enable-64bit
>> > configuration option).
>> >
>> > I also generated C code successfully from my grammar.
>> >
>> > However, when I attempt to compile the generated code I get a lot  
>> of
>> > type conversion errors such as:
>> >
>> > MyLexer.c:1634: error: invalid conversion from 'int' to 'const
>> > ANTLR3_INT32*'
>> >
>> > The code that produces this error is:
>> >
>> > /* Transition tables are a table of sub tables, with some tables
>> >   * reused for efficiency.
>> >   */
>> > static const ANTLR3_INT32 * const dfa31_transitions[] =
>> > {
>> >      dfa31_T0, dfa31_T139, dfa31_T171, dfa31_T56, dfa31_T131,  
>> dfa31_T36,
>> >      dfa31_T27, dfa31_T147, dfa31_T149, dfa31_T125, dfa31_T170,
>> > dfa31_T33,
>> >
>> >
>> > I am using g++ (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7).
>> >
>> Are you trying to compile it as C++ code? Did you use:
>> -I/usr/local/wherantlris and of course run 'make install' Looks like
>> perhaps it hasn't picked up the header files. make sure you read the
>> example in the docs.
>>
>> Jim
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090120/75917ff8/attachment.html 


More information about the antlr-interest mailing list