• entries
    359
  • comments
    237
  • views
    188206

Parsing into Practical Application.

Sign in to follow this  
Telastyn

43 views

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...
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now