🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Parsing into Practical Application.

Published July 23, 2007
Advertisement
One of the best little libraries I've ever written was a set of classes for an interpreter. The original requirements stemmed from wanting something to handle input from a quake-style console without a big case statement.

Since then it's grown a little to handle requirements here and there. It's also been used in a variety of other places with exceptional results. Very little modification allows me to use it for chat stuff, config files, resource loading... the few places where I do want to employ the interpreter pattern without the need to bust out fuller featured lua or its kin.


My past few journal entries discuss a little parser framework I've been working on. The past few days I've been integrating it into the interpreter to see what benefits it might provide compared to the regex/split hackery that the current version of the interpreter uses.

The biggest integration difficulty was an auto-detect feature I had. You can use attributes (C#) to specify which types the interpreter should recognize. Having something generic enough to pull any type, but specific enough to not just use object everywhere (and die if it's not what's expected) was a bit challenging.

That's all done now and working. Bad things first: It's about 15% slower in the super basic naive test. Good things: It now supports command overloading, and types can be given their own tokenizers which allows for earlier and more accurate detection of bad input. It also allows for connect xxx.xxx.xxx.xxx and connect www.foo.com to be distinguished as two different styles of commands which should go to different delegates.

Still, I'm not sure I'm gaining too much. I might be better off just going through and refactoring it a little rather than knocking out the entirety of the parsing bits. Maybe some optimization could help. The parser itself seems wildly variant based on the grammar it's using...
Next Entry Oh... not good.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement