Confused about the approach I should take for parsing / interactive analysis
One of the first things that made me want to program was to create a multiplayer text game. I was put off by the concept though, when I realized, at least at the time for me, how difficult it would be to write a smart parser.
So now I thought about it again and I tried to do a lot of research on this issue. It turns out this seems a lot more appealing than I think, and I came across terms like lexing, tokenization and parsing, only the last of which I knew before. I figured the lexical analysis field was what I wanted to find.
So instead of trying to create my own lexer and parser, which I read is very complex and error prone and most people condition to dodge it, I thought I'd find a good lexer and parser generator to use which supposedly does for me everything is heavy lifting and I can just focus on the grammar I want. I've also heard a lot of people say that people who want to do these things should just use Inform
.
Of course, I think that "Inform" is cool, but C # is my language of choice, and I like the freedom that allows me to understand what I perceive "Inform". I am more interested in creating all the components and frameworks for a multiplayer text game than I am in any particular end result, and therefore I like the idea of ββusing a standard programming language better.
I've been trying to find a good lexer / parser generator for C # for a while now, not quite satisfied with everything that seems to be suggested in terms of the comments people give.
antlr for C # appears to be underdeveloped and mostly an afterthought. I tried to understand GPLEX and GPPG, but as of now they are too confusing for me, even though I read a lot of documentation and read a lot about lexing in general.
I have a lot of concepts in my head about all the lexing processes, but when faced with a lexer and parser, I think I really don't know how they should be tied to my actual code.
I want to build a simple English grammar with phrases and verb phrases and have lists of nouns and verbs that can be dynamically added and prepared from a database as the game is developed and expanded.
I guess I feel like I disagree with the results of the research I was trying to do with this topic.
To be honest, the idea of ββcreating my own banardized notion of lexer and parser based on what I've researched seems more attractive at the moment than using any lexer / parser generator I've read about.
source to share
First, some meta tips. This may not be a big question for StackOverflow as it is not a specific technical issue. Instead, you can ask questions like this at Programmers.StackExchange.com.
To answer your question: I agree with tallseth; it depends on what skill you want to improve here. People sometimes ask me why I don't build a boat as I am quite comfortable and love to swim. Because you only have to build a boat if you like having an unfinished boat in your garage for two years. If you want to swim, swim. 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, check out Inform7; it is the most incredibly amazing adventure creation tool the world has ever seen. If you want to learn how to make a lexer and a parser then don't mess with the parser generators. Make a lexer and parser.
Parser generators are great if you're prototyping a new programming language and want to get started quickly. But grammars of a programming language can have some really nice properties that make them suitable for automatically generating a parser in a way that natural languages ββdo not. You will probably spend as much time wrestling with the parser generator as you would spend building the grammar if you go with the parsing generator approach.
Since you are new to this, I suggest you retrace the history of text adventure. Start by writing a lexer and parser that can parse two-word commands: "go north", "get the sword", "blob-brick", etc. This gives you enough flexibility that you can then tackle 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 drop items, you are well on your way.
In short, I strongly recommend that you follow your instinct; Writing your own lexer and parser is super fun and really not that hard if you start small and work up.
source to share
It depends on what you want to get out of the project.
If this is a tutorial project that you do in your spare time, you can use your own tokenizer and interpreter. While this is difficult to do completely, it is fairly easy to create a sufficient level of parsing. I would recommend using the minimum level of parsing you can use and building it up gradually, adding richness to the game. This is a good type of problem to practice TDD and design patterns if you're interested in. Using these techniques will facilitate gradual improvement.
On the other hand, if you don't get a lot of value from this exercise (you are on a tight timeline, this is for real work, you just don't care about syntactic level, etc.), then I suggest doing with an existing parser. If you are encapsulating a third party parser behind an abstraction, you may later change your mind about writing your own, or what to use a parser.
You've probably seen this already, but this SO question has a good list of parsers for C #.
source to share