1999Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Text Parsing -->
<!--X-From-R13: Oyoreg <gurpurrmrznaNrneguyvax.arg> -->
<!--X-Date: Fri, 28 May 1999 11:51:42 &#45;0700 -->
<!--X-Message-Id: 199905281836.LAA11685#penguin,prod.itd.earthlink.net -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Text Parsing</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:thecheezeman#earthlink,net">
</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="msg00335.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00337.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00370.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00340.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00336">Author</A>
&nbsp;|&nbsp;<A HREF="#00336">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00336">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Text Parsing</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: MUD Dev List &lt;<A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A>&gt;</LI>
<LI><em>Subject</em>: [MUD-Dev] Text Parsing</LI>
<LI><em>From</em>: Albert &lt;<A HREF="mailto:thecheezeman#earthlink,net">thecheezeman#earthlink,net</A>&gt;</LI>
<LI><em>Date</em>: Fri, 28 May 1999 14:35:49 -0500</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
Delurking :)

I'm currently building a text adventure game, with intentions of expanding it into some sort of 
mud server once I master network programming. In any case, I was spending some time thinking 
about how to parse text and came to the follow conclusion. Nearly any command can be broken apart 
into four different strings: verb, direct object, indirect object, and adjectives. I have a class 
called ParsedCommand that looks like this:

class ParsedCommand { public:
        string verb;
        string direct_object; // Noun being manipulated
        string indirect_object; // Noun that receives the action
        string direct_object_adj; // Adjectives describing direct object
        string indirect_object_adj; // Adjectives describing the indirect object
        bool IsNewClause;
}

Then say the player enter a command like: buy the biggest ball from the 3rd shopkeeper
The convoluted pseudocode would be:

void Parse(string &amp; rhs) {
        ParsedCommand pc;
        string word;
	while (1) {
		word = GetNextWord(rhs); // Would magically keep pointer position
		if (word.empty())	break;		
		switch (GetKind(word)) {
		case VERB:
			if (pc.IsNewClause)
				pc.verb = word;
			else
				SendToQueue(pc);
			break;
		case DIRECT_OBJECT:
			if (pc.IsNewClause) {
				pc.direct_object = word; 
				pc.IsNewClause = false;
			} else
				pc.direct_object += " " += word;
			break;
		case INDIRECT_OBJECT:
		case ADJECTIVE:
			// Pretty much the same code for direct_object
		case CONJUNCTION:
			SendToQueue(pc); // Would send a copy to the queue, but pc still exists
			pc.IsNewClause = true; // Not technically true, but...
			break;
		}
	}
}

I know, this system is hugely inefficient. But I believe it allows the user to enter complicated 
commands like "get the red ball and the 4th rock then kill the troll and ogre". Because pc 
persists, it can use data interpreted from previous commands and simply send copies to the work 
queue. Comments?

--
Author: Albert Yi (TheCheeseMan)  ICQ: 14617788
home.earthlink.net/~thecheezeman AOL: EvlWombat

Author: Albert Yi (TheCheeseMan)  ICQ: 14617788
home.earthlink.net/~thecheezeman




_______________________________________________
MUD-Dev maillist  -  MUD-Dev#kanga,nu
<A  HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A>


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<ul compact><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><A NAME="00357" HREF="msg00357.html">Re: [MUD-Dev] Text Parsing</A></strong>
<ul compact><li><em>From:</em> Travis Casey &lt;efindel#io,com&gt;</li></ul>
<li><strong><A NAME="00348" HREF="msg00348.html">Re: [MUD-Dev] Text Parsing</A></strong>
<ul compact><li><em>From:</em> Mik Clarke &lt;mikclrk#ibm,net&gt;</li></ul>
<li><strong><A NAME="00342" HREF="msg00342.html">Re: [MUD-Dev] Text Parsing</A></strong>
<ul compact><li><em>From:</em> Greg Miller &lt;gmiller#classic-games,com&gt;</li></ul>
<li><strong><A NAME="00340" HREF="msg00340.html">Re: [MUD-Dev] Text Parsing</A></strong>
<ul compact><li><em>From:</em> "Kylotan" &lt;kylotan#kylotan,force9.co.uk&gt;</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00335.html">[MUD-Dev] Searching the archives</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00337.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00370.html">Re: [MUD-Dev] Re: Re: [MUD-Dev] Text Parsing</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00340.html">Re: [MUD-Dev] Text Parsing</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00336"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00336"><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><A NAME="00344" HREF="msg00344.html">[MUD-Dev] Re: Re: [MUD-Dev] Text Parsing</A></strong>, 
Albert <a href="mailto:thecheezeman#earthlink,net">thecheezeman#earthlink,net</a>, Sat 29 May 1999, 01:24 GMT
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00360" HREF="msg00360.html">[MUD-Dev] Re: Re: [MUD-Dev] Text Parsing</A></strong>, 
Albert <a href="mailto:thecheezeman#earthlink,net">thecheezeman#earthlink,net</a>, Mon 31 May 1999, 21:37 GMT
<UL>
<LI><strong><A NAME="00367" HREF="msg00367.html">Re: [MUD-Dev] Re: Re: [MUD-Dev] Text Parsing</A></strong>, 
Travis Casey <a href="mailto:efindel#io,com">efindel#io,com</a>, Tue 01 Jun 1999, 02:21 GMT
</LI>
<LI><strong><A NAME="00370" HREF="msg00370.html">Re: [MUD-Dev] Re: Re: [MUD-Dev] Text Parsing</A></strong>, 
Mik Clarke <a href="mailto:mikclrk#ibm,net">mikclrk#ibm,net</a>, Tue 01 Jun 1999, 05:48 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
<LI><strong><A NAME="00336" HREF="msg00336.html">[MUD-Dev] Text Parsing</A></strong>, 
Albert <a href="mailto:thecheezeman#earthlink,net">thecheezeman#earthlink,net</a>, Fri 28 May 1999, 18:51 GMT
<UL>
<LI><strong><A NAME="00340" HREF="msg00340.html">Re: [MUD-Dev] Text Parsing</A></strong>, 
Kylotan <a href="mailto:kylotan#kylotan,force9.co.uk">kylotan#kylotan,force9.co.uk</a>, Fri 28 May 1999, 21:08 GMT
</LI>
<LI><strong><A NAME="00342" HREF="msg00342.html">Re: [MUD-Dev] Text Parsing</A></strong>, 
Greg Miller <a href="mailto:gmiller#classic-games,com">gmiller#classic-games,com</a>, Sat 29 May 1999, 00:51 GMT
</LI>
<LI><strong><A NAME="00348" HREF="msg00348.html">Re: [MUD-Dev] Text Parsing</A></strong>, 
Mik Clarke <a href="mailto:mikclrk#ibm,net">mikclrk#ibm,net</a>, Sat 29 May 1999, 21:14 GMT
</LI>
<LI><strong><A NAME="00357" HREF="msg00357.html">Re: [MUD-Dev] Text Parsing</A></strong>, 
Travis Casey <a href="mailto:efindel#io,com">efindel#io,com</a>, Mon 31 May 1999, 03:34 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>