[antlr-interest] (newbie problem)out of memory problem
Kay Roepke
kroepke at classdump.org
Thu Jul 12 23:54:57 PDT 2007
On Jul 13, 2007, at 2:52 AM, ali azimi wrote:
> I have written the following grammar and rewrite rule. However,
> when I try to generate code it produces some problems (like java
> out of memory and I am sure the problem in my grammar comes from
> this rule). Could you recommend a better way of writing it?
org.antlr.Tool is out of memory? If so, try to pass the -Xmx300m
argument (substituting the appropriate of max memory) to the Java call.
However, I don't think the rule in question really is the problem, as
the lookahead is fine for a simple test case I just made up.
It might however all depend on the rules you didn't include in your
mail. There's no way to figure out the problem from just this rule.
> blocksubstructuredefinition
> :'substructure' qualifier? blocksubstructurename?
> end'endsubstructure'qualifier? blocksubstructurename? end
> (entityinsystem+ ->^('substructure' qualifier?
> blocksubstructurename? end 'endsubstructure'qualifier?
> blocksubstructurename? end entityinsystem+ )
> |channelconnection+ ->^('substructure' qualifier?
> blocksubstructurename? end'endsubstructure'qualifier?
> blocksubstructurename? end channelconnection+ )
> )
> ;
Also, use whitespace and underscores or camelCase. The rule is really
hard to read this way. You'll be thanking yourself sometime down the
road...
And:
The rewrite rules don't look right to me, but this hasn't anything to
do with you original question.
You haven't assigned labels to the qualifier, blocksubstructurename,
and end rules but reference them twice in the rule and in the rewrite.
This way, in the rewrite, you will end up with the first references
twice because ANTLR calls reset() on the RewriteRuleSubtreeStreams.
That's probably not what you meant. Assign labels to the rule
references and use the labels in the rewrites.
blocksubstructuredefinition
: 'substructure'
q1=qualifier? b1=blocksubstructurename? e1=end
'endsubstructure'
q2=qualifier? b2=blocksubstructurename? e2=end
( entityinsystem+ -> ^('substructure' $q1? $b1? $e1
'endsubstructure' $q2? $b2? $e2 entityinsystem+ )
| channelconnection+ -> ^('substructure' $q1? $b1? $e1
'endsubstructure' $q2? $b2? $e2 channelconnection+ )
)
;
HTH,
-k
--
Kay Röpke
http://classdump.org/
More information about the antlr-interest
mailing list