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

Naveen Chawla naveen.chwl at googlemail.com
Sat Oct 3 02:44:30 PDT 2009


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/20091003/d7d3d4d0/attachment.html 


More information about the antlr-interest mailing list