[DGD] parse_string question

bart at wotf.org bart at wotf.org
Sun Dec 30 10:05:02 CET 2007


A long time ago, Par posted about seperating input parsing from actions. Over
time, I have been changing my lib to use this idea, and have gotten to dealing
with the input parsing side of it.

First of, this idea works really well for me, and after some experimenting
with parse_string, the results are quite encouraging.

My mud now understands things like 'put 2 knifes from the first bag in the
second bag', 'greet the gatekeeper, get a pass from the first bag and show it
to him' or 'from the second bag, sell the first knife' and many such things,
using 2 grammars (one for chopping up the player's input in verbs with
'arguments', and one to deal with the arguments of each verb. The later
grammar results in an action record that is then queued and eventually executed.

Anyway, my question..

Assume I have a big mapping called verbs, containing some 500 or so verbs as
index, with some verb specific arrays as values.

Then I have a grammar that looks something like
whitespace=/[ ]+/
word=/[^ ]+/
part: words verb words
verb: word ? test_verb
words: word
words: words word

and a function 

mixed * test_verb(mixed * arg)
{
   if(arg && sizeof(arg) == 1)
      return verbs[arg[0]];
   return nil;
}

This would eliminate alternative parse trees by returning nil for everything
that is not a verb.

Alternatively, I could create a grammar that has a regexp for each verb in the
verbs mapping by looping through the indeces of the map

I'd still end up calling a function to change the array for verbs, but it
would remove the ambiguity of the grammar I believe. Its also less flexible
because I can't change the verbs it recognizes dynamically.

So my question is how big an issue ambiguity of the example above is, and how
adding hundreds of patterns to it would affect the parser.

Bart
--
Created with Open WebMail at http://www.bartsplace.net/
Read my weblog at http://soapbox.bartsplace.net/




More information about the DGD mailing list