What you're describing is a grammar analyzer. A grammar analyzer consists of a parser and lexical analyzer.
The Parser operates at a syntax level. The Lexical Analyzer operates at the buffer level. If you were reading a book, your brain would be the Parser and your eyes would be the Lexical Analyzer.
So you are sitting there and decide to read a book. You get up and walk to your bookshelf and select a book called SerialDevice. You sit back down, open the book (the stream), turn to the first page, and prepare to read (instantiate your SerialContoller class, and pass it the stream).
Now the logic gets a little more intricate. To make it simpler, lets pretend the book is just a sentence long. So we want to read the sentence. More specifically, we want read each word in the sentence. So our brain says, "Eyes, get the first word", and our eyes move through the sentence until they reach a space (or $), and returns, "This array of characters is the word you requested." Then our brain interprets the word by comparing it to all the cases (like in a switch statement) of words it knows. So if the word is UP, it calls the appropriate function. If it is PU, it might reply, "That doesn't make sense, scan it again eyes", or it might say, "Whatever. Get me the next word"
So, thats the gist of it. Just remember only the Parser calls Lexical Analzer and only the Lexical Analyzer handles the buffer.
The next step I may or may not be able to help with. So, with the grammar analyzer we can get valid commands. The question is, "Does this need to happen on a separate thread?" I'm not quite up to multithreading yet, but if it does need to be on another thread you would need to have the Parser call a public function of the command buffer object that will put the command in the buffer. Also, unless the command buffer processor is polling the command buffer, an event would have to notify the processor a command has been put in the queue. An event system is easy enough to create. But I'll wait for a response before I elaborate.
If not, then you would still have the Parser call a public function of the command buffer, but you wouldn't raise an event. Practically, there is no need for a command buffer if the flow of execution is synchronous. However, if this is just "proof of concept", then the Parser could read in several commands, and execution could then be handed to the command buffer processor.
Last edited by kkelly; 09-13-2007 at 01:31 PM.
|