[antlr-interest] Segfault with very simple parser

Ric Klaren ric.klaren at gmail.com
Sat Aug 26 16:06:17 PDT 2006


On 8/27/06, John Gruenenfelder <johng at as.arizona.edu> wrote:
> Starting simple, I pieced together a very simple parser and lexer from the
> many examples on the ANTLR website. I can run the new parser through ANTLR
> without problems and without errors or warnings. I can even compile it without
> any issues using g++ 4.1.
>
> It's when I try to run this simple parser that I get a segfault. The C++ code
> is:
>
>   ...
>   OpCLexer lexer(cin);
>   OpCParser parser(lexer);
>
>   parser.expr();
>   RefAST t = parser.getAST();
>   ...

You probably forgot to set the ASTFactory:

	ASTFactory ast_factory;

	parser.initializeASTFactory(ast_factory);
	parser.setASTFactory(&ast_factory);

Cheers,

Ric


More information about the antlr-interest mailing list