One of the first things that got me into wanting to program was to create a multiplayer text game. I was scared away from the notion though when I realized, at least at the time for me, how complicated writing a smart parser would be.
So now I’m back to thinking about it, and I’ve tried to do lots of research on the subject. It turns out that it seems to be a lot more involved than I think, and I’ve stumbled across terms such as lexing and tokenizing and parsing, only the latter of which I knew of before. I figured the field of lexical analysis is what I wanted to look for.
So instead of trying to create my own lexer and parser which I’ve read to be very difficult and error prone, and most people instruct to steer away from, I thought I would find a good lexer and parser generator to use which will supposedly do all the heavy lifting for me and I can just focus on the grammar that I want. I’ve also heard lots of people say that individuals looking to do such a thing should simply use Inform.
Sure, I guess Inform is cool, but C# is my language of choice and I like the freedom that it allows me over what I perceive Inform to offer. I’m more interested in creating all the components and framework of the multiplayer text game than I am in any one particular final result, and so I like the idea of using a standard programming language best.
I’ve been trying to find a good lexer/parser generator for C# for a while now, not really satisfied with all that seems to be offered in terms of the comments people give.
antlr for C# seems to be underdeveloped and mostly an afterthought.
I’ve tried understanding GPLEX and GPPG but as of right now they are far too confusing for me, despite reading a lot of the documentation and trying to read up a lot on lexing in general.
I have a lot of the concepts in my head about the whole process of lexing, but when faced with a lexer and a parser, I guess I don’t really know how these are supposed to be meshed into my actual code.
I want to build a simple English like grammar with noun phrases and verb phrases, and be able to have lists of nouns and verbs that can be dynamically added and ready from a database as the game is developed and expanded upon.
I guess I’m feeling like I’m turning up short on the results of the research I’ve been trying to do with this subject.
To be honest, the idea of creating my own bastardized notion of a lexer and parser based on what I’ve researched seems far more appealing at this point than using any lexer/parser generator that I’ve read about.
First, some meta-advice. This is maybe not a great question for StackOverflow since it is not about a specific technical problem. You might consider asking questions like this on Programmers.StackExchange.com instead.
To address your question: I agree with tallseth; it depends on what skill you want to improve here. People occasionally ask me why I don’t build a boat, since I am fairly handy and like sailing. Because you should only build a boat if you like having an unfinished boat in your garage for two years. If you want to sail, sail. If you want to build a boat, build a boat. But don’t build a boat because you want to sail. If you want to write a text adventure, learn Inform7; it is the most incredibly awesome tool for making text adventures the world has ever seen. If you want to learn how to make a lexer and parser, then don’t mess around with parser generators. Make a lexer and parser.
Parser generators are great if you are prototyping up a new programming language and you want to get going quickly. But programming language grammars can have really nice properties that make them amenable to automatic parser generation in a way that natural languages do not. You’re likely to spend as much time fighting with the parser generator as you spend building the grammar if you go with a parser generator approach.
Since you’re a beginner at this, I suggest that you recapitulate the history of text adventures. Start by writing a lexer and parser that can parse two-word commands: “go north”, “get sword”, “drop brick”, and so on. That will give you enough flexibility that you can then start solving other problems in text adventure design: how to represent objects and locations. Start small; if you can make a two-room game where the player can pick up and put down objects, you are well on your way.
In short, I strongly encourage you to follow your instinct; writing your own lexer and parser is super fun and actually not that hard if you start small and work your way up.