[MUD-Dev2] Command Parsing. Lame question!
Tiago
tiago.matias at gmail.com
Sat Jun 13 01:57:48 CEST 2009
Hi all,
I have written a parser with the help Lex/Bison style tools. Thing is, my
parser is a bit limited and I'm writing to you all to see if you have
suggestions on the best approach to solve this problem. (My compiler skills
are a bit rust so the solution may be plain obvious :))
Here's the deal: I have a grammar for recognizing simple actions for the
game. Something like:
Action : Command
| Command Argument
| Command Argument Preposition Argument
And my lexer recognizes some strings like "look", "open", "pick", "left",
"right" as Command and generic strings as Argument.
With this I can recognize commands like "look" and "left". I can even
recognize something like "give sword TO john".
But if I input "look left" the grammar won't work since the lexer is giving
me Command Command and the second token cannot be shifted. Now, as I see it,
my grammar is not context free and the tokens have different meaning
according to previous ones.
My question is, what is the best approach to solve this type of problem ? My
first approach was trying to recognize literal strings in the grammar. Like:
Command : "left"
| "open" (etc)
but that makes the grammar a mess. Another idea I had was processing tokens
from the lexer directly and building commands accordingly, but the code
would also be a mess because I'd lose the syntactic verifications of the
parser.
In your opinion, what is the best approach for this type of problem ?
thanks!
tg
More information about the mud-dev2-archive
mailing list