Hello Thanks for the reply.
My requirement wouldnt allow for an unwrap at the grammar. Yes all leaves wud be 'simple' but complex dont mean simple. Meaning Complex : expr ( join expr)+ Helps in Complex1 and complex2 Or Simple1 or complex1 Etc Thanks n Regards Arun On Jun 14, 2012 6:15 PM, "John B. Brodie" <j...@acm.org> wrote: > Greetings! > > On 06/14/2012 04:44 AM, Arun N Kumar wrote: > >> Hi All, >> >> I have a recursive rule, would like to know what can be done to make it >> behave ! >> >> expr : ( simple | complex ) ; >> >> simple : ( ID operator ID ) ; >> complex : ( expr join expr (join expr)* ) ; >> >> >> > first note that your `complex` rule can be simplified to: > > complex : expr ( join expr )+ ; > > we can easily see that the base case for the recursion is the `simple` > rule. > and so no matter how one parses (an ambiguous) sequence of `join`s one > always ends up with: > > complex : simple ( join simple )+ ; > > of course, if the `join` rule contains `ID` and/or `operator` rule > references ambiguity will probably still be present. > > and, if you feel like it, we can now remove the `complex` rule entirely > (assuming no other usage) via: > > expr : simple | simple ( join simple )+ ; > > written better as: > > expr : simple ( join simple )* ; > simple : ID operator ID ; > > Hope this helps... > -jbb > > >
_______________________________________________ antlr-dev mailing list antlr-dev@antlr.org http://www.antlr.org/mailman/listinfo/antlr-dev