So here’s what I’m looking to achieve. I would like to give my users a single google-like textbox where they can type their queries. And I would like them to be able to express semi-natural language such as
'view all between 1/1/2008 and 1/2/2008'
it’s ok if the syntax has to be fairly structured and limited to this specific domain … these are expert users who will be using this.
Ultimately, I think I’d like the parse results to be available as some sort of expression tree. But if you’ve got some other ideas about what data structure might be better.
This is in C# 🙂
You are describing a programming language. Granted it’s a small language (often called a little language, or Domain Specific Language (DSL)). If you’ve never heard the term recursive descent parser, you are probably better off following Paul’s advice and using drop down boxes of some description.
However, again, I would have to agree with him, that if you want to do it, Antlr is the way to go. There are tutorials on the site that might help you get started. Basically, you will need to describe how the syntax using Backus-Naur Form notation.
You will then run Antlr over your grammer, and it will generate your parser. You can then feed the input from your textbook into an Abstract Syntax Tree. You can then use that Tree to generate your query. It’s not as difficult as it all sounds, but there’s a bit to it.
If you’re really into this and/or want to stretch your programming wings a bit, you could read more on the topic with the Dragon Book, AKA Compilers: Principles, Techniques and Tools.
Good luck my friend.