"Domain-Specific Languages" in Julia

In my opinion, a DSL is more characterized by its semantics than its syntax. The specific syntax of a particular implementation is not as important as the semantics of the type system and how the DSL program fits together. Just because multiple programs in different languages do essentially the same thing, doesn’t mean they are necessarily the same DSL, but they could be, semantically, if not syntactically. However, the limitations and features of some programming languages will inevitable affect some semantics too. So the situation is a bit more complex and is context dependent on both syntax and semantics. If the different equivalent programs are achieved to be semantically the same, then they are essentially the same DSL.

2 Likes

There are other syntax’s that are roughly as readable as your example that are parseable. I think it’s ill-advised to devote effort into any more complicated DSL, as it’s more likely to become abandoned-ware than bog standard Julia (which other users can more easily take over if and when you choose to abandon it)

3 Likes

What these Julia libraries are offering might perhaps be better characterized as “embedded DSL”.

I have had some great experiences with the instaparse library in Clojure. It’s a nearly magical parser generator. Using mostly educated guesswork and a scrape of the yacc for ANSI C, I was able in just a few hours to write an embedded DSL for rewriting Yakindu finite-state-machines, expressed in C-like syntax, in my Clojure programs. If I were doing serious DSL’ing in Julia, I’d be tempted to use instaparse as a guide.

1 Like

Note also that since the original series of messages in this thread I have ported Python Lark to Julia as Lerche.jl . These packages take in an EBNF-style specification to create a parser, and then user-specified rules named after the EBNF productions are applied to process the AST. Lark and Lerche both eat their own dogfood in that they use themselves to define the EBNF syntax and semantics. Lerche.jl is not yet mature or that efficient but works.

One project that is using it is CIF_dREL.jl, which converts algorithms written in a fairly complex DSL named dREL into Julia code. The arbitrary document containing the dREL is read at runtime.

3 Likes