[antlr-interest] Segfault with very simple parser

John Gruenenfelder johng at as.arizona.edu
Sat Aug 26 15:51:48 PDT 2006


Hello,

I am just starting to use ANTLR, though I have written a parser before using
yacc/bison.

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();
  ...

The parser.expr() line executes and then I can type in a simple expression
like "1+1". As soon as I press return, I get a segfault. Checking with gdb, I
see that the segfault occurs in the antlr::ASTFactory::create() function in
the generated OpCParser.cpp file. The line in question is:

  tmp7_AST = astFactory->create(LT(1));

I ask this here because I am not sure what is going on. Being new to ANTLR I
am unsure if this is due to mistakes in the parser/lexer, something wrong with
my installation of ANTLR, or perhaps some incompatibilty with GCC 4.1. I have
only provided snippets of code, not knowing yet what the etiquette on this
list is regarding attachments, but I can attache them r place them online
elsewhere if needed.

Any help would be greatly appreciated. Thank you.


-- 
--John Gruenenfelder    Research Assistant, UMass Amherst student
                        Systems Manager, MKS Imaging Technology, LLC.
Try Weasel Reader for PalmOS  --  http://gutenpalm.sf.net
"This is the most fun I've had without being drenched in the blood
of my enemies!"
        --Sam of Sam & Max


More information about the antlr-interest mailing list