[antlr-interest] AST Question

massimiliano.masi at gmail.com massimiliano.masi at gmail.com
Fri May 20 01:11:34 PDT 2011


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


More information about the antlr-interest mailing list