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

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -