Designing DSL for L-System

The characteristics of a DSL are that the source code should look like the original representation of the domain concept. In this case, the domain concept is described by an axiom and a set of rules. Using the algae growth example, it needs to look like the following:

Axiom: A
Rule: A -> AB
Rule: B -> A

If we try to write them in plain Julia language, we may end up with code like this:

model = LModel("A")
add_rule!(model, "A", "AB")
add_rule!(model, "B", "A")

As we can see, this is not ideal. While the code is neither long nor difficult to read, it does not look as clean as the L-System grammar. What we really want is to build a DSL that lets us specify the model as follows:

model = @lsys begin
axiom : A
rule : A → AB
rule : B → A
end

This will be the target syntax for our DSL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.43.140