[DGD] Working with parse_string()
Kamil N
kamiln at gmail.com
Mon Jul 20 01:57:53 CEST 2009
2009/7/20 Felix A. Croes <felix at dworkin.nl>:
> Kamil N <kamiln at gmail.com> wrote:
>
>>[...]
>> VERB: give OBJI{case=accusative} LIV{case=dative}
>
> In order to solve your second problem, what you probably need is an
> ambiguous grammar.
>
> VERB: polish_give OBJI_ACCUSATIVE LIV_DATIVE
> VERB: polish_give OBJI_ACCUSATIVE SOMETHING
> VERB: polish_give SOMETHING LIV_DATIVE
>
> In order for the second and third option to be considered, parse trees
> for earlier ones must be taken out of the game by letting functions
> return nil.
That will work I guess, thanks for all tips in previous mail too :) I
was just thinking about my determination to give user a good feedback
(by telling him different messages in case item he wants to give
doesn't exist or person he wants to give it can't be found) and I
realized its impossible to distinct, because not parser nor object
finding function will be ever able to say which part of "OBJ LIV"
failed. So it seems I can either get it all fine (by finding both OBJ
& LIV) or have it fail completly.
I'm just concerned about failing it when all rules fail to find proper
objects, because then last one returns nil and parse_string also
returns nil. I prevented it by adding last rule for verb "give". Not
sure if its clean approach or just some work-around, but seems to
work:
VERB: polish_give OBJI_ACCUSATIVE LIV_DATIVE
VERB: polish_give OBJI_ACCUSATIVE SOMETHING
VERB: polish_give SOMETHING LIV_DATIVE
VERB: polish_give STR ? parse_give_command_fail
where STR is defined like this:
STR: STR word
STR: word
STR:
so it also catches whole supported phrase, but this time it doesn't
look for object because we already know earlier functions failed to
locate it, so its just fallback to return ANY value and prevent
parse_string failure:
mixed *parse_give_command_fail(mixed *arr)
{
return ({ "give", ({}), ({}) });
}
This means that even if all possible rules to find proper objects
needed (object to give and/or living to receive) I don't get nil as a
result of parse_string, but empty command "give" without parameters,
so I can still execute this command and at least give some feedback
("Give [what] [whom]?");
Once again thanks for help & feedback at this late hour :)
Regards,
KN
More information about the DGD
mailing list