[antlr-interest] error(10): internal error: TWalker.g : java.lang.IllegalArgumentException: Can't find template tokenRefRuleRoot.st

Thomas Brandon tbrandonau at gmail.com
Thu Aug 9 02:09:38 PDT 2007


On 8/9/07, Cameron Palmer <cameron.palmer at gmail.com> wrote:
> This is a painful error because it seems to be meaningless. In my
> grammar I eliminated the error by finding places that I got carat
> happy:
>
> rule : x^ this that
>        | y^
>        ;
>
> CHANGED TO
>
> rule : x^ this that
>        | y
>        ;
>
The error occurs when you mix rewrites and tree operators (! or ^) in
a single rule. In this case as the template is tokenRefRuleRoot.st it
means a misplaced ^, a misplaced ! will result in the same error but
for tokenRefRuleBang.st.

Unfortunately due to the lack of location information it is annoying
to find. The fix is waiting on the rewrite of the ANTLR grammar in v3.
You can try commenting out\in rules to track it down but this can be
annoying as you have to deal with the missing references to commented
out rules.
Or, as ANTLR reports the first occurence of the error in the file if
you insert the other tree operator in a rule with a rewrite above the
error the error will switch. So you can use this to track it down.
e.g. Given rules:
rule1: a -> a;
rule2: b -> b;
rule3: c -> c
       | c2^;
rule4: d -> d;
You get the tokenRefRuleRoot message, because of rule3. If you changed
rule2 to "b! -> b"  then the error will switch to tokenRefRuleBang,
telling you the error is below rule2. Reverting rule2 then changing
rule4 to "d! -> d" the error will not change. Showing you the error is
above rule4. Using this method you can track it down to a small area
of your code and scan that. Hope that's clear.

Tom.

>
>
> On 8/8/07, Cameron Esfahani <dirty at apple.com> wrote:
> > Thanks to Gavin Lambert, I fixed the "error(210):  The following sets of
> > rules are mutually left-recursive" error I had earlier.
> >
> > But now I get the following:
> >
> > ANTLR Parser Generator  Version 3.0 (May 17, 2007)  1989-2007
> > error(10):  internal error: TWalker.g :
> > java.lang.IllegalArgumentException: Can't find template
> > tokenRefRuleRoot.st
> > org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:485)
> > org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:372)
> > org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:384)
> > org.antlr.codegen.CodeGenTreeWalker.getTokenElementST(CodeGenTreeWalker.java:160)
> > org.antlr.codegen.CodeGenTreeWalker.atom(CodeGenTreeWalker.java:1992)
> > org.antlr.codegen.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1641)
> > org.antlr.codegen.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1478)
> > org.antlr.codegen.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1252)
> > org.antlr.codegen.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1037)
> > org.antlr.codegen.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:1804)
> > org.antlr.codegen.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1637)
> > org.antlr.codegen.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1252)
> > org.antlr.codegen.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1037)
> > org.antlr.codegen.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:753)
> > org.antlr.codegen.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:544)
> > org.antlr.codegen.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:486)
> > org.antlr.codegen.CodeGenTreeWalker.grammar(CodeGenTreeWalker.java:321)
> > org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:406)
> > org.antlr.Tool.processGrammar(Tool.java:347)
> > org.antlr.Tool.process(Tool.java:268)
> > org.antlr.Tool.main(Tool.java:70)
> >
> > I have no idea even where to begin looking.  Anyone have any ideas?
> >
> >
> > Cameron Esfahani
> > dirty at apple.com
> >
> > "Most people are bad programmers," says Joy. "The honest truth is that
> > having a lot of people staring at the code does not find the really nasty
> > bugs. The really nasty bugs are found by a couple of really smart people who
> > just kill themselves. Most people looking at the code won't see anything ...
> > You can't have thousands of people contributing and achieve a high
> > standard."
> >
> > Bill Joy on the myth of Linux's much touted "power in the masses"
> > development benefits.
> >
> >
>


More information about the antlr-interest mailing list