[MUD-Dev] Magnetic Scrolls' magical parser

Shawn Halpenny malachai at iname.com
Tue Apr 29 09:55:27 CEST 1997


Greg Munt wrote:

> On Sun, 27 Apr 1997, Chris Gray wrote:
> 
> > [Raz]
> > :It even supported the command that Magnetic Scrolls made such a big deal
> > :about, namely:
> > :  > put the pot plant in the plant pot
> > :
> > :Though, apparently, there's nothing very complicated about that syntax at
> > :all =3D)
> >
> > That's pretty straightforward. My 'putIn' verb just tells you that you
> > can't put something into itself.
> 
> A pot plant is not a plant pot :) Also, the whole 'big deal' about this
> was that 'plant' was able to be used as a verb, a noun *and* an
> adjective, IIRC the input was actually:
> 
>         > plant pot plant in plant pot
> 
> This sort of complexity seems to be lacking from the current mud
> 'mainstream' in its entirety. Most of which I have come across seems to
> be parsing such as:
> 
>         *  First word of input is the command, look it up in our hash
>            table of commands
> 
>         *  Call the function corresponding to the command, passing the
>            rest of the input (ie everything after the first word) as
>            parameters to the function
> 
> So, you might have function prototypes for your command functions as:
> 
>         void function (Player player, String parameters);
> 
> All command functions would have their own parameter parsing algorithms;
> so, for the above example, function 'plant' would be passed 'pot plant in
> plant pot' as its parameters.
> 
> This is utterly simplistic, and although quite easy to implement, does
> not make me happy in any way! I've looked about the web for things on
> NLP, but I think I'd need a PhD to understand it all :(

I had looked into the comp.ai.nat-lang FAQ for some pointers on natural
language processing, but a lot of the stuff in there seemed to center
around Prolog (ick).  I have no interest in complex natural lang parsing,
but rather just a small degree of improvement over what exists in the
stock muds now.  Since we're dealing with a fairly limited subset of
language, really, it's not too much work to bang out a simplistic parser
that will accept fairly natural syntax.  At the moment, I just break it
down into:
    verb object_construct [optional_object_construct]
for verbs that function that way (get, put, etc., though not say, shout,
etc.)

Basically, an object_construct can have a cardinal number (the quantity)
followed by an optional preposition, then alternating ordinal numbers
(specifying which numbered object in a set) and possessive nouns. 

So far, it seems to work.  So far.

> The best I can come up with is to have hash tables of verbs, nouns,
> adjectives, adverbs, etc - but beyond that I'm pretty much lost. Is
> anyone able to give me a few pointers on this? One of my goals is to have
> a parser of *at least* 'Infocom' complexity.

I parse complete commands into their component parts and pass an object
containing them to the appropriate function.  The function is responsible
for making sure the objects are in the correct places, have the correct
properties, etc. for the command to work, since the parser has already
resolved that the objects exist and the verb is valid. 

My verbs are always bound to an object, whether it is the character
executing the command, or the item(s) being used.  I maintain a global
mapping of object keywords to objects for global queries, as well as a
mapping of 2-space locations to objects for room queries (this second
mapping is also used for virtual space resolution).  Depending on ordering
of ordinal numbers and possessive nouns, the world's contents, the room's
contents, or the character's deep inv/equ could be searched when resolving
an object in a command.  Now I can write things like

    give 200 of my 2nd dog's bag's bread to room's 5th guard's 8th child's cat

(provided I've got at least 2 dogs, the second one's got a bag with bread
in it, there are at least 5 guards in the room I'm in and the 5th one has
8 children somewhere throughout the world and the 8th one owns a cat that
is also somewhere in the world.  I've also got to be an admin, if all of
those things are not in the same location as I am).  The parser will
resolve the 'bread' and the 'cat' to the proper objects and pass them to
the 'give' verb to be handled.	The verb will verify that the dog, his
bag, and the bread inside it are all in the room with me, as are the
guard, his 8th child and her cat.  (if I'm an admin, however, I can be on
the other side of the world and the necessary actions will be done to get
the bread from the dog's bag--this part might get interesting and I've not
thought it all out yet), and then do the action if the objects
are accessible to me.

As well, I can still write "give 200 bread cat" and that'll work just fine
(though it's not as pretty and perhaps I should direct the parser to
chastise the typist for poor and ambiguous grammar). 

Heh.  So far.

--
Shawn Halpenny

"Purgamentum init, exit purgamentum"
                            - Latin for All Occasions



More information about the mud-dev-archive mailing list