DSLs with simple syntax may or may not mean simple semantics.
Simple semantics can mean easy translation into the target language or not. such translations are “technically easy” only if the DSL and the target language share many common data types and execution models. (Constraint systems have simple semantics, but translating them into Fortran is very difficult!). (You should be wondering: if DSL translation is simple, why do you have it?)
If you want to create DSL (in your case, you will keep it simple because you are learning), you want the DSL compiler infrastructure to have everything you need, including support for complex translations. The “what's needed” to handle the translation of all DSLs into all possible target languages is clearly an incredibly large set of mechanisms.
However, there is a lot that is clear that may be useful:
- A strong syntactic mechanism (which wants to sculpt with grammars, the structure of which is forced by the weakness of the simulator? (If you do not know what it is, read about LL (1) grammars as an example).
- Automatically constructing the representation (for example, an abstract syntax tree) of the analyzed DSL
- Ability to access / modify / build new AST
- Ability to capture information about symbols and their meaning (symbol tables)
- Ability to build AST analyzes for DSL, to support translations requiring informatain from "far away" in the tree, in order to influence the translation at a specific point in the tree
- The ability to reorganize AST is easy to achieve local optimizations
- Ability to track / analyze information and data flow information if DSL has some procedural aspects, and code generation requires deep reasoning or optimization
Most of the tools available for “creating DSL generators” provide some sort of parsing, perhaps tree building, and then leave you to fill out the rest. This puts you in the position of having a small, clean DSL, but to implement it forever. This is not good. You really want all this infrastructure.
Our DMS Software Reengineering Toolkit contains all the infrastructure drawn above and more. (He obviously does not and cannot have a moon). You can see the full, all-in-one "page", a simple DSL example that uses some integral parts of this mechanism .
source share