[antlr-interest] TinyC
Bryan Ewbank
ewbank at gmail.com
Wed Oct 5 11:40:31 PDT 2005
> The program is crashing out on the call parser.funclist()
> More specifically its a problem with the "ASTFactory".
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x08063b50 in
> antlr::ASTFactory::create(antlr::TokenRefCount<antlr::Token>) ()
Looks like you are generating a tree, right (e.g., buildAST=true).
For this, you need an instance of the factory class; this is described
(buried ;-) on page 112 of the antlrman.pdf file in the distro:
quoting...
New as of ANTLR 2.7.2 is that if you supply the
buildAST=true
option to a parser then you have to set and initialize an ASTFactory
for the parser and treewalkers that use the resulting AST.
ASTFactory my_factory; // generates CommonAST per default..
MyParser parser( some−lexer );
// Do setup from the AST factory repeat this for all parsers
using the AST
parser.initializeASTFactory( my_factory );
parser.setASTFactory( );
In other words, you need to call the initialize and set methods on the
parser /before/ you attempt to build a tree by calling your
parser.funclist() method. Also, that same factory should be used by
all TreeParser classes in your pipeline.
I use a hand-written constructor that takes a second argument - the
AST factory - to help prevent me from forgetting this:
class P extends Parser;
options {
noConstructors = true;
}
{
public:
P(antlr::TokenStream &lexer, antlr::ASTFactory *my_factory)
: antlr::LLkParser(lexer,2) // copied from default
generated constructor
, ... ...... // other c'tor
initializations here, as needed
{
initializeASTFactory(*my_factory);
setASTFactory(my_factory);
}
}
More information about the antlr-interest
mailing list