8 Apr 2012 16:02
Debuging ANTLR3.4.1-snapshot C target ASTTreeParse.stg
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:
(2) The antlr compiler was complaining that /noRewrite was called without its declared two arguments:
Both of these patches are on the file:
in the gitHub stephengaito/antlr3 fork of the main antlr/antlr3 project.
As per my previous bug report:
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
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:
<at> <at> -319,7 +319,7 <at> <at> 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:
<at> <at> -209,7 +209,7 <at> <at> 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
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
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
<div>
Hello,<br><br>
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.<br><br>
My current grammars antlr-compile in Java but I noticed they did not
antlr-compile in the C target.<br><br>
I have traced the problem to 11 characters missing in three places
in the C target ASTTreeParse.stg string template.<br><br>
(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!)<br><br>
There were two overall problems:<br><br>
(1) The antlr compiler was complaining that two anonymous
templates were missing arguments:<br><br><blockquote type="cite">
<table cellpadding="0" cellspacing="0" width="100%">
<tr data-position="0">
<td width="100%">
<div class="gc"> <at> <at> -319,7 +319,7 <at> <at> if ( <actions.(actionScope).synpredgate> ) {<\n></div>
</td>
</tr>
<tr data-position="1">
<td width="100%">
<div class=""> }</div>
</td>
</tr>
<tr data-position="2">
<td width="100%">
<div class=""> <endif></div>
</td>
</tr>
<tr data-position="3">
<td width="100%">
<div class=""> <ruleDescriptor.allTokenRefsInAltsWithRewrites</div>
</td>
</tr>
<tr data-position="4">
<td width="100%">
<div class="gd">- :{i<span class="x"></span>f (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; separator="\n"></div>
</td>
</tr>
<tr data-position="5">
<td width="100%">
<div class="gi">+ :{i<span class="x">t | i</span>f (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; separator="\n"></div>
</td>
</tr>
<tr data-position="6">
<td width="100%">
<div class=""> <ruleDescriptor.allRuleRefsInAltsWithRewrites</div>
</td>
</tr>
<tr data-position="7">
<td width="100%">
<div class="gd">- :{i<span class="x"></span>f (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; separator="\n"></div>
</td>
</tr>
<tr data-position="8">
<td width="100%">
<div class="gi">+ :{i<span class="x">t | i</span>f (stream_<it> != NULL) stream_<it>->free(stream_<it>);}; separator="\n"></div>
</td>
</tr>
<tr data-position="9">
<td width="100%">
<div class=""> >></div>
</td>
</tr>
</table>
</blockquote>
<br>
(2) The antlr compiler was complaining that /noRewrite was called
without its declared two arguments:<br><blockquote type="cite">
<table cellpadding="0" cellspacing="0" width="100%">
<tr data-position="0">
<td width="100%">
<div class="gc"> <at> <at> -209,7 +209,7 <at> <at> ADAPTOR->addChild(ADAPTOR, root_<treeLevel>, <label>_tree);</div>
</td>
</tr>
<tr data-position="1">
<td width="100%">
<div class=""> </div>
</td>
</tr>
<tr data-position="2">
<td width="100%">
<div class=""> matchRuleBlockSet(s,label,terminalOptions,elementIndex,postmatchCode,treeLevel="0") ::= <<</div>
</td>
</tr>
<tr data-position="3">
<td width="100%">
<div class=""> <matchSet(...)></div>
</td>
</tr>
<tr data-position="4">
<td width="100%">
<div class="gd">-<noRewrite(<span class="x"></span>)> <! set return tree !></div>
</td>
</tr>
<tr data-position="5">
<td width="100%">
<div class="gi">+<noRewrite(<span class="x">...</span>)> <! set return tree !></div>
</td>
</tr>
<tr data-position="6">
<td width="100%">
<div class=""> >></div>
</td>
</tr>
<tr data-position="7">
<td width="100%">
<div class=""> </div>
</td>
</tr>
<tr data-position="8">
<td width="100%">
<div class=""> matchSetBang(s,label,terminalOptions,elementIndex,postmatchCode) ::= <<</div>
</td>
</tr>
</table>
</blockquote>
<br>
Both of these patches are on the file:<br><br><blockquote type="cite"><a href="https://github.com/stephengaito/antlr3/commit/888b90b3d81af76c152ae73abed32e3662094011#diff-0">tool/src/main/resources/org/antlr/codegen/templates/C/ASTTreeParser.stg</a></blockquote>
<br>
in the gitHub stephengaito/antlr3 fork of the main antlr/antlr3
project.<br><br><br>
As per my previous bug report:<br><br><blockquote type="cite"><a href="http://www.antlr.org/pipermail/antlr-dev/2012-April/002732.html">[antlr-dev]
Inconsistencies between ANTLR 3.4 C.stg and ANTLR gitHub C.stg
versions</a></blockquote>
<br>
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.<br><br>
Regards,<br><br>
Stephen Gaito<br><br>
</div>
RSS Feed