[antlr-interest] ANTLR Java Bytecode Generator Example

Hani Sayyid hna12 at aub.edu.lb
Wed Dec 29 04:04:53 PST 2010


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/2pass/ByteCode.stg

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.checkNullAttributeAgainstFormalArguments(StringTemplate.java:1311)
at
org.antlr.stringtemplate.StringTemplate.getAttribute(StringTemplate.java:684)
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.java: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.


More information about the antlr-interest mailing list