[MUD-Dev] Text Parsing

Chris Gray cg at ami-cg.GraySage.Edmonton.AB.CA
Wed Jun 2 00:01:18 CEST 1999


[Ross Nicoll:]

> > take cookie then eat cookie
>
> My MUD would fall over at this. It was never hold how to deal with "then".
> Simplest method seems to be to split commands up around "then".

Agreed. I've just never bothered to do it. Mine breaks multiple commands
around '.', ';' or '!', and that's been good enough for me.

> > take cup and saucer and spoon
>
> or
>
> > take cup, saucer and spoon
>
> in which case, we have to make sure that the program doesn't start trying
> to find "cup," in the room.

Yep. Treat them as indentical. If the user insists on typing

    take cup and saucer, spoon

I don't much care - it'll work. Why add code to prevent it?

> > take off coat
>
> seems simple enough. Thing is, do you first check for an object that can
> be described as an "off coat", or first check through the list of possible
> arguments to "take" for a match? The first options starts adding reserved
> words ("off button" anyone?), the second one has problems with other
> syntaxes:
>
> > take small box from wooden table

Ah, but the save here is that in your first case, 'off' is only a special
word when used with the 'take' verb. Similarly, 'from' is special for
this use of 'take'. The way I do it is to have, for each verb, a list
of the syntax forms for that verb. Only a simple no-indirect-object
form of a verb is allowed to not specify a preposition. Only one use
of a given preposition is allowed for a given verb. So, the prepositions
allow the parser to decide which verb form it is. The form says whether
or not it allows an indirect object, and if not, the preposition can be
either before or after the direct object. So:

    check for special leading characters (", ', :, etc.) => special code
    identify first word - its the verb
    look up verb in active grammar. Cases:
    if is "tail" verb pass rest of command (upto . or ; or !) to verb code
    else
	starting with word after verb, try to grab a noun phrase.
	Phrase ends at end of command or at any preposition for any
	form of the verb. If preposition is found, use that form of
	the verb (requiring direct/indirect as indicated by form),
	else the verb must have a simple form that requires no objects,
	or just direct objects - pick whichever one you find. The
	system disallows having both forms without prepositions.

> > take gold ring from the small box from wooden table
>
> but quite frankly, anyone typing that in deserves everything they get.

Yep. As indicated by the fact that it took *me* a second or so to
figure it out!

> Although 4 might be a lot simpler if the function was just called once for
> each item in a list.

That's what I do. That way the function just accepts one or two strings
for the noun phrases, rather than having to possibly accept a list of
them. I abort processing the list if the verb code says to.

--
Don't design inefficiency in - it'll happen in the implementation.

Chris Gray     cg at ami-cg.GraySage.Edmonton.AB.CA
               http://www.GraySage.Edmonton.AB.CA/cg/


_______________________________________________
MUD-Dev maillist  -  MUD-Dev at kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev




More information about the mud-dev-archive mailing list