Fireworks!

Published July 04, 2007
Advertisement
4th of July and Independence Day isn't on TV. wtf?

I got out and saw the new Die Hard movie today. It was okay. Worse than the first and third, way better than the second. Too much boom, too little funny. At least the computer stuff was mildly plausible. But then again, after Swordfish even Jurassic Park and Independence Day are high in the computer plausibility department...


As for MoE, I want to work on Projects next. A project is a catchall for something your dudes can work on. Research, training, building, social efforts, spells... Anything that takes resources and/or labor and produces a result. To get those working though, I'd like a nice way to define their prerequisites, requirements, results. A way that's flexible, but not so flexible that it's impossible to auto-generate some help/info screens for each of them ala the Civpedia.

Which led me to wanting something like boost::spirit for C#. ANTLR can produce C# code, and looked pretty swanky but the parsers it generates are... inscrutable. I give it a nice simple grammar and it dumps code that doesn't compile (and doesn't seem to work when I hack it). I use their test grammar and get code that by all views seems to not actually do more than tell me something is well formed. At least the methods don't do anything visibly useful and all the documentation is about how to make grammars rather than integrate the generated stuff into doing something vaguely useful...

I've taken CS 101 at a community college. Formal computation and compiler theory is not my strong suit. That doesn't particularly help my cause in deciphering the docs for parser generators.

I unfortunately gave up on that for now. Against the better judgment of that little voice in my head saying to use 3rd party tools I went ahead and tried to throw together a little modular parsing code. Just something small to handle simple grammars in simple scenarios when speed and memory usage isn't a concern. And if it doesn't work, no big deal; I'll learn a bit via success or failure I figured.

It took about 6 hours, but I have the base stuff done. An abstract parser, support for 0 or 1, 0 or more, 1 or more, difference/exception (matches one but not another), not, or, "followed by"... Also done are a parser matching Any (the dot in regexes) and one which takes a regex and uses that as the matching pattern.

There's still a bunch that will need to be done, and I'm fairly sure I did it in such a way that there will be terrible, weird problems with certain text or parsers; for now though everything works as expected and I am very pleased with it. Maybe I had some hints from using boost::spirit, but so far it's been quite a bit easier to implement than I'd've guessed. The parser for my in-game console was a horror with just regexes and procedural fiddling.

Example test:
            Parser Everything = new Any().ZeroOrMore;            Parser Word = new Expression(new System.Text.RegularExpressions.Regex(@"[a-zA-Z]+"));            IndexTree rslt = Everything.Parse("How now brown cow?");            foreach (string s in rslt.ViewTree("How now brown cow?")) {                Console.WriteLine(s);            }            IndexTree rsltWord = Word.Parse("How now brown cow?");            foreach (string s in rsltWord.ViewTree("How now brown cow?")) {                Console.WriteLine(s);            }


result:
rms.Support.Parsing.Series  0:18 - How now brown cow?  rms.Support.Parsing.Any  0:1 - H  rms.Support.Parsing.Any  1:2 - o  rms.Support.Parsing.Any  2:3 - w  rms.Support.Parsing.Any  3:4 -   rms.Support.Parsing.Any  4:5 - n  rms.Support.Parsing.Any  5:6 - o  rms.Support.Parsing.Any  6:7 - w  rms.Support.Parsing.Any  7:8 -   rms.Support.Parsing.Any  8:9 - b  rms.Support.Parsing.Any  9:10 - r  rms.Support.Parsing.Any  10:11 - o  rms.Support.Parsing.Any  11:12 - w  rms.Support.Parsing.Any  12:13 - n  rms.Support.Parsing.Any  13:14 -   rms.Support.Parsing.Any  14:15 - c  rms.Support.Parsing.Any  15:16 - o  rms.Support.Parsing.Any  16:17 - w  rms.Support.Parsing.Any  17:18 - ?rms.Support.Parsing.Expression  0:3 - How
Previous Entry Not game stuff.
Next Entry Parsing baby steps.
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