[antlr-interest] Compiler-exploding grammar

Mark Edgeworth mark.edgeworth at scarletcode.co.uk
Wed Nov 28 06:26:43 PST 2007


Hi Steve,

The last alternative in your rule is empty, and so need not contain a '->'.
This looks like a corner case that might just create an invalid AST tree and
an unconstrained recursion.  Remove the '->' :-)

close_bold_italics
@after {text_bold=false; text_italics = false;}
: ;
/*        {text_bold==true && text_italics==true}? =>  -> B_OFF I_OFF
       |{text_bold==false && text_italics==true}? => -> I_OFF
       |{text_bold==true && text_italics==false}? => -> B_OFF
       |->;*/

Hope this helps,

Mark Edgeworth

-----Original Message-----
Message: 5
Date: Wed, 28 Nov 2007 23:05:45 +1100
From: "Steve Bennett" <stevagewp at gmail.com>
Subject: [antlr-interest] Compiler-exploding grammar

I have a grammar, which when generated, causes the java compiler to explode
with an out of stack space message:

The system is out of resources.
Consult the following stack trace for details. java.lang.StackOverflowError
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:297)
at com.sun.tools.javac.comp.Attr.visitBinary(Attr.java:1518)
at com.sun.tools.javac.tree.Tree$Binary.accept(Tree.java:926)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:275)
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:297)
at com.sun.tools.javac.comp.Attr.visitBinary(Attr.java:1518)
at com.sun.tools.javac.tree.Tree$Binary.accept(Tree.java:926)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:275)
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:297)
at com.sun.tools.javac.comp.Attr.visitBinary(Attr.java:1518)
...
(hundreds of lines)

Is there a developer I should send this to? It's pretty big. I tried
trimming it down to the relevant bit, but strangely enough, that compiled
fine, and even stranger, ran as expected.

That is, the code that makes it explode is commented out in the following
snippet. But that snippet alone isn't enough to make the compiler explode, I
think.

close_bold_italics
@after {text_bold=false; text_italics = false;}
: ;
/*        {text_bold==true && text_italics==true}? =>  -> B_OFF I_OFF
       |{text_bold==false && text_italics==true}? => -> I_OFF
       |{text_bold==true && text_italics==false}? => -> B_OFF
       |->;*/


Steve



More information about the antlr-interest mailing list