parsing string messages in c++
<p>I'm asking for a suggestion regarding the parsing of text messages. I have a list of messages in text format, in the format:</p>

<pre><code>dev1.comm1 param

dev1.comm2 param

dev1.comm11 param

dev2.comm1 param

dev3.comm1 param
</code></pre>

<p>I need to parse each received line of text and find out the message contained. I did a parser for binary messages with lookup tables, i.e.:</p>

<pre><code>first byte table = 
{

0x01 -&gt; table 0x01,

0x02 -&gt; table 0x01,

0x03 -&gt; message 0x03

}
</code></pre>

<p>where 0x01 and 0x02 are the start of messages with lenght greater than 1, while 0x03 is a message made up of only one byte. If the first byte of the received message is 0x01 i go on comparing the second byte with the content of the table 0x01, while if the first byte is 0x03 i return the id of the message 0x03 and get it in some other fucntion. Obviously I implemented this with structures and pointers, this is just some form of pseudocode. </p>

<p>I would like to have a similiar solution for text messages, but the one i outlined above seems not that good to me, also because I have long text messages, and I would end up with too many tables.
Is there a cleaner solution, in the case of text messages? A parse tree perhaps?</p>
