0

I am planning to create a SQL queries parser. It can be done just using proper tokenizing and checking for the order.

But I'm planning to do it from something I learned in my Compiler Design courses (but years ago)

I can define the grammar for the queries I want to include, but I need some help in initial guidance, what kind of parser to implement? Top-Down/Bottom-up etc. Which is easier to start with.

Tagging as homework as I'm looking for some guidance.

http://blog.tcx.be/2007/05/writing-parser-overview.html -- I looked at this link which help me on how to proceed. Any other help is appreciated.

2 Answers 2

1

A top-down, recursive descent parser is the easiest to understand and thus the easiest to implement if you are coding it by hand.

Have you considered using a parser generator, though? I successfully used antlr in a recent project and would certainly recommend it to others. It has some good tutorials and a nice GUI tool for prototyping your grammar.

Sign up to request clarification or add additional context in comments.

2 Comments

You don't want a hand-coded parser for this. SQL grammars tend to be quite big; you want to use a strong parser generator. ANTLR is OK, and might come with a SQL grammar already available.
I'm planning to implement only a small set of features, and may be expand on top of that. Simply to learn this, not to deploy in any prod. environment. so, Top-Down is the best start point my question right?
1

A little late for this question, but recently I've been playing with the SQL Query Parser classes, which is part of Eclipse DataTools project. It was a little difficult to me to install it and make it work (I'm not a Java developer) but I managed to and it is very apt to parse very complex queries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.