I'm not sure if this is the right place to ask but I was told it might be.
I want the user of my C# program to be able to enter statements and queries to access a database using simple English sentences which I have defined the grammar for in EBNF format.
I need a C# parser for this grammar that will allow me to determine if the statement entered by the user is valid within the defined grammar, and also, I need to know what terminal symbols were used to classify each word of the input, so that the program can
interpret their sentence meaningfully.
I have downloaded Grammatica and ANTLR, but I cannot figure out how to use either of them to generate my C# parser.
I also could not find a decent example showing how to use one of these parsers once it is made.
I would greatly appreciate it if anyone who understands this could help me figure out how to build my parser using either of these parser generators, or direct me to another parser generator that is easier to use, or direct me to a webpage that describes precisely
how to go about writing a parser by hand.
Not sure how much help this will be.
For hand parsing little languages the best tutorial i've seen is in bjarne stroustrops c++ 3rd edition ( possibly other editions also ). He goes through a fairly nice walkthrough of mapping a desk-top calculator from grammar to code generation with a hand-coded
lexer and parser ( recursive descent ). It's pretty cool.
If your language is suitable for recursive descent ( is that what LL(1) means, i can't remember ), small enough, and you don't need to be super efficient then that's probably the way to go. The code ends up as a fairly direct mapping of the grammar, so
drops out quite cleanly in my experience.
wrt automatic lexers and parsers, the only ones i've ( limited )experience with are Lex and Yacc. Many compiler books go into detail on these , and there will be loads of stuff on the internet ( google for "lex yacc tutorial" etc ).
Though I'm not sure that any are exactly what you're looking for.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.