<!-- MHonArc v2.4.4 --> <!--X-Subject: Re: [MUD-Dev] string parsing --> <!--X-From-R13: ptNnzv-pt.UenlEntr.Sqzbagba.OP.QO (Quevf Uenl) --> <!--X-Date: Thu, 30 Oct 1997 09:32:28 +0000 --> <!--X-Message-Id: 9710300533.8ju3@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="msg00172.html">Previous</a> | <a href="msg00174.html">Next</a> ] Thread: [ <a href="msg00213.html">Previous</a> | <a href="msg00174.html">Next</a> ] Index: [ <A HREF="author.html#00173">Author</A> | <A HREF="#00173">Date</A> | <A HREF="thread.html#00173">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>: Wed, 29 Oct 97 22:33:43 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:] :What follows is a description of something I am currently implementing :for my server. I am providing it here for others to comment on. Also, :I'd like to hear of other approaches to the same problem. In general, I think such a facility is a very good idea. That's why I have one in my system! I've found it to be useful in a couple of places, such as "sublanguages" for my online building commands, etc. One of my main concerns, however, is efficiency. LPC isn't as fast as native code for string handling, so anything you do on a per-character basis is going to be expensive. In my system, I did a number of builtin (native) functions to perform most of the core of the work. You can probably do that too. Another efficiency issue is that you should probably "compile" the grammars into an internal form. Especially if the grammar is likely to be used more than once or twice. Traversing through structures is more efficient than going back and forth in strings. Note that both lex and yacc essentially "compile" into a more efficient representation. I believe there are a number of regexp packages out there that compile the regexp, thus making the matches faster (up to an order of magnitude). Of course, I'm not at all sure how you would adapt one of them to your purposes! (I don't use regexp's myself - just some custom code.) Some other issues I've bumped into relating to this kind of parsing: - some kind of "escape" commands are very useful. For example, an input line starting with a quote is usually speech, regardless of what the rest of the line contains. You might be able to handle that OK with your grammars, or you could do preprocessing on input lines. Similar for using command aliases. - some kind of quoting mechanism is useful. For you, perhaps it can be put into the lexical definition of a 'word'. This is useful when the normal whitespace rules do something undesireable, or for the exceptional cases that always seem to come up. - interpretation can sometimes be ambiguous. I note that you seem to be intending that commands often have keywords within them that separate the various pieces (e.g. put <obj> IN <obj>). They also end up distinguishing various forms of input (versus put <obj> DOWN). Those keywords will occasionally also be verbs themselves (like DOWN). I don't see any problems for you here, since you can put all of the various forms in alternative productions. - the resolution of a noun-phrase string to a MUD-world object can be context dependent on the verb in the command. E.g. 'pick up the rock' can resolve to a different rock than 'take the rock from the sack'. I handle this by not doing the resolution until I am inside the code for the specific verb. Perhaps you could pass the verb to your 'find_obj' and 'find_liv' routines, but that doesn't result in very modular verbs. 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. In your last "give sword to dwarf" example, what would parse_string return if find_obj couldn't find a sword? An array containing the words of the noun-phrase, so that higher-level code could properly complain about not being able to find a sword? -- 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="msg00172.html">Re: [MUD-Dev] Re: Idea: Hive-mind monster</A></STRONG> </LI> <LI>Next by Date: <STRONG><A HREF="msg00174.html">Re: [MUD-Dev] string parsing</A></STRONG> </LI> <LI>Prev by thread: <STRONG><A HREF="msg00213.html">Re: [MUD-Dev] string parsing</A></STRONG> </LI> <LI>Next by thread: <STRONG><A HREF="msg00174.html">Re: [MUD-Dev] string parsing</A></STRONG> </LI> <LI>Index(es): <UL> <LI><A HREF="index.html#00173"><STRONG>Date</STRONG></A></LI> <LI><A HREF="thread.html#00173"><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="00178" HREF="msg00178.html">Re: [MUD-Dev] string parsing</A></strong>, Nathan Yospe <a href="mailto:yospe#hawaii,edu">yospe#hawaii,edu</a>, Thu 30 Oct 1997, 21:34 GMT </LI> <LI><strong><A NAME="00191" HREF="msg00191.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:02 GMT <UL> <LI><strong><A NAME="00195" HREF="msg00195.html">Re: [MUD-Dev] string parsing</A></strong>, Nathan Yospe <a href="mailto:yospe#hawaii,edu">yospe#hawaii,edu</a>, Fri 31 Oct 1997, 20:54 GMT </LI> <LI><strong><A NAME="00213" HREF="msg00213.html">Re: [MUD-Dev] string parsing</A></strong>, coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Sun 02 Nov 1997, 20:59 GMT </LI> </UL> </LI> </ul> </LI> <LI><strong><A NAME="00173" HREF="msg00173.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>, Thu 30 Oct 1997, 09:32 GMT <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00174" HREF="msg00174.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>, Thu 30 Oct 1997, 09:32 GMT </LI> <LI><strong><A NAME="00188" HREF="msg00188.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:00 GMT <UL> <LI><strong><A NAME="00194" HREF="msg00194.html">Re: [MUD-Dev] string parsing</A></strong>, Nathan Yospe <a href="mailto:yospe#hawaii,edu">yospe#hawaii,edu</a>, Fri 31 Oct 1997, 20:40 GMT </LI> </UL> </LI> </UL> </LI> <LI><strong><A NAME="00170" HREF="msg00170.html">Re: Idea: Hive-mind monster</A></strong>, coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Thu 30 Oct 1997, 07:14 GMT </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>