Preliminary understanding of DSL and GPL

DSL: A language that describes objects, rules, and operations in a specific domain in an extremely efficient manner.

A specific interpreter is required to cooperate with it.

Efficient and simple domain language, which can greatly reduce the difficulty of understanding and using compared with general language, and greatly improve the development efficiency of the language.

A language that can describe the world view and methodology of a particular field.

DSL compromises on expressive ability in exchange for high efficiency in a certain field.

The limited expressive power becomes a boundary between GPL and DSL.

Talk about DSL and the application of DSL (take CocoaPods as an example)
https://zhuanlan.zhihu.com/p/22824177

And the DSL introduced today can really increase productivity, reduce unnecessary work, and help us meet demand faster in some areas.

What is DSL?
DSL is actually the abbreviation of Domain Specific Language, and Chinese is translated into domain specific language (hereinafter referred to as DSL); the opposite of DSL is the GPL. The GPL here is not the open source license we know, but the abbreviation of General Purpose Language, namely General-purpose programming language, that is, Objective-C, Java, Python, and C language that we are very familiar with.

Wikipedia's definition of DSL is relatively simple:

A specialized computer language designed for a specific task.

A computer language specially designed to solve a certain type of task.

In contrast to the GPL, DSL is completely different from the traditional general-purpose programming languages ​​C, Python, and Haskell. The general computer programming language can be used to write any computer program, and can express any logic that can be calculated, and it is also Turing complete.

But the DSLs mentioned here are not Turing complete, their expressive power is limited, and they only solve specific tasks in specific fields.

A computer programming language of limited expressiveness focused on a particular domain.

Another world-class software development master Martin Fowler's definition of domain-specific languages ​​is more specific in the author's opinion. DSL compromises its expressive ability in exchange for efficiency in a certain field.

The limited expressive power becomes a boundary between GPL and DSL.

Several chestnuts. The
most common DSLs include Regex and HTML & CSS. Here are a few examples of these.

Regex
regular expression only specifies the pattern of the string, and its engine will determine whether the current string matches the regular expression according to the pattern.
SQL
SQL statements are not actually executed when they are used. The SQL statements we input will eventually be handed over to the database for processing. The database will read useful information from the SQL statements and then return the results expected by the user from the database. .
HTML & CSS
HTML and CSS just describe the structural semantics and style of the web interface. Although they are very important when building a website, they are not a programming language. On the contrary, we can think of HTML and CSS in the Web Domain specific language.
Features
? Above several significant narrowing the concept of general-purpose programming language, but they do very good in their field performance, since DSL is shaped according to these characteristics of a particular field; and general-purpose programming language, compared Domain-Specific Languages At design time, it is to solve more abstract problems, and the focus is not just in a certain field.

The above examples have some common characteristics:

There is no concept of calculation and execution;
it does not need to directly represent calculation itself;
it only needs to declare rules, facts, and levels and relationships between certain elements when using it;
although we understand DSL and some characteristics of DSL, so far, , We are still not very clear about how to build a DSL.

Building DSL
The construction of DSL is actually similar to the programming language. Think about the things we need to do when re-implementing the programming language; the process of implementing the programming language can be simplified to define the syntax and semantics, and then implement the compiler or interpreter The implementation of DSL is very similar to it. We also need to design the syntax and semantics of DSL.

To sum up, there are two tasks that need to be completed to achieve DSL:

Design syntax and semantics, define what the elements in the DSL look like, and what the elements mean.
Implement the parser, parse the DSL, and finally execute it through the interpreter

Design Principles and Compromise The
biggest design principle of DSL is simplicity. It simplifies the elements in the language and reduces the burden on users. Whether it is Regex, SQL, HTML or CSS, the description document is often only a few pages, which is very easy to learn and master. However, the resulting problem is that the DSL lacks abstract concepts, such as modularity, variables, and methods.

Abstract concepts are not a concern in a certain field, just like Regex does not need to have concepts such as modules, variables, and methods.

Due to the lack of abstraction capabilities, when our project scale becomes larger and larger, DSL often cannot meet the needs of developers; we still need to supplement the DSL with concepts such as modularity in the programming language to solve DSL is not The problem with real programming languages.

The classification of
DSL DSL is not a new thing. SQL, CSS, regular expressions, etc., which we usually contact with, belong to DSL. Some DSLs may focus more on one aspect, such as Mathematica, LOGO, etc. The goals of these languages ​​are specific areas, while the opposite is GPPL (General Purpose Programming Language). Martin Fowler divides DSL into external DSL and internal DSL. External DSLs have their own specific grammars, parsers, lexical analyzers, etc. They are often a small programming language and do not even require source files like GPPL. The opposite is the internal DSL. The internal DSL is actually more like a nickname, it represents a special kind of API and usage model.

  XSLT, SQL, etc. can be counted as external DSL. External DSL is generally designed directly for a specific field, without considering other aspects. James Gosling once said: Every configuration file will eventually become a programming language. At first you may only use it to represent a little bit of things. Slowly you will want some rules, and these rules become expressions. Later, you may also define variables, make conditional judgments, etc., and eventually It has become a strange programming language, which is not uncommon.

  The internal DSL, as mentioned before, often represents only a series of special APIs and usage patterns, such as LINQ query statements and Active Record declaration code in Ruby on Rails. Internal DSL can use a series of APIs to "disguise" as a DSL, it often uses some "smoothing" skills, such as jQuery like some methods connected by "dots", while others also use meta programming the way. The internal DSL also has some advantages, such as access to the code or variables in the language, as well as all the features of the mother language such as code completion and reconstruction.

https://www.cnblogs.com/feng9exe/p/10065973.html

Guess you like

Origin www.cnblogs.com/ys-01/p/12679665.html