1997Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: mud grammar (was Re: Just a bit of musing) -->
<!--X-From-R13: @nguna Kbfcr <lbfcrNunjnvv.rqh> -->
<!--X-Date: from major.globecomm.net [207.51.48.5] by mx01.ca.us.ibm.net id 858020313.48160&#45;1 Mon Mar 10 18:58:33 1997 -->
<!--X-Message-Id: Pine.GSO.3.95q.970310083334.21415C&#45;100000@uhunix2 -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 199703101400.OAA108586#out1,ibm.net -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: mud grammar (was Re: Just a bit of musing)</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:yospe#hawaii,edu">
</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>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00082.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00084.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00081.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00085.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00083">Author</A>
&nbsp;|&nbsp;<A HREF="#00083">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00083">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: mud grammar (was Re: Just a bit of musing)</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: Multiple Recipients of MUD Design Mailing List &lt;<A HREF="mailto:mud-dev#null,net">mud-dev#null,net</A>&gt;</LI>
<LI><em>Subject</em>: Re: mud grammar (was Re: Just a bit of musing)</LI>
<LI><em>From</em>: Nathan Yospe &lt;<A HREF="mailto:yospe#hawaii,edu">yospe#hawaii,edu</A>&gt;</LI>
<LI><em>Date</em>: Mon, 10 Mar 1997 08:58:19 -1000</LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
On Mon, 10 Mar 1997, Carter T Shock wrote:

:&gt; From: coder#ibm,net
:&gt; A good MUD grammar is incredibly context sensitive.  A simple example is
:&gt; the case where the presence or proximity of an object adds verbs to the
:&gt; players.  There is no need for this crap to wander thru the global
:&gt; namespace, or even warp the general grammar.

Agreed. An object in someone's possesion (in one of their bags or pouches,
for example) might generate a certain set of new verbs for the owner, and
in hand, a new set of new verbs, ie a grenade might enable "prime" as a
verb, when held. I accomplish this by means of references in my internal
language attatchment scheme. Another example is: there is a horse in the
room. The new verb "mount" has been enabled. "mount", in my system, might
refer to a real function not normally accessed by the player, or to a
bytecode function written in my internal programming language.

&lt;snipped&gt;

:Lessee... in most mud worlds, the "nouns" are dynamic, but the verbs are
:not. I put nouns in quotes because often a noun/adjective pairing is
:required to uniquely identify an object (the long sword, the black sword,
:etc.). The verbs in the system are your commands. cast, throw, hit, etc. If
:we want to allow dynamic or generic verbs, now you're getting into natural
:language processing and I definitely don't want to go there. So there are
:some distinct sentence structures that emerge:

Hmmm. I, personally, am for dynamic verbs. Thus, my natural (command form
only, so far) language parser.

:&lt;verb&gt; &lt;object&gt;  "hit foo"
:&lt;verb&gt; &lt;object&gt; &lt;object&gt; "give gold foo" "cast fireball foo"
:
:So the first trick is to define your grammar... establish a mapping of
:verbs to appropriate objects. We'll start with "hit". In most codes if you
:"hit foo" the code first sees what the allowable targets are for foo, then
:tries to locate a foo somewhere in the world that satisfies the target
:rules (get_person_room_vis(), get_obj_room_vis() whatever). The basic flow
:doesn't change a whole lot. We still have classes of objects... people,
:things, places, etc. One solution is to write our lexical analyzer so it
:enforces target rules. Another is to write objects so they can respond to
:any command 

My objects respond with a boolean for recognized on a command, resulting
in a list of possible objects. The context engine then locates the proper
choice. shoot, for example:

&lt;verb&gt;       &lt;object&gt;       &lt;meanskey&gt;    &lt;means&gt;
&lt;shoot&gt; &lt;the purple dinosaur&gt; &lt;with&gt; &lt;the rocket launcher&gt;

&lt;verb&gt;        &lt;object&gt;     &lt;lockey&gt;  &lt;location&gt;
&lt;shoot&gt; &lt;the purple dinosaur&gt; &lt;in&gt; &lt;the kitchen&gt;

&lt;verb&gt;       &lt;object&gt;      &lt;speckey&gt; &lt;specifier&gt;
&lt;shoot&gt; &lt;the purple dinosaur&gt; &lt;in&gt; &lt;its left eye&gt;
&lt;shoot&gt; &lt;the purple dinosaur&gt; &lt;'s&gt; &lt;left eye&gt;

And these are the simple examples. Of course, unless there is a reason to
specify, and the time to specify (IE: set up a good shot) you usually type
"sho dino" and be done with it.

:(I've done sort of a mix here. Done in C++, the base generic
:object has a handler for all available commands, all of which respond "You
:can't do that" or somesuch. Real objects are derived from the base. For
:commands that make sense on the derived object, overload the virtual
:default handler, multiple levels of inheritence work nicely here).

