What is a domain specific language? Anybody using it? And in what way?

前端 未结 14 1688
天涯浪人
天涯浪人 2020-12-22 17:04

I guess I am looking for some kind of intro and see if anybody have used it. Are there any particular advantages of using it?

Wikipedia:

domai

相关标签:
14条回答
  • 2020-12-22 17:51

    Everything is a DSL...

    Assembler: MOV R1 to R2
    Compilers: Assignment Statements -- A = A + 1, Conditionals -- IF (TRUE) ..., Branch -- RETURN
    HTML: ... describe a nested structure
    TCP/IP: describe to/from addresses
    PDF: describe text/image placement on paper
    Fonts: describe characters

    Any language that we use to describe a specific process is a DSL. Unfortunately there is a lack of domain specific languages to describe even our most basic processes, so we use the few languages we do have to describe everything we do. "Zip all html files in my web site" requires 300 lines of 3 or 4 different Languages to complete.

    To build a DSL determine the minimum number of characters needed to describe a process that you can remember and does not require documentation. Remember that speed and ease of use are the primary design criteria. Parsing is so fast that any syntax you use is fine, I prefer natural language as my syntax in most cases, "Pay Employees at the first of the month", but domain specific is just that, domain specific, you determine the syntax that best fits the problem.

    I would stay away from using other solutions that might be convenient but do not fit the problem such as HTML that was used to define Data (XML). CSV is very useful, it fits most problems. JSON does not fit the ease of use portion, it is overkill that adds unnecessary complications were CSV works for most problem. We use EXCEL a lot for DSL, it works great for describing small problems, under 65K to 1M rows, such as a tree structures or menus, column A is the level, other columns are icons, colors, labels and such (EXCEL is an editable CSV).

    I found that HTML did not really solve the problem of page layout, so I got rid of it and defined a DSL that does fit. I defined 6 regions on the page, HEADER, BODY, FOOTER, LEFT/RIGHT MARGINS, and LEFT/RIGHT FULL MARGINS. I could then tell the page generator to add a TITLE BAR, STATUS BAR, MENUS, TABLE, FORMS,..., to specific cells. Each of these Cells could then be split into Rows and Columns to any depth. Page layout takes seconds for any style.

    BODY contains a Table of my Employees
    HEADER contains a Title Bar caption 'Hello World' with login to Collins Software

    A Menu DSL don't fit the page layout DSL, so I built a unique DSL for menus.

    Resource My Main Menu
    *define:menu,m,Level,Label,Icon,Action;
    m,0,file;
    m,1,open,open.gif,Dialog Open File;

    Each problem is unique, the computer can use any format, it is the human that DSLs are designed for, so make it understandable by humans, something they can type in, and make the language out of real words; for it is real people, places, and things that we are describing.

    0 讨论(0)
  • 2020-12-22 17:51

    A DSL is a good way to develop a language to be used by non-programmers. For example, if you have a DSL for the finance people in a company, then rather than programming to their specification you can just let them write the program they want done. Then, if it is too slow then you can take what they wrote that works as they want, write it in a compiled language to speed it up.

    0 讨论(0)
提交回复
热议问题