[antlr-interest] Out of memory error
Mark Bednarczyk
voytechs at yahoo.com
Wed Mar 14 18:30:07 PDT 2007
I've experimented with this a lot. And yes I have tried using the ? to make
the whole thing optional, but still run out of memory.
tableConstants
: tableConstant (',' tableConstant)* ';'
-> ^(TABLE_CONST tableConstant)*
| ';'!
;
tableDeclaration
: modifiers 'table' id typeParameters? tableBody
-> ^( TABLE_DEF id
modifiers
typeParameters?
tableBody)
;
variableDeclaratorRest
: ('[' ']')+ ('=' variableInitializer)?
| '=' variableInitializer
| tableBody
|
;
As you can see tableConstants can take an optional single ';', so that is
the requirement right now for empty tables. It would be wonderful if I could
figure out how to make tableConstants optional so an empty table with no
constants would not require a single ';' to separate from the blockStatement
list. Tables in NPL are almost like enums in java except you are allowed
blockStatements inside the body of a table.
Table body and blockStatement do not allow another table to be created
inside, so there shouldn't be any left recursion on rules, as far as I can
tell.
> -> {$tcs==null} ^(BLOCK_STATEMENT $bs*}
> -> ^(SLIST $tcs)
Is using multiple '->' rewrites allowed? I haven't tried that yet.
Cheers,
mark...
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
> Sent: Wednesday, March 14, 2007 7:51 PM
> To: ANTLR Interest
> Subject: Re: [antlr-interest] Out of memory error
>
> You could probably reduce the memory requirements by
> expressing this slitghtly differently (needs
> experimentation), though you can increase the heap space on
> the jvm when you run ANTLR of course. I wonder if this will help you:
>
> tableBody
> : '{' (tcs=tableConstants)? (bs+=blockStatement)* '}'
>
> ;
>
> Then if you really do wish to write only the tableConstants
> and ignore the blockStatements you can set a flag or check
> for null in a conditional rewrite:
>
> tableBody
> : '{' (tcs=tableConstants)? (bs+=blockStatement)* '}'
>
> -> {$tcs==null} ^(BLOCK_STATEMENT $bs*}
> -> ^(SLIST $tcs)
> ;
>
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mark Bednarczyk
> Sent: Wednesday, March 14, 2007 3:33 PM
>
>
> Here is the rule that triggers this error. If I comment out
> the second alternative, I don't run out of memory:
>
> tableBody
> : ('{' tableConstant)
> => ('{' tableConstants blockStatement* '}')
> -> ^(SLIST tableConstants+)
>
> | '{' blockStatement* '}'
> ;
>
> Cheers,
> mark...
>
>
>
More information about the antlr-interest
mailing list