I never really “got” the idea of the need to build a textual DSL when I was first introduced to MGrammar. The light really switched on when I looked into developing a DSL that would make it easier for developers to create BAM activities.
The BAML language only took a couple of hours to develop. I had experimented with simple text based DSLs before, so this was my first “real” language.
I have recorded a 20 minute webcast showing how the language works, and how it can be used. If you want to experiment with it yourself, the language is here.
module BloggersGuides
{
language BAML
{
syntax Main = Activity;
syntax Activity =
ActivityToken
n:NameToken
‘{‘
p:List(PKI)
‘}’
=> { activity { n,{ p }} };
syntax PKI = Milestone | Integer | Decimal | Text;
syntax Milestone = t:MilestoneToken n:NameToken ‘;’
=> { t, { n } };
syntax Integer = t:IntegerTokenn:NameToken ‘;’
=> { t, { n } };
syntax Decimal = t:DecimalTokenn:NameToken ‘;’
=> { t, { n } };
syntax Text = t:TextTokenn:NameToken ‘;’
=> { t, { n } };
syntax List (Element) =
e:Element => { e } |
list:List(Element) e:Element => { valuesof(list), e };
token NameToken = (‘A’..’Z’ | ‘a’..’z’)+;
@{ Classification [“Keyword”] }
token ActivityToken = “activity”;
@{ Classification [“Keyword”] }
token MilestoneToken = “milestone”;
@{ Classification [“Keyword”] }
token IntegerToken = “integer”;
@{ Classification [“Keyword”] }
token DecimalToken = “dec”;
@{ Classification [“Keyword”] }
token TextToken = “text”;
interleave Whitespace = ‘ ‘ | ‘\r’ | ‘\n’ | ‘\t’;
}
}
This is the sample input file I used on the webcast.
activity ConferenceBooking
{
milestone BookingDate;
text ConferenceName;
text AttendeeCity;
text HotelName;
dec Price;
integer Days;
}
You will need the command line compiler to get the BAM activity created, if you contact me I can email it to you.
Regards,
Alan