[antlr-interest] AST generating grammar not building for C target

Jim Idle jimi at temporal-wave.com
Tue Aug 21 08:38:21 PDT 2007


What version of ANTLR are you using to generate the code. This is fixed
in the latest template I believe and this should be a part of the latest
ANTLR tool. Maybe it is not a part of the ANTLRWorks version you are
using. I will check the template though. Try downloading the examples
and using the .sln files there to see how it integrates with VS2005.

Jim



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Josh Scholar
> Sent: Tuesday, August 21, 2007 12:32 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] AST generating grammar not building for C
> target
> 
> I solved my earlier problem by downloading the full source
> distribution rather than getting the C code from FishEye (though it
> would still be nice to keep up with development).
> 
> But my first test, an AST making grammar the compiles under Java isn't
> compiling in Visual C++ 2005.
> 
> Whether I use the 3.0 or the 3.0.1 C include code (and using the
> latest AntlrWorks) I get:
> 
> c:\assembler\antlr3\scratch\scratch\stuffparser.c(3008) : warning
> C4003: not enough actual parameters for macro 'TOKTEXT'
> c:\assembler\antlr3\scratch\scratch\stuffparser.c(3008) : error C2059:
> syntax error : ')'
> 
> for line 3008 in the generated "[grammar name]parser.c"
> 
>             	        root_1 = ADAPTOR->becomeRoot(ADAPTOR,
> ADAPTOR->createTypeTokenText(ADAPTOR, LIST, TOKTEXT(h)), root_1);
> 
> 
> or for a bit more context:
> 
>             /* AST REWRITE
>              * elements          : head, dot, rest
>              * token labels      :
>              * rule labels       : retval, rest, head, dot
>              * token list labels :
>              * rule list labels  :
>              */
>             if ( BACKTRACKING==0 )
>             {
>             	pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_retval;
>             	pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_rest;
>             	pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_head;
>             	pANTLR3_REWRITE_RULE_SUBTREE_STREAM stream_dot;
> 
> 
> 	stream_retval=antlr3RewriteRuleSubtreeStreamNewAEE(ADAPTOR,
> (pANTLR3_UINT8)"token retval", retval.tree != NULL ? retval.tree :
> NULL);
> 
> 	stream_rest=antlr3RewriteRuleSubtreeStreamNewAEE(ADAPTOR,
> (pANTLR3_UINT8)"token rest", rest.tree != NULL ? rest.tree : NULL);
> 
> 	stream_head=antlr3RewriteRuleSubtreeStreamNewAEE(ADAPTOR,
> (pANTLR3_UINT8)"token head", head.tree != NULL ? head.tree : NULL);
> 
> 	stream_dot=antlr3RewriteRuleSubtreeStreamNewAEE(ADAPTOR,
> (pANTLR3_UINT8)"token dot", dot.tree != NULL ? dot.tree : NULL);
> 
>             	root_0			    = ADAPTOR->nil(ADAPTOR);
>             	retval.tree    = root_0;
>             	// 29:78: -> ^( LIST[$h] ( $head)? ( $rest)* ( ^(
> DOT[$d]
> $dot) )? )
>             	{
>             	    //
> C:\\assembler\\antlr3\\scratch\\scratch\\stuff.g:29:80: ^( LIST[$h] (
> $head)? ( $rest)* ( ^( DOT[$d] $dot) )? )
>             	    {
>             	        pANTLR3_BASE_TREE root_1 = ADAPTOR-
> >nil(ADAPTOR);
>             	        root_1 = ADAPTOR->becomeRoot(ADAPTOR,
> ADAPTOR->createTypeTokenText(ADAPTOR, LIST, TOKTEXT(h)), root_1);
> 
>             	        //
> C:\\assembler\\antlr3\\scratch\\scratch\\stuff.g:29:91: ( $head)?
>             	        {
>             	        	if ( stream_head->hasNext(stream_head) )
>             	        	{
>             	        		ADAPTOR->addChild(ADAPTOR,
root_1,
> stream_head->next(stream_head));
> 
>             	        	}
>             	        	stream_head->reset(stream_head);
> 
>             	        }


More information about the antlr-interest mailing list