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
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev