[MUD-Dev] string parsing
Felix A. Croes
felix at xs1.simplex.nl
Fri Oct 31 21:06:50 CET 1997
cg at ami-cg.GraySage.Edmonton.AB.CA (Chris Gray) wrote:
> [Felix C:]
>
> :I am writing the entire function as a server builtin, using lazy DFA
> :construction, lazy DPDA construction, with the appropriate amount of
> :caching between calls, etc.
>
> Sorry, I don't grok the acronyms. (I've never been strong on theory, so
> if they refer to something theoretical, I probably wouldn't understand
> an explanation either!)
I explained them in a different posting. Note that I confused even
myself: no DPDA is actually generated, but rather a shift-reduce
parser that uses parallel LR(0) parsing to simulate a NPDA. <duck>
> :In this case, `find_obj' should not just deal with "the rock", but with
> :"the rock from the sack" as a single object. I.e. it's a matter of
> :adjusting the grammar.
>
> You could do that. Sounds a wee bit hackish to me - you'll end up with
> a mess of functions implementing all of the prepositions that you end up
> wanting. At least the functions will know which preposition they are
> dealing with, and can all call common lower-level routines to identify
> the second noun phrase. Hmm. They might have to recursively call
> parse_string to pull out that noun phrase. Gee, I guess that's why I
> have a "ParseNounPhrase" builtin! :-)
Grammar:
Sentence: 'get' Object
Sentence: 'get' FromObject
Sentence: 'examine' Object
Sentence: 'examine' InObject
FromObject: Noun 'from' Noun ? find_obj_in_obj
InObject: Noun 'in' Noun ? find_obj_in_obj
Object: Noun ? find_obj
with the following function:
object find_obj_in_obj(mixed *parsetree)
{
/*
* parsetree = ({ obj1name, preposition, obj2name })
*
* find obj1 in obj2 (the code below has been simplified)
*/
return present(parsetree[0], present(parsetree[2]));
}
Not actually very hackish, is it? Finding an object in another object
is a fairly common operation.
> :> My current system is less like your proposal than an earlier one I did.
> :> I don't quite remember why I changed! I do recall, however, that I ended
> :> up with a *lot* of rules in the grammar, to handle the various ways that
> :> the player could give a command. I didn't do the lexical stuff, just the
> :> syntactic level. The lexical stuff was hard-coded.
> :
> :Even if you don't remember <why> you changed, do you remember <what> you
> :changed? :)
>
> Urgh. Lemme go look - the old stuff is around here somewhere... ... found!
> Its off in my "CPM" directory, which is stuff I saved from my CP/M machine
> before I threw it away - that tells you how old it is! Anyway, it was
> somewhat simpler than what you are planning - there was no structure to
> grammar - each input form was flat, e.g. (from the docs):
>
> give [ARTICLE] ADJECTIVE* NOUN to [ARTICLE] ADJECTIVE* NOUN [PUNCTUATION]
It looks as if your system used regular expressions, rather than a
context-free grammar (a context-free grammar is just a set of
production rules as in the example above). The latter is much more
powerful. There is a great deal that you can find out merely by
checking the syntax, which cuts down on the need for function calls
that you mentioned.
What is your new system like?
Felix Croes
More information about the mud-dev-archive
mailing list