ANTLR tree construction problem -



ANTLR tree construction problem -

if got grammar rule like

a: (c|d|e)

i can create ast rule attaching rewrite rules each alternative(c, d, e) this:

a: (c -> ^(a c) | d -> ^(a d) | e -> ^(a e))

but, if got different grammar rule like

a: (a|b) (c|d|e)

how create ast every possible match? first tried this:

a: (a|b) (c|d|e) -> ^((a|b) (c|d|e))

but, did not work.

is there simple way solve problem?

thanks in advance. :)

you have 2 options:

1 a : (left=a | left=b) (right=c | right=d | right=e) -> ^($left $right) ;

or:

2 a : left right -> ^(left right) ; left : | b ; right : c | d | e ;

personally, prefer 2nd option.

antlr

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -