[antlr-interest] Enforcing a right associativity, to resolve an ambiguity (simple grammar included)
Naveen Chawla
naveen.chwl at googlemail.com
Fri Oct 2 14:10:21 PDT 2009
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/20091002/f924fc2e/attachment.html
More information about the antlr-interest
mailing list