1
  1. 我想创建特定领域的查询语言
  2. 我需要创建它的步骤以及如何从创建的域特定查询语言转换为普通 SQL 查询来执行它。
  3. 和任何推荐的工具?
4

1 回答 1

4

DSLs are not much related to SQL.

You first need to specify your DSL on paper. I strongly recommend reading good books about programming languages while doing that. (e.g. Lisp in Small Pieces by C.Queinnec).

Then you need to implement your DSL as an interpreter. You'll use standard lexing, parsing and interpreters (or possibly compiler) techniques. Very probably you'll need to use or implement a garbage collector (or use Boehm's GC). Parsers generators like ANTLR could help you.

Co-designing and implementing your DSL in parallel is usually a good way of working.

You really should read several books & papers on several languages before designing & implementing your own DSL.

A practical way to do that is to embed an existing interpreter like Lua into your application, or to embed your application inside an interpreter like ocaml or python

Designing and implementing a good DSL is not trivial (several months or years of work), and requires some computer science & programming culture & know-how. Perhaps reading proceedings of conferences like DSL2011 will help you.

In addition of C.Queinnec's book, you could also read Programming Languages: Principles and Paradigms (by Maurizio Gabbrielli & Simone Martini) & Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (by Tate) & Programmming Language Pragmatics (by M.Scott)

于 2011-12-12T11:49:10.370 回答