Hi Your rule:
targetsExpr : category ('CAND' targetsExpr)* -> ^('CAND' category targetsExpr*) ; is incorrect. You're always using `CAND` in your rewrite rule but that rule could just match `category` only. You'll probably want to do: targetsExpr : category ('CAND'^ targetsExpr)* ; (Note the ^ after CAND which makes it the root) Regards, Bart. On Fri, May 20, 2011 at 10:11 AM, massimiliano.m...@gmail.com < massimiliano.m...@gmail.com> wrote: > Hello All, > > I'm more or less a newbie using antlr. I have a small issue on creating > the AST, using rewrite rules. I'm so sorry if this is a FAQ or similar! :) > > I have the following productions (it's like an algebra with > 3 operators with different priorities): > > > targetsExpr : (category) ('CAND' targetsExpr)* > ->^('CAND' category targetsExpr*) > ; > category: (matchEl) ('OR' category)* > -> ^('OR' matchEl category* ) > ; > matchEl : factor ('AND' factor)* ->^('AND' factor*) > ; > > factor > : matchId OPAR targetValue COMMA targetName CPAR ->^('FAC' matchId > targetValue targetName) > > > The problem is that the AST created contains productions as: > > CAND ->OR -> OR-> AND (FAC, FAC). > > The second OR is created because the ``category'' production is passed > multiple times. > > Is there a way to not create these kind of rules? > > You can see a sample of the AST created in > http://www.mascanc.net/~max/policy.pdf. > > > > -- > Massimiliano Masi > > http://www.mascanc.net/~max > > 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.