Of course, this assumes preset commands, something I'd hate to have.
Instead, I have my String class parse things as above, and feed the
results to the verb and the various potential objects. An object will
respond if it recognizes a verb that _needs_ to be recognized (IE: prime),
but some verbs are universal, and never bother asking the object for
permission (IE: shoot).

:An example of where this works very nicely is with magic. Identify the verb
:"cast" as special in your lexical analyzer. Rather than
:&lt;verb&gt; &lt;object&gt; &lt;object&gt;
:it becomes
:&lt;verb&gt; &lt;spell&gt; &lt;object&gt;

Hmmm. Well, yes. But that functionality could just as easily be built into
cast with a good String parser.

:Now the question, why bother?
:Well, first off, it can make the mud more user-friendly. Rather than simply
:reporting "huh?" on bad commands, a true parser should be able to:
:	1) report the exact location of the error in the command
:	2) offer up suggestions (tab completion of commands)
:Now, we could do all of this without learning lex/yacc, but doing it in
:lex/yacc gives you a standard interface.. not to mention someone else has
:written most of the ugly code for you already. Btw, the newer flavors of
:the GNU lexer/parser software (glex and bison I think) offer up a C++
:version that encapsulates the parser as an object. Nifty side effect is
:that you can have more than one. So, if you really want to screw with the
:user's minds you could conceivably have different command sets in different
:parts of your world. (something along Zelazny's Amber... the physics are
:different in the place you've warped to so the commands, spells, etc are
:different). Wait, it gets better... if we want to link up muds, there are
:ways that one mud could export its parser object to another so, if you
:wanted, you could process commands for a user in the remote mud locally
:(not sure why you'd want to, but hey.... explore the possibiliteis :)

Now, that might be interesting. I wrote the whole thing in C++, didn't
find it very ugly, and thought it worked quite well, and fast enough for
my tastes. But that's just me. Incidentally, I used the keys as 
breakpoints. (in, at, on, over, etc) I find that I rarely need to parse an
unbroken set, though the parser will do so if required.

   __    _   __  _   _   ,  ,  , ,  
  /_  / / ) /_  /_) / ) /| /| / /\            First Light of a Nova Dawn
 /   / / \ /_  /_) / \ /-|/ |/ /_/            Final Night of a World Gone
Nathan F. Yospe - University of Hawaii Dept of Physics - yospe#hawaii,edu


</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="msg00082.html">Re: Threads, IO handling, and Event Queues</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00084.html">Re: Threads, IO handling, and Event Queues</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00081.html">mud grammar (was Re: Just a bit of musing)</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00085.html">Re: mud grammar (was Re: Just a bit of musing)</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00083"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00083"><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 grammar</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="00191" HREF="msg00191.html">Re: mud grammar</A></strong>, 
Nathan Yospe <a href="mailto:yospe#hawaii,edu">yospe#hawaii,edu</a>, Mon 24 Mar 1997, 05:25 GMT
</LI>
<LI><strong><A NAME="00198" HREF="msg00198.html">Re: mud grammar</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Mon 24 Mar 1997, 15:00 GMT
</LI>
<LI><strong><A NAME="00239" HREF="msg00239.html">Re: mud grammar</A></strong>, 
claw <a href="mailto:claw#null,net">claw#null,net</a>, Fri 28 Mar 1997, 04:05 GMT
</LI>
</ul>
</LI>
<LI><strong><A NAME="00081" HREF="msg00081.html">mud grammar (was Re: Just a bit of musing)</A></strong>, 
Carter T Shock <a href="mailto:ctso#umiacs,umd.edu">ctso#umiacs,umd.edu</a>, Mon 10 Mar 1997, 21:49 GMT
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00083" HREF="msg00083.html">Re: mud grammar (was Re: Just a bit of musing)</A></strong>, 
Nathan Yospe <a href="mailto:yospe#hawaii,edu">yospe#hawaii,edu</a>, Tue 11 Mar 1997, 02:58 GMT
</LI>
<LI><strong><A NAME="00085" HREF="msg00085.html">Re: mud grammar (was Re: Just a bit of musing)</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 11 Mar 1997, 13:20 GMT
</LI>
<LI><strong><A NAME="00112" HREF="msg00112.html">mud grammar (was Re: Just a bit of musing)</A></strong>, 
claw <a href="mailto:claw#null,net">claw#null,net</a>, Sat 15 Mar 1997, 07:29 GMT
</LI>
<LI><strong><A NAME="00121" HREF="msg00121.html">Re: mud grammar (was Re: Just a bit of musing)</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sun 16 Mar 1997, 04:15 GMT
</LI>
<LI><strong><A NAME="00133" HREF="msg00133.html">Re: mud grammar (was Re: Just a bit of musing)</A></strong>, 
claw <a href="mailto:claw#null,net">claw#null,net</a>, Tue 18 Mar 1997, 02:30 GMT
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>