[MUD-Dev] Magnetic Scrolls' magical parser

Chris Gray cg at ami-cg.GraySage.Edmonton.AB.CA
Tue Apr 29 08:30:32 CEST 1997


[Greg H:]
: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

Whoops! I missed that. I can handle any of those forms, however.

: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 :(
:
: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.

In an earlier game system, I required all nouns and adjectives to be in
tables, and multi-meaning words had to be handled special. In AmigaMUD
I've dropped that. Only verbs are in tables. When a noun-phrase is needed
(based on the type of the verb and the existence of non-key further
words in the command), a noun-phrase is grabbed. That is an optional article
skipped, and a bunch of words. The last word in the phrase is taken to
be the noun, the rest are assumed to be adjectives. Separators like 'and'
and ',', etc. terminate the noun-phrase, as does any special word linked
to the verb. Thus:

    plant the pot plant in the plant pot

'plant' is the verb. There are more words present, so look for a form
that takes one or two noun-phrases. Found one (or more), so grab a
noun phrase. The two-phrase form of 'plant' has special word 'in', so
stop the first noun phrase at that. Handle the 'in', then go get the
second noun phrase. The various forms of a verb are just an in-memory
linked list, pointed to by the hash table entry for the verb.

So, there is very little "understanding" of the command, but the effect
works out quite well. A nice side effect is that adjectives can be given
in any order, and alternatives are easy to handle, as are omitted
adjectives.

--
Chris Gray   cg at ami-cg.GraySage.Edmonton.AB.CA



More information about the mud-dev-archive mailing list