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

Anders.Karlsson at sybase.com Anders.Karlsson at sybase.com
Tue Jun 15 02:00:17 PDT 2010


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(
(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,

More information about the antlr-interest mailing list