[erlang-questions] Writing a DSL in ERlang

Christopher Foley <>
Fri Feb 8 09:59:28 CET 2013


Hi,

I'm am interested in creating an external DSL with Erlang and what are 
the steps involved. So very basically I want to convert some English 
like language into running erlang code. My goal is to build up a full 
erlang source file relative to the dsl file I have as input. I don't 
necessarily need to print out the source file to the file system, 
holding it in memory is sufficient and allowing its execution.

Sample DSL syntax; {createhandler, "TestHandler", {handles, [ {x, 
{action, printToScreen}}, {y, {action, writeToStorage}} ]} }

So from above I want to create a gen_event handler with a handle_event 
function which pattern matches on 'x' and 'y' and performs the actions 
defined. I have used this to just show what I would like to do, what I'm 
interested in is the steps and approaches to doing this.

The steps I see are as follows:

 1. Parse the dsl text file, create different tokens. I presume that I
    have to write my own parser as its dependent on the structure of the
    dsl language itself?
 2. Match these tokens to chunks of erlang code, is this correct? What
    is best approach here; create a 'fun' for each chunk of code. How
    would I then simply put these funs together to represent the overall
    module?
 3. Once I have the code combined into one entity(representing a
    module), then I can presumably use the compile module.

I am only coming back to writing erlang (ten years since I coded in 
erlang), so apologies if questions are fairly basic. Any info appreciated.

Chris.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130208/5dece88e/attachment.html>


More information about the erlang-questions mailing list