Hello,

As part of my ongoing work to build a LaTeXCreole filter for PHP/Drupal,
I have gone down the route of building AST trees AST trees using a tree
grammar.

My current grammars antlr-compile in Java but I noticed they did not
antlr-compile in the C target.

I have traced the problem to 11 characters missing in three places in
the C target ASTTreeParse.stg string template.

(I was pleasantly surprised at how little time it took me to diagnose
these two problems.... /this is entirely down to the cleanness of
ANTLR3's architecture/.... while there is a lot of code, there are a lot
of examples with which to intuit your original intent... so again, many
thanks for the excellent work and thought of both Terence and Jim!)

There were two overall problems:

(1)    The antlr compiler was complaining that two anonymous templates
were missing arguments:

> @@ -319,7 +319,7 @@ if ( <actions.(actionScope).synpredgate> ) {<\n>
>  }
>  <endif>
>  <ruleDescriptor.allTokenRefsInAltsWithRewrites
> -    :{if (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; 
> separator="\n">
> +    :{it | if (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; 
> separator="\n">
>  <ruleDescriptor.allRuleRefsInAltsWithRewrites
> -    :{if (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; 
> separator="\n">
> +    :{it | if (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; 
> separator="\n">
>  >>
>

(2)    The antlr compiler was complaining that /noRewrite was called
without its declared two arguments:
> @@ -209,7 +209,7 @@ ADAPTOR->addChild(ADAPTOR, root_<treeLevel>, 
> <label>_tree);
>  
>  
> matchRuleBlockSet(s,label,terminalOptions,elementIndex,postmatchCode,treeLevel="0")
>  ::= <<
>  <matchSet(...)>
> -<noRewrite()> <! set return tree !>
> +<noRewrite(...)> <! set return tree !>
>  >>
>  
>  matchSetBang(s,label,terminalOptions,elementIndex,postmatchCode) ::= <<
>

Both of these patches are on the file:

> tool/src/main/resources/org/antlr/codegen/templates/C/ASTTreeParser.stg 
> <https://github.com/stephengaito/antlr3/commit/888b90b3d81af76c152ae73abed32e3662094011#diff-0>

in the gitHub stephengaito/antlr3 fork of the main antlr/antlr3 project.


As per my previous bug report:

> [antlr-dev] Inconsistencies between ANTLR 3.4 C.stg and ANTLR gitHub
> C.stg versions
> <http://www.antlr.org/pipermail/antlr-dev/2012-April/002732.html>

I am happy to either raise a gitHub issue (on antlr/antlr3 or
antlr/antlr4) or issue a pull request.  Please let me know how you would
like me to deal with this.

Regards,

Stephen Gaito

_______________________________________________
antlr-dev mailing list
antlr-dev@antlr.org
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to