Open Enyby opened 7 years ago
:memo: This was fixed completely in ANTLR 4.
For ANTLR 3, you can avoid the rewrite overhead in many placed by using AST operators instead. The type
terminal option was added specifically to handle this case, but it appears to only have been implemented for the C# target. If added to the templates of the Java target,
// This code:
ACCESS_SPEC -> SIMPLE_NAME[$ACCESS_SPEC]
// Is the same as this code (but this one doesn't have the rewriter overhead):
ACCESS_SPEC<type=SIMPLE_NAME>
The specific templates affected are createNodeFromToken
, tokenRef
, tokenRefRuleRoot
, matchSet
, matchSetRuleRoot
, and createRewriteNodeFromElement
.
I do not understand - If I rewrite this code as you say then this must worked in Java or not?
@Enyby In the current release of ANTLR 3, only the C# target will allow you to do that. The Java target would support it only if you modify the code generation templates I mentioned above.
I translate this file https://github.com/JesusFreke/smali/blob/master/smali/src/main/antlr/smaliParser.g And get next Java code:
As you see it create many new object RewriteRuleTokenStream but use only one from it.
It is waste memory and cause run of garbage collector. This is slow down work parser.
For solve this issue need rewrite code to lazy init.
For example: