[antlr-interest] Enforcing a right associativity, to resolve an ambiguity (simple grammar included)

Naveen Chawla naveen.chwl at googlemail.com
Mon Oct 5 10:13:08 PDT 2009


Ok, so I found out that if you want it bound to the latest thing, that is
the "greedy" option, fortunately that is the way ANTLR automatically
resolves such ambiguities by default. According to p.276 ch.11 "The
Definitive ANTLR Reference": "ANTLR generates a warning, but you can safely
ignore it".

Thanks.

2009/10/3 Naveen Chawla <naveen.chwl at googlemail.com>

> To be clear, I want prepPhr to always belong to the last occuring 'Ving'
> (nounPhrase) before it (i.e. drinking-while-driving)
>
> 2009/10/2 Naveen Chawla <naveen.chwl at googlemail.com>
>
>  Hi,
>>
>> I'm a little bit stumped. You might find this easy. I'm trying to develop
>> an English parser and have come across a real ambiguity in English, on
>> which, for the time being, I just want to enforce simple right
>> associativity:
>>
>> e.g. Recommending drinking while driving is dangerous.
>>
>> (Is it referring to the person driving while they are recommending
>> drinking, or the person recommending drinking-during-driving?)
>>
>> This is not a problem. Since they are both equally valid in English, for
>> the time being I just want to enforce right associativity (maybe later give
>> a user option to change the tree), but I cannot figure out how!! Here is the
>> grammar I want to make right-associative (simplified for your convenience):
>>
>> grammar prep;
>> sentence: nounPhrase 'verb';
>>
>>             nounPhrase: 'Ving' complement? prepPhr?;
>>
>>                            complement : nounPhrase 'noun'? ;
>>
>>                            prepPhr: 'preposition' nounPhrase;
>>
>>
>> Ambiguous sentence example: "Ving Ving preposition Ving verb"
>> Ambiguity: "preposition" can be a prepPhr belonging to the first "Ving"
>> (nounPhrase) OR the second "Ving" (nounPhrase). I want prepPhr to always
>> belong to the last occurring 'Ving' (nounPhrase). So I want to
>> enforce, using the example sentence (right associativity):
>>
>>  sentence{
>>          nounPhrase{
>>                    'Ving'
>>                     complement{
>>                                 nounPhrase{
>>                                              'Ving'
>>                                               prepPhr{
>>                                                            'preposition'
>>                                                            nounPhrase{
>>
>>                                                                           'Ving'
>>                                                             }
>>                                               }
>>                                 }
>>                    }
>>          }
>>          'verb'
>> }
>>
>> instead of
>>
>>  sentence{
>>          nounPhrase{
>>                    'Ving'
>>                     complement{
>>                                 nounPhrase{
>>                                              'Ving'
>>                                 }
>>                      }
>>                      prepPhr{
>>                                 'preposition'
>>                                 nounPhrase{
>>                                              'Ving'
>>                                  }
>>                       }
>>          }
>>          'verb'
>> }
>>
>> while preserving the grammar.
>> Anybody have as easy idea how? Sorry if I sound newbie, I'm stumped.
>>
>> Regards,
>> N
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091005/1074ed4f/attachment.html 


More information about the antlr-interest mailing list