[antlr-interest] calling parser from c++, correct way?

Anders.Karlsson at sybase.com Anders.Karlsson at sybase.com
Wed Jun 16 16:32:26 PDT 2010


Hi,

Well it turned out to be something unrelated to the three scenarios 
mentioned below,
when I started out generating files I placed them in one directory but 
then decided in
my infinite wisdom to generate them directly in the project directory 
without removing
the old headers and changing the include path <> .... duh! /facepalm
Thank you and kind regards,
Anders




Joep Suijs <jsuijs at gmail.com> 
16/06/2010 13:54

To
Anders.Karlsson at sybase.com
cc

Subject
Re: [antlr-interest] calling parser from c++, correct way?






Hi Anders, Jim,

FYI: I have a similar problem (crash on free) with gcc3.4.5 (C, not
C++) on Windows XP. I disabled the free but never got around to fix it
properly.

Joep

2010/6/16  <Anders.Karlsson at sybase.com>:
>
> Hi Jim,
>
> It seems I have this issue only when running with VS2010, the main 
program
> is in C++ and the generated lexer/parser are kept as C-files (tried also
> compiling them as C++ files, same result).
>
> The same parser/lexer seems to work under objective-c(and Java of 
course)
> however when running it from within VS2010 the function pointers in the 
CTX
> seem to either not be set or set to wrong functions during run-time, not
> sure if the debugger is showing wrong and this is just normal behavior 
or
> if what I am seeing is a memory overwrite that occurs inside the 
generated
> parser. Are there any particular switches when compiling the library 
that
> needs to be set, something specific when using VS2010? I've been 
fiddling
> with pragma pack(1) thinking it had something to do with the structures 
not
> aligning up on byte boundary but that didn't help as well, I have tried
> both unicode and multibyte same problem.
>
> Since I am running under Windows/VS2010 I don't have Valgrind but I will
> try and see if I can dig up Boundschecker today
>
> Another observation is that the problem seems to depend on the 
expression,
> so I was thinking maybe my grammar had broken some unwritten laws for 
how a
> grammar should look like :-)
>
>
>
> Thank you and kind regards,
> Anders
>
>
>
> Anders Karlsson | Staff SE II, Architect | Sybase Inc, Singapore, ( +65
> 6571 3125 | * anders.karlsson at sybase.com
> -- It takes a tonne of fact to overcome an ounce of opinion
>
>
> <antlr-interest-bounces at antlr.org> wrote on 06/16/2010 01:54:50 AM:
>
>> Jim Idle <jimi at temporal-wave.com>
>> Sent by: <antlr-interest-bounces at antlr.org>
>>
>> 06/16/2010 01:54 AM
>>
>> To
>>
>> "Anders.Karlsson at sybase.com" <Anders.Karlsson at sybase.com>
>>
>> cc
>>
>> antlr-interest Interest <antlr-interest at antlr.org>
>>
>> Subject
>>
>> Re: [antlr-interest] calling parser from c++, correct way?
>>
>> Try copying the examples and see where your issue is or use valgrind.
>> I am yravellling this week so difficult to spend more time looking.
>>
>> Jim
>>
>> On Jun 15, 2010, at 2:00, Anders.Karlsson at sybase.com wrote:
>>
>> > Hi,
>> >
>> > Is this the correct way to call the antlr-runtime from C++? (It
>> > seems I
>> > have some memory overwrite issues so that is why I am asking)
>> >
>> > I have a string with the content I want to parse (e.g. string s =
>> > "1+1")
>> >
>> >
>> >      pANTLR3_INPUT_STREAM input = antlr3NewAsciiStringInPlaceStream(
>> > reinterpret_cast<pANTLR3_UINT8>(const_cast<char*>(s.c_str())),
>> > (ANTLR3_UINT64)s.length(), NULL);
>> >      pMAExpressionLexer lxr = MAExpressionLexerNew(input);
>> >      pANTLR3_COMMON_TOKEN_STREAM tstream =
>> > antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lxr));
>> >      pMAExpressionParser psr = MAExpressionParserNew(tstream);
>> >      MAExpressionParser_ma_expression_return r = psr->ma_expression
>> > (psr);
>> > // calling the start rule for parsing
>> >
>> > when I later free psr it crashes
>> >
>> >        psr->free(psr); psr = NULL;
>> > Has anybody an idea what I am doing wrong?
>> > Thank you and kind regards,
>> > Anders
>> >
>> > 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
>




More information about the antlr-interest mailing list