5

Possible Duplicate:
Learning to write a compiler

I need to come up with a dummy SQL like language which has very limited features. I have never done any compiler or parsing stuff before. Can anyone let me know a good point to start may be a link or a example of the same. I am so clueless.

I will be using this dummy language with C/C++ as my primary language.

Thanks

Community
  • 1
  • 1
keeda
  • 2,605
  • 5
  • 28
  • 27
  • This is a pretty odd request. Can you explain why this is useful? – Ira Baxter Jul 28 '11 at 22:39
  • @Ira : I am in process of writing an application that uses sqlite3 for its database usage. database is populated with XML content and this content is stored using Nested Model logic [http://en.wikipedia.org/wiki/Nested_set_model] To query this database, I need to come up with a dummy SQL like language that would eventually convert to a complex SQL statement and query my database. to query the database using sql would be non reusable. – keeda Jul 28 '11 at 22:48
  • 1
    If you've never done compiler or parsing stuff before, why do you think you are well prepared to design an effective query language (syntax, semantics, pragmatics, expressiveness)? If you are storing XML, you might be better off using XPath (you already know it is well designed) as a query language and translating it to the schema you are storing, or simply storing the XML rather directly in the database. This still leaves you with the problem of parsing XPath, and translating XPath into SQL calls, which is likely to be pretty hard for someone without experience. Just trying to be realistic. – Ira Baxter Jul 28 '11 at 23:13
  • @Ira : My goal with this new dummy language is to provide an easier query mechanism, hence it has to be a very small subset of SQL. Since in the backend I will still be using the SQL query language, I am just looking for a intermediate dummy language to define the real SQL. Moreover I have started reading about the BNF and Bison for GNU. Does not look simpler but does not look unachievable either. I had earlier presented the idea of XPath but it was not appreciated among my peers due to efficiency reasons for the specific application. – keeda Jul 29 '11 at 06:12
  • 1
    I'm having a hard time understanding this. So people rejected XPath under the assumption there was some unknown yet definable query notation that would give better efficiency, and have handed you, a language designer/implementer novice, the job of designing and implementing this langauge? Look, I'm not trying to be a nay-sayer but I think the odds are stacked pretty highly against you on this. – Ira Baxter Jul 29 '11 at 06:56
  • @Ira : I get your point, but on the brighter side, I am getting to learn new stuff as Compiler and Parsing fundamentals. I am an intern here, so I guess will have to take, whatever is thrown on my plate. Lets see how it works out from here. – keeda Jul 29 '11 at 17:29
  • Well, if you're an intern, then nobody is likely depending on your actual success. In that case, if they'll give you the opportunity to play with this (I think they are crazy but that's their problem), then you absolutely should. Count me as an enthusiast for your learning activities now that I understand the circumstances. I'd start by asking *why* XPath was percieved to be slow; you don't want your solution to be slow for the same reasons. I suspect you'll have trouble making this efficient no matter what you do; RDBs and tree-like structures such as XML generally aren't efficient, period. – Ira Baxter Jul 29 '11 at 18:01

3 Answers3

2

The Dragon Book is often considered a good starting point. However, I will also recommend the ANTLR book

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
1

So you want to design a new langauge, build a parser for it, and then translate the result to SQL calls.

You should check out Parser Generators, especially the link to comparision of parser generators

When designing a language, you want the strongest, easiest-to-use parser generator to test your grammars, because you will be changing it a lot. If you choose a weak parser generator, you can find yourself spending more energy reshaping the grammer to make the parser generator tool happy than you will thinking about what grammar makes sense.

But once having a well-defined, parseable language, you discover there is considerably life-beyond-parsing.

When implementing a language, you need to capture an internal representation of it (e.g., a parse tree or AST), find a way to analye it for special cases, and means to transform it to your output language. By and large, parser generator tools don't help you at all here, and yet this is the hard part of the problem. And building all this extra stuff yourself is much more work than most people imagine.

What you actually want is an integrated system of tools that parse, build ASTs, can analyze them, can translate, etc. There aren't many tools like this. Our DMS Software Reengineering Toolkit provides all the machinery you need as foundations. You might not want actually use it, but you should know about this kind of tool so you can make a conscious choice to do it all yourself.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
0

I did a compiler construction course last year and we used the book

Compiler Construction by Kenneth C. Louden

It is very detailed with a good theoretical background. At the same time the author gives enough examples and uses very informative figures, so that you're never lost while learning. Eventually a compiler in C for a toy language is listed in the later chapters.

I really liked it!

das_weezul
  • 6,082
  • 2
  • 28
  • 33