The fix is to put a backslash before each occurrence of <init> in
ByteCode.stg. So convert:

; public Calc() { super(); } // calls java.lang.Object()
.method public <init>()V
   aload_0
   invokenonvirtual java/lang/Object/<init>()V
   return
.end method

into:

; public Calc() { super(); } // calls java.lang.Object()
.method public \<init>()V
   aload_0
   invokenonvirtual java/lang/Object/\<init>()V
   return
.end method

and the example works fine.


On Dec 29 2010, 4:21 pm, bill punch <[email protected]> wrote:
> Sorry to bother. I was having the same problem but I'm not quite getting
> what the fix is .Should the entire init stuff be commented out as in
>
> ; public Calc() { super(); } // calls java.lang.Object()
> ;.method public <init>()V
> ;   aload_0
> ;   invokenonvirtual java/lang/Object/<init>()V
> ;   return
> ;.end method
>
> or something else? Thanks for any help.
>
>       >>>bill<<<
>
> On 12/29/10 7:04 AM, Hani Sayyid wrote:
>
>
>
>
>
> > I fixed the issue. I just had to remove the <init> attribute
> > from ByteCode.stg. In the PDF version of the book, it it is correct. But if
> > you download the code from this link:
> >http://media.pragprog.com/titles/tpantlr/code/templates/generator/2pa...
>
> > or the zip/tar file on the book's website, 2 extra and useless <init>
> > attributes are included in the stg file.
>
> > Regards.
> > -------
>
> > Hi,
>
> > I'm trying to run the files in \templates\generator\2pass. I haven't changed
> > anything code related. I created a new project in Eclipse, added the files
> > in a new package, and compiled them. They compiled fine, but when I give
> > them any input like 2+4*3, they give the following error:
>
> > Exception in thread "main" java.util.NoSuchElementException: no such
> > attribute: init in template context [jasminFile]
> > at
> > org.antlr.stringtemplate.StringTemplate.checkNullAttributeAgainstFormalArgu 
> > ments(StringTemplate.java:1311)
> > at
> > org.antlr.stringtemplate.StringTemplate.getAttribute(StringTemplate.java:68 
> > 4)
> > at
> > org.antlr.stringtemplate.language.ActionEvaluator.attribute(ActionEvaluator 
> > .java:360)
> > at
> > org.antlr.stringtemplate.language.ActionEvaluator.expr(ActionEvaluator.java 
> > :136)
> > at
> > org.antlr.stringtemplate.language.ActionEvaluator.action(ActionEvaluator.ja 
> > va:84)
> > at org.antlr.stringtemplate.language.ASTExpr.write(ASTExpr.java:149)
> > at org.antlr.stringtemplate.StringTemplate.write(StringTemplate.java:705)
> > at
> > org.antlr.stringtemplate.StringTemplate.toString(StringTemplate.java:1670)
> > at
> > org.antlr.stringtemplate.StringTemplate.toString(StringTemplate.java:1661)
> > at strt.Test.main(Test.java:37)
>
> > Is there something missing in the code or I'm doing something wrong?
>
> > Regards.
>
> > List:http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
> List:http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to