There seems to be a problem in the definitive guide example code
templates/generator/1pass/Expr.g

If more that two integers are added then the middle ones drop out, that is
1+2+3+4 becomes 1+4 in the generated jasmin.  Seems to be that ops is not
treated as an array in the expr rule.  My fix for this is:

Original Expr.g expr rule:


expr
    :   multExpr ( ops+=addOp | ops+=subOp )*
        -> expr(firstExpr={$multExpr.st}, ops={ops})
    ;


Modified Expr.g expr rule


expr
    :   multExpr ( ops+=addOp | ops+=subOp )*
        -> expr(firstExpr={$multExpr.st}, ops={$ops})
    ;


by adding the $ so that ops becomes $ops it gets treated as an array as it
should.

then since the template is getting an array now, need to add a separator to
the expr template in ByteCode.stg

Original expr template


expr(firstExpr, ops) ::= <<




Modified expr template

expr(firstExpr, ops) ::= <<

&lt;ops; separator=&quot;\n&quot;&gt;
>>

I didn't see a post on this previously.  This works for me.  Hope this helps
someone.

--
View this message in context: 
http://antlr.1301665.n2.nabble.com/1pass-cannot-add-subtract-more-than-two-consecutive-integers-tp6209416p6209416.html
Sent from the ANTLR mailing list archive at Nabble.com.

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