parsing - ANTLR rewrite rules in grammar file -


i have rule looks this:

a : (b | c) d;  b : 'b';  c : 'c';  d : 'd'; 

with grammar antlr builds flat parse tree. how can rewrite first rule (and leave other 2 unchanged) whatever matched being returned under root node called a?

if first production rule this:

a : b d; 

then have been rewritten

a : b d -> ^(a b d) 

and have solved problem. first grammar rule yields more 1 possibility resulting parse tree ^(a b d) or ^(a c d).

how express when rewriting rule?

you can use ? operator in rewrite follows.

a : (b | c) d -> ^(a b? c? d); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -