<!-- MHonArc v2.4.4 --> <!--X-Subject: Re: [MUD-Dev] string parsing --> <!--X-From-R13: ptNnzv-pt.UenlEntr.Sqzbagba.OP.QO (Quevf Uenl) --> <!--X-Date: Sat, 01 Nov 1997 18:17:22 +0000 --> <!--X-Message-Id: 9711011808.8k2w@ami-cg.GraySage.Edmonton.AB.CA --> <!--X-Content-Type: text/plain --> <!--X-Head-End--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <title>MUD-Dev message, Re: [MUD-Dev] string parsing</title> <!-- meta name="robots" content="noindex,nofollow" --> <link rev="made" href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA"> </head> <body background="/backgrounds/paperback.gif" bgcolor="#ffffff" text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000"> <font size="+4" color="#804040"> <strong><em>MUD-Dev<br>mailing list archive</em></strong> </font> <br> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] <br clear=all><hr> <!--X-Body-Begin--> <!--X-User-Header--> <!--X-User-Header-End--> <!--X-TopPNI--> Date: [ <a href="msg00196.html">Previous</a> | <a href="msg00198.html">Next</a> ] Thread: [ <a href="msg00193.html">Previous</a> | <a href="msg00198.html">Next</a> ] Index: [ <A HREF="author.html#00197">Author</A> | <A HREF="#00197">Date</A> | <A HREF="thread.html#00197">Thread</A> ] <!--X-TopPNI-End--> <!--X-MsgBody--> <!--X-Subject-Header-Begin--> <H1>Re: [MUD-Dev] string parsing</H1> <HR> <!--X-Subject-Header-End--> <!--X-Head-of-Message--> <UL> <LI><em>To</em>: <A HREF="mailto:mud-dev#null,net">mud-dev#null,net</A></LI> <LI><em>Subject</em>: Re: [MUD-Dev] string parsing</LI> <LI><em>From</em>: <A HREF="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</A> (Chris Gray)</LI> <LI><em>Date</em>: Sat, 1 Nov 97 11:08:25 MST</LI> </UL> <!--X-Head-of-Message-End--> <!--X-Head-Body-Sep-Begin--> <HR> <!--X-Head-Body-Sep-End--> <!--X-Body-of-Message--> <PRE> [Felix C:] : 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. Well, are you going to have find_obj_on_obj, find_obj_beside_obj, find_obj_under_obj, etc.? Wouldn't you also want 'present' to be able to properly parse a noun phrase? That's where I was thinking you might end up recursively calling parse_string. Nothing really bad here, I guess - there probably aren't any truly tidy alternatives that work better. :> 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. Hmm. The syntax might have confused the issue. The metasymbols []* apply to the word-types - they aren't used on characters like in a traditional regexp. So, the above rule is read as: the word 'give', followed by an optional word of type ARTICLE, followed by zero or more words of type ADJECTIVE, followed by a word of type NOUN, followed by the word 'to', followed by an optional word of type ARTICLE, followed by zero or more words of type ADJECTIVE, followed by a word of type NOUN, followed by an optional word of type PUNCTUATION I guess you could think of it as a regexp of words, but I never did. :What is your new system like? Erff. Full docs at: ftp.myrias.com:/pub/cg/MUD/AmigaMUD/docs.tar.Z (Not sure of the filename at the end.) Briefly: A grammar is basically a hash table of words. It will contain "separator words" like 'in', 'on', 'from', etc. as well as the "verbs" that will be the first word of a command. Associated with each verb word is a list of the forms of that verb (only Verb0, Verb1 and Verb2 forms). Each such element includes a reference to any "separator word" needed, and a referenced to the MUD-code routine to handle the semantics of that verb form. Synonyms can be entered - they just point at another entry. The verb forms are: VerbTail - no handling of the rest of the command - it is available to the verb routine, word by word or as a single string. E.g. SAY hello to the mouse Verb0 - no noun-phrase allowed. e.g. NORTH; GET UP Verb1 - direct object wanted. Several can be given, separated by commas or 'and', and each will be passed to the handler in turn. E.g. GET the large rock; PUT DOWN the book and the rod. Verb2 - direct and indirect objects wanted. First one can be several, separated by commas or 'and'. E.g. PUT the sword, big orange pillow INTO trophy case. The same word can be all of the last 3 kinds, and it will be disambiguated based on the separator words. The set of articles and punctuation handled is fixed. Builtin 'Parse' parses an input string against a grammar - it handles several commands at one time from the string. I have a canonical form for noun phrases, e.g. "pillow;big,orange", and I have a builtin to match them (allowing several alternatives for the in-db parameter). This is used within another builtin which will look at a list of objects in the database, and try for a match with a given input noun-phrase. In my current scenario, there is an input command handler which checks for special forms (leading ", leading :, etc.) as well as aliases, before it passes the input to 'Parse', with the main grammar. There is more detailed documentation, and examples, in the 'Parsing' section of the "ProgConcepts.txt" file in the docs archive. -- Chris Gray cg#ami-cg,GraySage.Edmonton.AB.CA </PRE> <!--X-Body-of-Message-End--> <!--X-MsgBody-End--> <!--X-Follow-Ups--> <HR> <!--X-Follow-Ups-End--> <!--X-References--> <!--X-References-End--> <!--X-BotPNI--> <UL> <LI>Prev by Date: <STRONG><A HREF="msg00196.html">Re: [MUD-Dev] Re: Idea: Hive-mind monster</A></STRONG> </LI> <LI>Next by Date: <STRONG><A HREF="msg00198.html">Re: [MUD-Dev] string parsing</A></STRONG> </LI> <LI>Prev by thread: <STRONG><A HREF="msg00193.html">Re: [MUD-Dev] string parsing</A></STRONG> </LI> <LI>Next by thread: <STRONG><A HREF="msg00198.html">Re: [MUD-Dev] string parsing</A></STRONG> </LI> <LI>Index(es): <UL> <LI><A HREF="index.html#00197"><STRONG>Date</STRONG></A></LI> <LI><A HREF="thread.html#00197"><STRONG>Thread</STRONG></A></LI> </UL> </LI> </UL> <!--X-BotPNI-End--> <!--X-User-Footer--> <!--X-User-Footer-End--> <ul><li>Thread context: <BLOCKQUOTE><UL> <LI><STRONG>Re: [MUD-Dev] string parsing</STRONG>, <EM>(continued)</EM> <ul compact> <LI><strong><A NAME="00180" HREF="msg00180.html">Re: [MUD-Dev] string parsing</A></strong>, Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Fri 31 Oct 1997, 01:17 GMT </LI> <LI><strong><A NAME="00187" HREF="msg00187.html">Re: [MUD-Dev] string parsing</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Fri 31 Oct 1997, 07:02 GMT </LI> <LI><strong><A NAME="00192" HREF="msg00192.html">Re: [MUD-Dev] string parsing</A></strong>, Felix A. Croes <a href="mailto:felix#xs1,simplex.nl">felix#xs1,simplex.nl</a>, Fri 31 Oct 1997, 12:12 GMT </LI> <LI><strong><A NAME="00193" HREF="msg00193.html">Re: [MUD-Dev] string parsing</A></strong>, Felix A. Croes <a href="mailto:felix#xs1,simplex.nl">felix#xs1,simplex.nl</a>, Fri 31 Oct 1997, 20:06 GMT </LI> <LI><strong><A NAME="00197" HREF="msg00197.html">Re: [MUD-Dev] string parsing</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sat 01 Nov 1997, 18:17 GMT </LI> <LI><strong><A NAME="00198" HREF="msg00198.html">Re: [MUD-Dev] string parsing</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sat 01 Nov 1997, 20:17 GMT </LI> <LI><strong><A NAME="00228" HREF="msg00228.html">Re: [MUD-Dev] string parsing</A></strong>, Felix A. Croes <a href="mailto:felix#xs1,simplex.nl">felix#xs1,simplex.nl</a>, Mon 03 Nov 1997, 13:25 GMT <UL> <LI><strong><A NAME="00231" HREF="msg00231.html">Re: [MUD-Dev] string parsing</A></strong>, coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Tue 04 Nov 1997, 04:30 GMT </LI> </UL> </LI> <LI><strong><A NAME="00233" HREF="msg00233.html">Re: [MUD-Dev] string parsing</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 04 Nov 1997, 07:03 GMT </LI> </ul> </LI> </UL></BLOCKQUOTE> </ul> <hr> <center> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] </center> <hr> </body> </html>